linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] fs: Fix memory leaks in do_renameat2() error paths
@ 2020-10-30 15:24 Qian Cai
  2020-10-30 15:27 ` Jens Axboe
  2020-10-30 18:42 ` Al Viro
  0 siblings, 2 replies; 17+ messages in thread
From: Qian Cai @ 2020-10-30 15:24 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Alexander Viro, linux-fsdevel, linux-kernel, Qian Cai

We will need to call putname() before do_renameat2() returning -EINVAL
to avoid memory leaks.

Fixes: 3c5499fa56f5 ("fs: make do_renameat2() take struct filename")
Signed-off-by: Qian Cai <cai@redhat.com>
---
 fs/namei.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index 27f5a4e025fd..9dc5e1b139c9 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -4362,11 +4362,11 @@ int do_renameat2(int olddfd, struct filename *oldname, int newdfd,
 	int error;
 
 	if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
-		return -EINVAL;
+		goto out;
 
 	if ((flags & (RENAME_NOREPLACE | RENAME_WHITEOUT)) &&
 	    (flags & RENAME_EXCHANGE))
-		return -EINVAL;
+		goto out;
 
 	if (flags & RENAME_EXCHANGE)
 		target_flags = 0;
@@ -4486,6 +4486,14 @@ int do_renameat2(int olddfd, struct filename *oldname, int newdfd,
 	}
 exit:
 	return error;
+out:
+	if (!IS_ERR(oldname))
+		putname(oldname);
+
+	if (!IS_ERR(newname))
+		putname(newname);
+
+	return -EINVAL;
 }
 
 SYSCALL_DEFINE5(renameat2, int, olddfd, const char __user *, oldname,
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2020-11-03 14:47 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-30 15:24 [PATCH -next] fs: Fix memory leaks in do_renameat2() error paths Qian Cai
2020-10-30 15:27 ` Jens Axboe
2020-10-30 15:52   ` Qian Cai
2020-10-30 16:49     ` Jens Axboe
2020-10-30 18:42 ` Al Viro
2020-10-30 18:46   ` Jens Axboe
2020-10-30 18:49     ` Al Viro
2020-10-30 20:33       ` Jens Axboe
2020-10-30 22:22         ` Al Viro
2020-10-30 23:21           ` Jens Axboe
2020-11-02 18:43             ` Eric W. Biederman
2020-11-02 19:27             ` Eric W. Biederman
2020-11-02 19:54               ` Jens Axboe
2020-11-02 20:12                 ` Eric W. Biederman
2020-11-02 20:31                   ` Jens Axboe
2020-11-02 21:39                     ` Jens Axboe
2020-11-03 14:45                       ` Eric W. Biederman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).