From: Miklos Szeredi <miklos@szeredi.hu>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Phasip <phasip@gmail.com>, overlayfs <linux-unionfs@vger.kernel.org>
Subject: Re: Kernel warnings in fs/inode.c:302 drop_nlink+0x28/0x40
Date: Mon, 23 Mar 2020 15:53:24 +0100 [thread overview]
Message-ID: <CAJfpeguKujUqW-z75F+6mCh0uwHF6rz2cK4OWUCFe83QNmaSrQ@mail.gmail.com> (raw)
In-Reply-To: <CAJfpegtCn-HLhuDB98G4dO8L-t2PMcqcwDw+0TiknU5LGvBacQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 633 bytes --]
On Mon, Mar 23, 2020 at 3:21 PM Miklos Szeredi <miklos@szeredi.hu> wrote:
>
> On Mon, Mar 23, 2020 at 2:24 PM Amir Goldstein <amir73il@gmail.com> wrote:
> > IDGI. coming from vfs_unlink() and vfs_rename() it doesn't look like
> > it is possible for victim inode not to have a hashed alias, so the
> > alias test seems futile.
>
> Yeah, needs a comment: both ovl_remove_upper() and
> ovl_remove_and_whiteout() unhash the dentry before returning, so
> d_find_alias() will find another hashed dentry or none.
Except that doesn't seem to be true for the overwriting rename case...
Attached patch should work for both.
Thanks,
Miklos
[-- Attachment #2: ovl-prevent-negative-nlink-v2.patch --]
[-- Type: text/x-patch, Size: 1344 bytes --]
---
fs/overlayfs/dir.c | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
--- a/fs/overlayfs/dir.c
+++ b/fs/overlayfs/dir.c
@@ -819,6 +819,27 @@ static bool ovl_pure_upper(struct dentry
!ovl_test_flag(OVL_WHITEOUTS, d_inode(dentry));
}
+static void ovl_drop_nlink(struct dentry *dentry)
+{
+ struct inode *inode = d_inode(dentry);
+ struct dentry *alias;
+
+ spin_lock(&inode->i_lock);
+ hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) {
+ if (alias != dentry && !d_unhashed(alias))
+ break;
+ }
+ spin_unlock(&inode->i_lock);
+
+ /*
+ * Changes to underlying layers may cause i_nlink to lose sync with
+ * reality. In this case prevent the link count from going to zero
+ * prematurely.
+ */
+ if (inode->i_nlink > !!alias)
+ drop_nlink(inode);
+}
+
static int ovl_do_remove(struct dentry *dentry, bool is_dir)
{
int err;
@@ -856,7 +877,7 @@ static int ovl_do_remove(struct dentry *
if (is_dir)
clear_nlink(dentry->d_inode);
else
- drop_nlink(dentry->d_inode);
+ ovl_drop_nlink(dentry);
}
ovl_nlink_end(dentry);
@@ -1201,7 +1222,7 @@ static int ovl_rename(struct inode *oldd
if (new_is_dir)
clear_nlink(d_inode(new));
else
- drop_nlink(d_inode(new));
+ ovl_drop_nlink(new);
}
ovl_dir_modified(old->d_parent, ovl_type_origin(old) ||
next prev parent reply other threads:[~2020-03-23 14:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAFkON1U3cXdXFQYdkoQ3OQU+14GX7C88U6qre58vyfhrrFgKXw@mail.gmail.com>
2020-03-23 12:52 ` Kernel warnings in fs/inode.c:302 drop_nlink+0x28/0x40 Miklos Szeredi
2020-03-23 13:23 ` Amir Goldstein
2020-03-23 14:21 ` Miklos Szeredi
2020-03-23 14:53 ` Miklos Szeredi [this message]
2020-03-23 17:27 ` Amir Goldstein
2020-03-23 19:15 ` Amir Goldstein
2020-03-24 6:27 ` Amir Goldstein
2020-03-23 14:27 ` Miklos Szeredi
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=CAJfpeguKujUqW-z75F+6mCh0uwHF6rz2cK4OWUCFe83QNmaSrQ@mail.gmail.com \
--to=miklos@szeredi.hu \
--cc=amir73il@gmail.com \
--cc=linux-unionfs@vger.kernel.org \
--cc=phasip@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).