diff mbox series

inspect: make sure LOGICAL_INO_V2 args are zero-initialized

Message ID 20200131020823.29824-1-ce3g8jdj@umail.furryterror.org (mailing list archive)
State New, archived
Headers show
Series inspect: make sure LOGICAL_INO_V2 args are zero-initialized | expand

Commit Message

Zygo Blaxell Jan. 31, 2020, 2:08 a.m. UTC
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 <ce3g8jdj@umail.furryterror.org>
---
 cmds/inspect.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Qu Wenruo Jan. 31, 2020, 2:15 a.m. UTC | #1
On 2020/1/31 上午10:08, Zygo Blaxell wrote:
> 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 <ce3g8jdj@umail.furryterror.org>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> ---
>  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];
>
David Sterba March 4, 2020, 1:50 p.m. UTC | #2
On Thu, Jan 30, 2020 at 09:08:23PM -0500, Zygo Blaxell wrote:
> 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 <ce3g8jdj@umail.furryterror.org>

Added to devel, thanks.
diff mbox series

Patch

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];