From: Al Viro <viro@zeniv.linux.org.uk>
To: Christian Brauner <brauner@kernel.org>
Cc: Greg KH <gregkh@linuxfoundation.org>,
Kirtikumar Anandrao Ramchandani <kirtiar15502@gmail.com>,
security@kernel.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org,
Linus Torvalds <torvalds@linuxfoundation.org>
Subject: Re: Patch for a overwriting/corruption of the file system
Date: Tue, 14 Mar 2023 16:57:08 +0000 [thread overview]
Message-ID: <20230314165708.GY3390869@ZenIV> (raw)
In-Reply-To: <20230314095539.zf7uy27cjflqp6kp@wittgenstein>
On Tue, Mar 14, 2023 at 10:55:39AM +0100, Christian Brauner wrote:
> On Mon, Mar 13, 2023 at 11:32:08AM +0100, Greg KH wrote:
> > On Mon, Mar 13, 2023 at 03:54:55PM +0530, Kirtikumar Anandrao Ramchandani wrote:
> > > Seems like again it got rejected. I am sending it in the body if it works:
> > >
> > > >From 839cae91705e044b49397590f2d85a5dd289f0c5 Mon Sep 17 00:00:00 2001
> > > From: KirtiRamchandani <kirtar15502@gmail.com>
> > > Date: Mon, 13 Mar 2023 15:05:08 +0530
> > > Subject: [PATCH] Fix bug in affs_rename() function. The `affs_rename()`
> > > function in the AFFS filesystem has a bug that can cause the `retval`
> > > variable to be overwritten before it is used. Specifically, the function
> > > assigns `retval` a value in two separate code blocks, but then only checks
> > > its value in one of those blocks. This commit fixes the bug by ensuring
> > > that
> > > `retval` is properly checked in both code blocks.
> > >
> > > Signed-off-by: KirtiRamchandani <kirtar15502@gmail.com>
> > > ---
> > > namei.c | 4++++--
> > > 1 file changed, 4 insertions(+), 2 deletion(-)
> > >
> > > diff --git a/fs/affs/namei.c b/fs/affs/namei.c
> > > index d1084e5..a54c700 100644
> > > --- a/fs/affs/namei.c
> > > +++ b/fs/affs/namei.c
> > > @@ -488,7 +488,8 @@ affs_xrename(struct inode *old_dir, struct dentry
> > > *old_dentry,
> > > affs_lock_dir(new_dir);
> > > retval = affs_insert_hash(new_dir, bh_old);
> > > affs_unlock_dir(new_dir);
> > > -
> > > + if (retval)
> > > + goto done;
> >
> > The patch is corrupted and can not be applied.
>
> Yeah, that patch is pretty borked. This should probably be sm like:
>
> >From f3a7758bb53cc776820656c6ac66b13fb8ed9022 Mon Sep 17 00:00:00 2001
> From: KirtiRamchandani <kirtar15502@gmail.com>
> Date: Tue, 14 Mar 2023 10:49:38 +0100
> Subject: [PATCH] affs: handle errors in affs_xrename()
>
> Fix a bug in the affs_xrename() function. The affs_xrename() function in
> the AFFS filesystem has a bug that can cause the retval variable to be
> overwritten before it is used. Specifically, the function assigns retval
> a value in two separate code blocks, but then only checks its value in
> one of those blocks. This commit fixes the bug by ensuring that retval
> is properly checked in both code blocks.
"Properly checked" as in...?
> Signed-off-by: KirtiRamchandani <kirtar15502@gmail.com>
> ---
> fs/affs/namei.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/fs/affs/namei.c b/fs/affs/namei.c
> index d12ccfd2a83d..98525d69391d 100644
> --- a/fs/affs/namei.c
> +++ b/fs/affs/namei.c
> @@ -488,6 +488,8 @@ affs_xrename(struct inode *old_dir, struct dentry *old_dentry,
> affs_lock_dir(new_dir);
> retval = affs_insert_hash(new_dir, bh_old);
> affs_unlock_dir(new_dir);
> + if (retval)
> + goto done;
OK, so you've got an IO error and insertion has failed. Both entries had already
been removed from their directories. Sure, we must report an error, but why is
leaking *both* entries the right thing to do?
> /* Insert new into the old directory with the old name. */
> affs_copy_name(AFFS_TAIL(sb, bh_new)->name, old_dentry);
> @@ -495,6 +497,8 @@ affs_xrename(struct inode *old_dir, struct dentry *old_dentry,
> affs_lock_dir(old_dir);
> retval = affs_insert_hash(old_dir, bh_new);
> affs_unlock_dir(old_dir);
> + if (retval)
> + goto done;
> done:
Really? How could that possibly make any sense? I mean, look for the target of
that goto...
The bug here (AFFS awful layout aside) is that error from the first insert_hash
is always lost. And it needs to be reported. But this is no way to fix that.
next prev parent reply other threads:[~2023-03-14 16:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CADZg-m0Z+dOGfG=ddJxqPvgFwG0+OLAyP157SNzj6R6J2p7L-g@mail.gmail.com>
2023-03-13 10:16 ` Greg KH
[not found] ` <CADZg-m04XELrO-v-uYZ4PyYHXVPX35dgWbCHBpZvwepS4XV9Ew@mail.gmail.com>
[not found] ` <CADZg-m2k_L8-byX0WKYw5Cj1JPPhxk3HCBexpqPtZvcLRNY8Ug@mail.gmail.com>
2023-03-13 10:32 ` Greg KH
2023-03-14 9:55 ` Christian Brauner
2023-03-14 16:57 ` Al Viro [this message]
2023-03-14 17:13 ` Christian Brauner
[not found] ` <CADZg-m3w_xJ3cQS=+-yb7iS5PJg8kGHntMb7poP6tOsOXvnDeQ@mail.gmail.com>
[not found] ` <CADZg-m1uBXit9gX0bcZQ3vWvg34J_sLX-df32x+JX=bjtJeg0w@mail.gmail.com>
2023-04-21 3:00 ` Al Viro
2023-04-21 3:05 ` Al Viro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230314165708.GY3390869@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=brauner@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=kirtiar15502@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=security@kernel.org \
--cc=torvalds@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®