* [PATCH] xfs_io: fix memory leak in add_enckey
@ 2019-11-07 16:50 Eric Sandeen
2019-11-07 20:29 ` Bill O'Donnell
2019-11-07 21:46 ` Eric Biggers
0 siblings, 2 replies; 8+ messages in thread
From: Eric Sandeen @ 2019-11-07 16:50 UTC (permalink / raw)
To: linux-xfs; +Cc: Eric Biggers
Invalid arguments to add_enckey will leak the "arg" allocation,
so fix that.
Fixes: ba71de04 ("xfs_io/encrypt: add 'add_enckey' command")
Fixes-coverity-id: 1454644
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
diff --git a/io/encrypt.c b/io/encrypt.c
index 17d61cfb..c6a4e190 100644
--- a/io/encrypt.c
+++ b/io/encrypt.c
@@ -696,6 +696,7 @@ add_enckey_f(int argc, char **argv)
goto out;
break;
default:
+ free(arg);
return command_usage(&add_enckey_cmd);
}
}
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH] xfs_io: fix memory leak in add_enckey 2019-11-07 16:50 [PATCH] xfs_io: fix memory leak in add_enckey Eric Sandeen @ 2019-11-07 20:29 ` Bill O'Donnell 2019-11-07 21:46 ` Eric Biggers 1 sibling, 0 replies; 8+ messages in thread From: Bill O'Donnell @ 2019-11-07 20:29 UTC (permalink / raw) To: Eric Sandeen; +Cc: linux-xfs, Eric Biggers On Thu, Nov 07, 2019 at 10:50:59AM -0600, Eric Sandeen wrote: > Invalid arguments to add_enckey will leak the "arg" allocation, > so fix that. > > Fixes: ba71de04 ("xfs_io/encrypt: add 'add_enckey' command") > Fixes-coverity-id: 1454644 > Signed-off-by: Eric Sandeen <sandeen@redhat.com> Reviewed-by: Bill O'Donnell <billodo@redhat.com> > --- > > diff --git a/io/encrypt.c b/io/encrypt.c > index 17d61cfb..c6a4e190 100644 > --- a/io/encrypt.c > +++ b/io/encrypt.c > @@ -696,6 +696,7 @@ add_enckey_f(int argc, char **argv) > goto out; > break; > default: > + free(arg); > return command_usage(&add_enckey_cmd); > } > } > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] xfs_io: fix memory leak in add_enckey 2019-11-07 16:50 [PATCH] xfs_io: fix memory leak in add_enckey Eric Sandeen 2019-11-07 20:29 ` Bill O'Donnell @ 2019-11-07 21:46 ` Eric Biggers 2019-11-07 21:58 ` Eric Sandeen 1 sibling, 1 reply; 8+ messages in thread From: Eric Biggers @ 2019-11-07 21:46 UTC (permalink / raw) To: Eric Sandeen; +Cc: linux-xfs On Thu, Nov 07, 2019 at 10:50:59AM -0600, Eric Sandeen wrote: > Invalid arguments to add_enckey will leak the "arg" allocation, > so fix that. > > Fixes: ba71de04 ("xfs_io/encrypt: add 'add_enckey' command") > Fixes-coverity-id: 1454644 > Signed-off-by: Eric Sandeen <sandeen@redhat.com> > --- > > diff --git a/io/encrypt.c b/io/encrypt.c > index 17d61cfb..c6a4e190 100644 > --- a/io/encrypt.c > +++ b/io/encrypt.c > @@ -696,6 +696,7 @@ add_enckey_f(int argc, char **argv) > goto out; > break; > default: > + free(arg); > return command_usage(&add_enckey_cmd); > } > } > The same leak happens later in the function too. How about this instead: diff --git a/io/encrypt.c b/io/encrypt.c index 17d61cfb..de48c50c 100644 --- a/io/encrypt.c +++ b/io/encrypt.c @@ -678,6 +678,7 @@ add_enckey_f(int argc, char **argv) int c; struct fscrypt_add_key_arg *arg; ssize_t raw_size; + int retval = 0; arg = calloc(1, sizeof(*arg) + FSCRYPT_MAX_KEY_SIZE + 1); if (!arg) { @@ -696,14 +697,17 @@ add_enckey_f(int argc, char **argv) goto out; break; default: - return command_usage(&add_enckey_cmd); + retval = command_usage(&add_enckey_cmd); + goto out; } } argc -= optind; argv += optind; - if (argc != 0) - return command_usage(&add_enckey_cmd); + if (argc != 0) { + retval = command_usage(&add_enckey_cmd); + goto out; + } raw_size = read_until_limit_or_eof(STDIN_FILENO, arg->raw, FSCRYPT_MAX_KEY_SIZE + 1); @@ -732,7 +736,7 @@ add_enckey_f(int argc, char **argv) out: memset(arg->raw, 0, FSCRYPT_MAX_KEY_SIZE + 1); free(arg); - return 0; + return retval; } static int ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] xfs_io: fix memory leak in add_enckey 2019-11-07 21:46 ` Eric Biggers @ 2019-11-07 21:58 ` Eric Sandeen 2019-11-11 15:13 ` Eric Sandeen 0 siblings, 1 reply; 8+ messages in thread From: Eric Sandeen @ 2019-11-07 21:58 UTC (permalink / raw) To: Eric Sandeen, linux-xfs On 11/7/19 3:46 PM, Eric Biggers wrote: > On Thu, Nov 07, 2019 at 10:50:59AM -0600, Eric Sandeen wrote: >> Invalid arguments to add_enckey will leak the "arg" allocation, >> so fix that. >> >> Fixes: ba71de04 ("xfs_io/encrypt: add 'add_enckey' command") >> Fixes-coverity-id: 1454644 >> Signed-off-by: Eric Sandeen <sandeen@redhat.com> >> --- >> >> diff --git a/io/encrypt.c b/io/encrypt.c >> index 17d61cfb..c6a4e190 100644 >> --- a/io/encrypt.c >> +++ b/io/encrypt.c >> @@ -696,6 +696,7 @@ add_enckey_f(int argc, char **argv) >> goto out; >> break; >> default: >> + free(arg); >> return command_usage(&add_enckey_cmd); >> } >> } >> > > The same leak happens later in the function too. How about this instead: whoops yes it does. I kind of hate "retval = command_usage" but seeing the memset of the key on the way out it's probably prudent to have one common exit point after the function gets started. Care to send this as a formal patch? Thanks, -Eric > diff --git a/io/encrypt.c b/io/encrypt.c > index 17d61cfb..de48c50c 100644 > --- a/io/encrypt.c > +++ b/io/encrypt.c > @@ -678,6 +678,7 @@ add_enckey_f(int argc, char **argv) > int c; > struct fscrypt_add_key_arg *arg; > ssize_t raw_size; > + int retval = 0; > > arg = calloc(1, sizeof(*arg) + FSCRYPT_MAX_KEY_SIZE + 1); > if (!arg) { > @@ -696,14 +697,17 @@ add_enckey_f(int argc, char **argv) > goto out; > break; > default: > - return command_usage(&add_enckey_cmd); > + retval = command_usage(&add_enckey_cmd); > + goto out; > } > } > argc -= optind; > argv += optind; > > - if (argc != 0) > - return command_usage(&add_enckey_cmd); > + if (argc != 0) { > + retval = command_usage(&add_enckey_cmd); > + goto out; > + } > > raw_size = read_until_limit_or_eof(STDIN_FILENO, arg->raw, > FSCRYPT_MAX_KEY_SIZE + 1); > @@ -732,7 +736,7 @@ add_enckey_f(int argc, char **argv) > out: > memset(arg->raw, 0, FSCRYPT_MAX_KEY_SIZE + 1); > free(arg); > - return 0; > + return retval; > } > > static int > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] xfs_io: fix memory leak in add_enckey 2019-11-07 21:58 ` Eric Sandeen @ 2019-11-11 15:13 ` Eric Sandeen 2019-11-11 17:27 ` Eric Biggers 0 siblings, 1 reply; 8+ messages in thread From: Eric Sandeen @ 2019-11-11 15:13 UTC (permalink / raw) To: Eric Sandeen, linux-xfs On 11/7/19 3:58 PM, Eric Sandeen wrote: > On 11/7/19 3:46 PM, Eric Biggers wrote: >> On Thu, Nov 07, 2019 at 10:50:59AM -0600, Eric Sandeen wrote: >>> Invalid arguments to add_enckey will leak the "arg" allocation, >>> so fix that. >>> >>> Fixes: ba71de04 ("xfs_io/encrypt: add 'add_enckey' command") >>> Fixes-coverity-id: 1454644 >>> Signed-off-by: Eric Sandeen <sandeen@redhat.com> >>> --- >>> >>> diff --git a/io/encrypt.c b/io/encrypt.c >>> index 17d61cfb..c6a4e190 100644 >>> --- a/io/encrypt.c >>> +++ b/io/encrypt.c >>> @@ -696,6 +696,7 @@ add_enckey_f(int argc, char **argv) >>> goto out; >>> break; >>> default: >>> + free(arg); >>> return command_usage(&add_enckey_cmd); >>> } >>> } >>> >> >> The same leak happens later in the function too. How about this instead: > > whoops yes it does. I kind of hate "retval = command_usage" but seeing the > memset of the key on the way out it's probably prudent to have one common > exit point after the function gets started. > > Care to send this as a formal patch? <interprets silence as a "no"> ;) I'll just incorporate your fixes as an addendum to my patch, then. -Eric ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] xfs_io: fix memory leak in add_enckey 2019-11-11 15:13 ` Eric Sandeen @ 2019-11-11 17:27 ` Eric Biggers 2019-11-11 18:07 ` Eric Sandeen 0 siblings, 1 reply; 8+ messages in thread From: Eric Biggers @ 2019-11-11 17:27 UTC (permalink / raw) To: Eric Sandeen; +Cc: Eric Sandeen, linux-xfs On Mon, Nov 11, 2019 at 09:13:45AM -0600, Eric Sandeen wrote: > On 11/7/19 3:58 PM, Eric Sandeen wrote: > > On 11/7/19 3:46 PM, Eric Biggers wrote: > >> On Thu, Nov 07, 2019 at 10:50:59AM -0600, Eric Sandeen wrote: > >>> Invalid arguments to add_enckey will leak the "arg" allocation, > >>> so fix that. > >>> > >>> Fixes: ba71de04 ("xfs_io/encrypt: add 'add_enckey' command") > >>> Fixes-coverity-id: 1454644 > >>> Signed-off-by: Eric Sandeen <sandeen@redhat.com> > >>> --- > >>> > >>> diff --git a/io/encrypt.c b/io/encrypt.c > >>> index 17d61cfb..c6a4e190 100644 > >>> --- a/io/encrypt.c > >>> +++ b/io/encrypt.c > >>> @@ -696,6 +696,7 @@ add_enckey_f(int argc, char **argv) > >>> goto out; > >>> break; > >>> default: > >>> + free(arg); > >>> return command_usage(&add_enckey_cmd); > >>> } > >>> } > >>> > >> > >> The same leak happens later in the function too. How about this instead: > > > > whoops yes it does. I kind of hate "retval = command_usage" but seeing the > > memset of the key on the way out it's probably prudent to have one common > > exit point after the function gets started. > > > > Care to send this as a formal patch? > > <interprets silence as a "no"> ;) > > I'll just incorporate your fixes as an addendum to my patch, then. > > -Eric Sorry, I didn't receive this because I was dropped from Cc, and I'm not currently subscribed to linux-xfs. The patch you committed looks fine, thanks. - Eric ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] xfs_io: fix memory leak in add_enckey 2019-11-11 17:27 ` Eric Biggers @ 2019-11-11 18:07 ` Eric Sandeen 2019-11-14 21:09 ` Eric Biggers 0 siblings, 1 reply; 8+ messages in thread From: Eric Sandeen @ 2019-11-11 18:07 UTC (permalink / raw) To: Eric Sandeen, linux-xfs On 11/11/19 11:27 AM, Eric Biggers wrote: ... >>>> The same leak happens later in the function too. How about this instead: >>> >>> whoops yes it does. I kind of hate "retval = command_usage" but seeing the >>> memset of the key on the way out it's probably prudent to have one common >>> exit point after the function gets started. >>> >>> Care to send this as a formal patch? >> >> <interprets silence as a "no"> ;) >> >> I'll just incorporate your fixes as an addendum to my patch, then. >> >> -Eric > > Sorry, I didn't receive this because I was dropped from Cc, and I'm not > currently subscribed to linux-xfs. The patch you committed looks fine, thanks. Oh, I'm sorry about that, my mistake. Thanks, -Eric ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] xfs_io: fix memory leak in add_enckey 2019-11-11 18:07 ` Eric Sandeen @ 2019-11-14 21:09 ` Eric Biggers 0 siblings, 0 replies; 8+ messages in thread From: Eric Biggers @ 2019-11-14 21:09 UTC (permalink / raw) To: Eric Sandeen; +Cc: Eric Sandeen, linux-xfs On Mon, Nov 11, 2019 at 12:07:27PM -0600, Eric Sandeen wrote: > > > > Sorry, I didn't receive this because I was dropped from Cc, and I'm not > > currently subscribed to linux-xfs. The patch you committed looks fine, thanks. > > Oh, I'm sorry about that, my mistake. > And it happened again :-) For the record, this seems to have been my fault. My .muttrc was missing set followup_to = no and at some point I had added mailing list declarations including: subscribe .*@vger.kernel.org so Mutt was generating a Mail-Followup-To header excluding me. I hadn't noticed this problem earlier because I'm normally subscribed to one of the lists anyway. - Eric ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2019-11-14 21:09 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2019-11-07 16:50 [PATCH] xfs_io: fix memory leak in add_enckey Eric Sandeen 2019-11-07 20:29 ` Bill O'Donnell 2019-11-07 21:46 ` Eric Biggers 2019-11-07 21:58 ` Eric Sandeen 2019-11-11 15:13 ` Eric Sandeen 2019-11-11 17:27 ` Eric Biggers 2019-11-11 18:07 ` Eric Sandeen 2019-11-14 21:09 ` Eric Biggers
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox