LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] fs: Detect API misuse of i_op->lookup
@ 2015-01-25 21:57 Richard Weinberger
2015-01-25 22:16 ` Al Viro
0 siblings, 1 reply; 3+ messages in thread
From: Richard Weinberger @ 2015-01-25 21:57 UTC (permalink / raw)
To: viro; +Cc: linux-fsdevel, linux-kernel, Richard Weinberger
Hunting down a refcount issue in an out-of-tree filesystem uncovered
that its lookup function directly returned the dentry which was passed to it.
Add a BUG_ON() to detect such misuse in future.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
fs/namei.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/namei.c b/fs/namei.c
index bc35b02..f8ccae6 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1370,6 +1370,7 @@ static struct dentry *lookup_real(struct inode *dir, struct dentry *dentry,
old = dir->i_op->lookup(dir, dentry, flags);
if (unlikely(old)) {
+ BUG_ON(old == dentry);
dput(dentry);
dentry = old;
}
--
2.2.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] fs: Detect API misuse of i_op->lookup
2015-01-25 21:57 [PATCH] fs: Detect API misuse of i_op->lookup Richard Weinberger
@ 2015-01-25 22:16 ` Al Viro
2015-01-25 22:20 ` Richard Weinberger
0 siblings, 1 reply; 3+ messages in thread
From: Al Viro @ 2015-01-25 22:16 UTC (permalink / raw)
To: Richard Weinberger; +Cc: linux-fsdevel, linux-kernel
On Sun, Jan 25, 2015 at 10:57:40PM +0100, Richard Weinberger wrote:
> Hunting down a refcount issue in an out-of-tree filesystem uncovered
> that its lookup function directly returned the dentry which was passed to it.
> Add a BUG_ON() to detect such misuse in future.
In principle, it's not a bug. You *must* grab a reference to dentry before
returning it, but you can very well decide to return the one you've got -
any place where have ->lookup() return NULL has every right to become
return dget(dentry).
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] fs: Detect API misuse of i_op->lookup
2015-01-25 22:16 ` Al Viro
@ 2015-01-25 22:20 ` Richard Weinberger
0 siblings, 0 replies; 3+ messages in thread
From: Richard Weinberger @ 2015-01-25 22:20 UTC (permalink / raw)
To: Al Viro; +Cc: linux-fsdevel, linux-kernel
Am 25.01.2015 um 23:16 schrieb Al Viro:
> On Sun, Jan 25, 2015 at 10:57:40PM +0100, Richard Weinberger wrote:
>> Hunting down a refcount issue in an out-of-tree filesystem uncovered
>> that its lookup function directly returned the dentry which was passed to it.
>> Add a BUG_ON() to detect such misuse in future.
>
> In principle, it's not a bug. You *must* grab a reference to dentry before
> returning it, but you can very well decide to return the one you've got -
> any place where have ->lookup() return NULL has every right to become
> return dget(dentry).
Thanks for the clarification! The filesystem in question did of course
not grab a reference before returning the same dentry.
Thanks,
//richard
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-01-25 22:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-25 21:57 [PATCH] fs: Detect API misuse of i_op->lookup Richard Weinberger
2015-01-25 22:16 ` Al Viro
2015-01-25 22:20 ` Richard Weinberger
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).