From patchwork Fri Jan 31 02:08:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zygo Blaxell X-Patchwork-Id: 11359003 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CA7A71800 for ; Fri, 31 Jan 2020 02:09:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A904320CC7 for ; Fri, 31 Jan 2020 02:09:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727824AbgAaCId (ORCPT ); Thu, 30 Jan 2020 21:08:33 -0500 Received: from james.kirk.hungrycats.org ([174.142.39.145]:45078 "EHLO james.kirk.hungrycats.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727722AbgAaCId (ORCPT ); Thu, 30 Jan 2020 21:08:33 -0500 X-Envelope-Mail-From: zblaxell@waya.furryterror.org X-Envelope-Mail-From: zblaxell@waya.furryterror.org Received: from waya.furryterror.org (waya.vpn7.hungrycats.org [10.132.226.63]) by james.kirk.hungrycats.org (Postfix) with ESMTP id 2D00A59C3BD; Thu, 30 Jan 2020 21:08:32 -0500 (EST) Received: from zblaxell by waya.furryterror.org with local (Exim 4.92) (envelope-from ) id 1ixLjT-00008p-VZ; Thu, 30 Jan 2020 21:08:32 -0500 From: Zygo Blaxell To: linux-btrfs@vger.kernel.org Subject: [PATCH] inspect: make sure LOGICAL_INO_V2 args are zero-initialized Date: Thu, 30 Jan 2020 21:08:23 -0500 Message-Id: <20200131020823.29824-1-ce3g8jdj@umail.furryterror.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org LOGICAL_INO v1 ignored the reserved fields, so they could be filled with random stack garbage and have no effect. LOGICAL_INO_V2 requires all unused reserved bits to be set to zero, and returns EINVAL if they are not, to guard against future kernel versions which may interpret non-zero bit values. Sometimes when 'btrfs ins log' runs, the stack garbage is zeros, so the -o (ignore offsets) option for logical-resolve works. Sometimes the stack garbage is something else, and 'btrfs ins log -o' fails with invalid argument. This depends mostly on compiler version and build environment details, so a binary typically either always works or never works. Fix by initializing logical-resolve's argument structure with a C99 compound literal zero. Signed-off-by: Zygo Blaxell Reviewed-by: Qu Wenruo --- cmds/inspect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds/inspect.c b/cmds/inspect.c index 9ca78611..5b946da0 100644 --- a/cmds/inspect.c +++ b/cmds/inspect.c @@ -149,7 +149,7 @@ static int cmd_inspect_logical_resolve(const struct cmd_struct *cmd, int verbose = 0; int getpath = 1; int bytes_left; - struct btrfs_ioctl_logical_ino_args loi; + struct btrfs_ioctl_logical_ino_args loi = { 0 }; struct btrfs_data_container *inodes; u64 size = SZ_64K; char full_path[PATH_MAX];