linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: viro@zeniv.linux.org.uk,linux-fsdevel@vger.kernel.org
Cc: torvalds@linux-foundation.org,brauner@kernel.org,jack@suse.cz,raven@themaw.net,miklos@szeredi.hu,neil@brown.name,a.hindborg@kernel.org,linux-mm@kvack.org,linux-efi@vger.kernel.org,ocfs2-devel@lists.linux.dev,kees@kernel.org,rostedt@goodmis.org,gregkh@linuxfoundation.org,linux-usb@vger.kernel.org,paul@paul-moore.com,casey@schaufler-ca.com,linuxppc-dev@lists.ozlabs.org,john.johansen@canonical.com,selinux@vger.kernel.org,borntraeger@linux.ibm.com,bpf@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,clm@meta.com,ihor.solodrai@linux.dev
Subject: Re: [PATCH v3 34/50] selinuxfs: new helper for attaching files to tree
Date: Tue, 11 Nov 2025 07:53:18 +0000 (UTC)	[thread overview]
Message-ID: <70d825699c6e0a7e6cb978fdefba5935d5a515702e22e732d5c2ad919cfe010b@mail.kernel.org> (raw)
In-Reply-To: <20251111065520.2847791-35-viro@zeniv.linux.org.uk>

[-- Attachment #1: Type: text/plain, Size: 2457 bytes --]

> diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
> index b39e919c2..f088776db 100644
> --- a/security/selinux/selinuxfs.c
> +++ b/security/selinux/selinuxfs.c

[ ... ]

> @@ -1197,6 +1197,25 @@ static struct inode *sel_make_inode(struct super_block *sb, umode_t mode)
>  	return ret;
>  }
>
> +static struct dentry *sel_attach(struct dentry *parent, const char *name,
> +				 struct inode *inode)
> +{
> +	struct dentry *dentry = d_alloc_name(parent, name);
> +	if (unlikely(!dentry)) {
> +		iput(inode);
> +		return ERR_PTR(-ENOMEM);
> +	}
> +	d_add(dentry, inode);
> +	return dentry;
> +}
> +
> +static int sel_attach_file(struct dentry *parent, const char *name,
> +			   struct inode *inode)
> +{
> +	struct dentry *dentry = sel_attach(parent, name, inode);
> +	return PTR_ERR_OR_ZERO(dentry);
> +}

[ ... ]

> @@ -1887,31 +1887,23 @@ static struct dentry *sel_make_dir(struct dentry *dir, const char *name,
>  			unsigned long *ino)
>  {
> -	struct dentry *dentry = d_alloc_name(dir, name);
>  	struct inode *inode;
>
> -	if (!dentry)
> -		return ERR_PTR(-ENOMEM);
> -
>  	inode = sel_make_inode(dir->d_sb, S_IFDIR | S_IRUGO | S_IXUGO);
> -	if (!inode) {
> -		dput(dentry);
> +	if (!inode)
>  		return ERR_PTR(-ENOMEM);
> -	}
>
>  	inode->i_op = &simple_dir_inode_operations;
>  	inode->i_fop = &simple_dir_operations;
>  	inode->i_ino = ++(*ino);
>  	/* directory inodes start off with i_nlink == 2 (for "." entry) */
>  	inc_nlink(inode);
> -	d_add(dentry, inode);
>  	/* bump link count on parent directory, too */
>  	inc_nlink(d_inode(dir));
> +
> +	return sel_attach(dir, name, inode);
>  }

Can this leak the parent directory's reference count? The parent inode's
link count is incremented with inc_nlink(d_inode(dir)) before calling
sel_attach(). When sel_attach()->d_alloc_name() fails and returns NULL,
sel_attach() correctly cleans up the child inode with iput() and returns
ERR_PTR(-ENOMEM). However, the parent directory's link count has already
been incremented and is never decremented on this error path.

In the original code, the parent link count increment happened after
d_add() succeeded, ensuring it only occurred when the full operation
completed successfully.


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/19257803162

  reply	other threads:[~2025-11-11  7:53 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-11  6:54 [PATCH v3 00/50] tree-in-dcache stuff Al Viro
2025-11-11  6:54 ` [PATCH v3 01/50] fuse_ctl_add_conn(): fix nlink breakage in case of early failure Al Viro
2025-11-11 10:22   ` Miklos Szeredi
2025-11-11  6:54 ` [PATCH v3 02/50] tracefs: fix a leak in eventfs_create_events_dir() Al Viro
2025-11-11  6:54 ` [PATCH v3 03/50] new helper: simple_remove_by_name() Al Viro
2025-11-11 10:29   ` Miklos Szeredi
2025-11-11  6:54 ` [PATCH v3 04/50] new helper: simple_done_creating() Al Viro
2025-11-11  6:54 ` [PATCH v3 05/50] introduce a flag for explicitly marking persistently pinned dentries Al Viro
2025-11-11  6:54 ` [PATCH v3 06/50] primitives for maintaining persisitency Al Viro
2025-11-11  6:54 ` [PATCH v3 07/50] convert simple_{link,unlink,rmdir,rename,fill_super}() to new primitives Al Viro
2025-11-11  6:54 ` [PATCH v3 08/50] convert ramfs and tmpfs Al Viro
2025-11-11  6:54 ` [PATCH v3 09/50] procfs: make /self and /thread_self dentries persistent Al Viro
2025-11-11  6:54 ` [PATCH v3 10/50] configfs, securityfs: kill_litter_super() not needed Al Viro
2025-11-11  6:54 ` [PATCH v3 11/50] convert xenfs Al Viro
2025-11-11  6:54 ` [PATCH v3 12/50] convert smackfs Al Viro
2025-11-11  6:54 ` [PATCH v3 13/50] convert hugetlbfs Al Viro
2025-11-11  6:54 ` [PATCH v3 14/50] convert mqueue Al Viro
2025-11-11  6:54 ` [PATCH v3 15/50] convert bpf Al Viro
2025-11-11  6:54 ` [PATCH v3 16/50] convert dlmfs Al Viro
2025-11-11  6:54 ` [PATCH v3 17/50] convert fuse_ctl Al Viro
2025-11-11 10:28   ` Miklos Szeredi
2025-11-11  6:54 ` [PATCH v3 18/50] convert pstore Al Viro
2025-11-11  6:54 ` [PATCH v3 19/50] convert tracefs Al Viro
2025-11-11  6:54 ` [PATCH v3 20/50] convert debugfs Al Viro
2025-11-11  6:54 ` [PATCH v3 21/50] debugfs: remove duplicate checks in callers of start_creating() Al Viro
2025-11-11  6:54 ` [PATCH v3 22/50] convert efivarfs Al Viro
2025-11-11  6:54 ` [PATCH v3 23/50] convert spufs Al Viro
2025-11-11  6:54 ` [PATCH v3 24/50] convert ibmasmfs Al Viro
2025-11-11  6:54 ` [PATCH v3 25/50] ibmasmfs: get rid of ibmasmfs_dir_ops Al Viro
2025-11-11  6:54 ` [PATCH v3 26/50] convert devpts Al Viro
2025-11-11  6:54 ` [PATCH v3 27/50] binderfs: use simple_start_creating() Al Viro
2025-11-11  6:54 ` [PATCH v3 28/50] binderfs_binder_ctl_create(): kill a bogus check Al Viro
2025-11-11  6:54 ` [PATCH v3 29/50] convert binderfs Al Viro
2025-11-11  6:54 ` [PATCH v3 30/50] autofs_{rmdir,unlink}: dentry->d_fsdata->dentry == dentry there Al Viro
2025-11-11  6:55 ` [PATCH v3 31/50] convert autofs Al Viro
2025-11-11  6:55 ` [PATCH v3 32/50] convert binfmt_misc Al Viro
2025-11-11  6:55 ` [PATCH v3 33/50] selinuxfs: don't stash the dentry of /policy_capabilities Al Viro
2025-11-11  6:55 ` [PATCH v3 34/50] selinuxfs: new helper for attaching files to tree Al Viro
2025-11-11  7:53   ` bot+bpf-ci [this message]
2025-11-11  9:49     ` Al Viro
2025-11-12  3:55       ` Chris Mason
2025-11-11  6:55 ` [PATCH v3 35/50] convert selinuxfs Al Viro
2025-11-11  6:55 ` [PATCH v3 36/50] functionfs: switch to simple_remove_by_name() Al Viro
2025-11-11  7:53   ` bot+bpf-ci
2025-11-11  9:22     ` Al Viro
2025-11-11  9:30       ` Christian Brauner
2025-11-11 10:01         ` Al Viro
2025-11-11 14:25           ` Chris Mason
2025-11-12  3:44       ` Chris Mason
2025-11-13  9:26         ` [functionfs] mainline UAF (was Re: [PATCH v3 36/50] functionfs: switch to simple_remove_by_name()) Al Viro
2025-11-13 21:20           ` Greg Kroah-Hartman
2025-11-14  2:16             ` Chris Mason
2025-11-14  7:58               ` Al Viro
2025-11-14  7:46             ` Al Viro
2025-11-14 11:42               ` Christian Brauner
2025-11-15 13:21               ` Greg Kroah-Hartman
2025-11-16  6:30                 ` Al Viro
2025-11-17 22:04                 ` Al Viro
2025-11-17 22:04                   ` [PATCH 1/4] functionfs: don't abuse ffs_data_closed() on fs shutdown Al Viro
2025-11-17 22:05                   ` [PATCH 2/4] functionfs: don't bother with ffs->ref in ffs_data_{opened,closed}() Al Viro
2025-11-17 22:06                   ` [PATCH 3/4] functionfs: need to cancel ->reset_work in ->kill_sb() Al Viro
2025-11-17 22:06                   ` [PATCH 4/4] functionfs: fix the open/removal races Al Viro
2025-11-18  2:35                   ` [functionfs] mainline UAF (was Re: [PATCH v3 36/50] functionfs: switch to simple_remove_by_name()) Greg Kroah-Hartman
2025-11-11  6:55 ` [PATCH v3 37/50] convert functionfs Al Viro
2025-11-11  6:55 ` [PATCH v3 38/50] gadgetfs: switch to simple_remove_by_name() Al Viro
2025-11-11  6:55 ` [PATCH v3 39/50] convert gadgetfs Al Viro
2025-11-11  6:55 ` [PATCH v3 40/50] hypfs: don't pin dentries twice Al Viro
2025-11-11  6:55 ` [PATCH v3 41/50] hypfs: switch hypfs_create_str() to returning int Al Viro
2025-11-11  6:55 ` [PATCH v3 42/50] hypfs: swich hypfs_create_u64() " Al Viro
2025-11-11  6:55 ` [PATCH v3 43/50] convert hypfs Al Viro
2025-11-11  6:55 ` [PATCH v3 44/50] convert rpc_pipefs Al Viro
2025-11-11  6:55 ` [PATCH v3 45/50] convert nfsctl Al Viro
2025-11-11  6:55 ` [PATCH v3 46/50] convert rust_binderfs Al Viro
2025-11-11  6:55 ` [PATCH v3 47/50] get rid of kill_litter_super() Al Viro
2025-11-11  6:55 ` [PATCH v3 48/50] convert securityfs Al Viro
2025-11-11  6:55 ` [PATCH v3 49/50] kill securityfs_recursive_remove() Al Viro
2025-11-11  6:55 ` [PATCH v3 50/50] d_make_discardable(): warn if given a non-persistent dentry 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=70d825699c6e0a7e6cb978fdefba5935d5a515702e22e732d5c2ad919cfe010b@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=borntraeger@linux.ibm.com \
    --cc=bpf@vger.kernel.org \
    --cc=brauner@kernel.org \
    --cc=casey@schaufler-ca.com \
    --cc=clm@meta.com \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=ihor.solodrai@linux.dev \
    --cc=jack@suse.cz \
    --cc=john.johansen@canonical.com \
    --cc=kees@kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=martin.lau@kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=neil@brown.name \
    --cc=ocfs2-devel@lists.linux.dev \
    --cc=paul@paul-moore.com \
    --cc=raven@themaw.net \
    --cc=rostedt@goodmis.org \
    --cc=selinux@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=yonghong.song@linux.dev \
    /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