From: Carlos Maiolino <cem@kernel.org>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Christian Brauner <brauner@kernel.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Jan Kara <jack@suse.cz>, Miklos Szeredi <miklos@szeredi.hu>,
Chris Mason <mason@kernel.org>, Christoph Hellwig <hch@lst.de>,
Theodore Ts'o <tytso@mit.edu>,
linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org,
stable@vger.kernel.org,
Alexander Mikhalitsyn <alex@amutable.com>
Subject: Re: [PATCH v3] xattr: enforce the name and size limits for in-kernel callers
Date: Wed, 25 Nov 2026 09:35:53 +0100 [thread overview]
Message-ID: <awad0QRdTtG6sLUP@cronus.toxiclabs.cc> (raw)
In-Reply-To: <20261125055900.2077059-1-amir73il@gmail.com>
On Wed, Nov 25, 2026 at 06:59:00AM +0100, Amir Goldstein wrote:
> The xattr system calls refuse an empty name, a name longer than
> XATTR_NAME_MAX and a value larger than XATTR_SIZE_MAX, but the VFS
> helpers do not. An in-kernel caller may pass a name or a size that it
> got from another filesystem, such as overlayfs copy up from a lower
> layer.
>
> Check these limits before calling the xattr handler of the filesystem,
> and fail with the errors that the system calls return for them.
>
> Cc: stable@vger.kernel.org
> Reviewed-by: Alexander Mikhalitsyn <alex@amutable.com>
> Reviewed-by: Jan Kara <jack@suse.cz>
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
Looks good to me:
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
>
> Changes since v2:
> - Rename the helper to xattr_check_name_len() (Carlos)
> - Also refuse an empty name (Carlos)
> - Add Reviewed-by tags
>
> Changes since v1:
> - Check the name in vfs_getxattr_alloc() too (Alex)
>
> v2: https://lore.kernel.org/r/20261123165807.1939942-1-amir73il@gmail.com/
> v1: https://lore.kernel.org/r/20261123113513.1910906-1-amir73il@gmail.com/
>
> fs/xattr.c | 38 +++++++++++++++++++++++++++++++++++++-
> 1 file changed, 37 insertions(+), 1 deletion(-)
>
> diff --git a/fs/xattr.c b/fs/xattr.c
> index 0705801a62cc5..64df10ed498c3 100644
> --- a/fs/xattr.c
> +++ b/fs/xattr.c
> @@ -178,6 +178,21 @@ xattr_permission(const struct mnt_idmap *idmap, struct inode *inode,
> return inode_permission(idmap, inode, mask);
> }
>
> +/*
> + * The xattr system calls refuse an empty name, a name above XATTR_NAME_MAX
> + * and a value above XATTR_SIZE_MAX, but an in-kernel caller may pass a name or
> + * a size that it got from another filesystem, such as the lower layer of
> + * overlayfs.
> + */
> +static int xattr_check_name_len(const char *name)
> +{
> + size_t len = strnlen(name, XATTR_NAME_MAX + 1);
> +
> + if (!len || len > XATTR_NAME_MAX)
> + return -ERANGE;
> + return 0;
> +}
> +
> /*
> * Look for any handler that deals with the specified namespace.
> */
> @@ -209,10 +224,17 @@ __vfs_setxattr(const struct mnt_idmap *idmap, struct dentry *dentry,
> size_t size, int flags)
> {
> const struct xattr_handler *handler;
> + int error;
>
> if (is_posix_acl_xattr(name))
> return -EOPNOTSUPP;
>
> + error = xattr_check_name_len(name);
> + if (error)
> + return error;
> + if (size > XATTR_SIZE_MAX)
> + return -E2BIG;
> +
> handler = xattr_resolve_name(inode, &name);
> if (IS_ERR(handler))
> return PTR_ERR(handler);
> @@ -408,6 +430,10 @@ vfs_getxattr_alloc(const struct mnt_idmap *idmap, struct dentry *dentry,
> if (error)
> return error;
>
> + error = xattr_check_name_len(name);
> + if (error)
> + return error;
> +
> handler = xattr_resolve_name(inode, &name);
> if (IS_ERR(handler))
> return PTR_ERR(handler);
> @@ -416,6 +442,8 @@ vfs_getxattr_alloc(const struct mnt_idmap *idmap, struct dentry *dentry,
> error = handler->get(handler, dentry, inode, name, NULL, 0);
> if (error < 0)
> return error;
> + if (error > XATTR_SIZE_MAX)
> + return -E2BIG;
>
> if (!value || (error > xattr_size)) {
> value = krealloc(*xattr_value, error + 1, flags);
> @@ -434,16 +462,24 @@ __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
> void *value, size_t size)
> {
> const struct xattr_handler *handler;
> + ssize_t ret;
>
> if (is_posix_acl_xattr(name))
> return -EOPNOTSUPP;
>
> + ret = xattr_check_name_len(name);
> + if (ret)
> + return ret;
> +
> handler = xattr_resolve_name(inode, &name);
> if (IS_ERR(handler))
> return PTR_ERR(handler);
> if (!handler->get)
> return -EOPNOTSUPP;
> - return handler->get(handler, dentry, inode, name, value, size);
> + ret = handler->get(handler, dentry, inode, name, value, size);
> + if (ret > XATTR_SIZE_MAX)
> + return -E2BIG;
> + return ret;
> }
> EXPORT_SYMBOL(__vfs_getxattr);
>
> --
> 2.56.1
>
>
next prev parent reply other threads:[~2026-11-25 8:35 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 11:35 [PATCH] xattr: enforce the name and size limits for in-kernel callers Amir Goldstein
2026-11-23 14:08 ` Alexander Mikhalitsyn
2026-11-23 16:58 ` [PATCH v2] " Amir Goldstein
2026-11-23 19:09 ` Alexander Mikhalitsyn
2026-11-24 12:29 ` Carlos Maiolino
2026-11-25 5:29 ` Christoph Hellwig
2026-11-24 17:06 ` Jan Kara
2026-11-25 5:59 ` [PATCH v3] " Amir Goldstein
2026-11-25 6:06 ` Christoph Hellwig
2026-11-25 8:35 ` Carlos Maiolino [this message]
2026-12-01 10:37 ` Christian Brauner
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=awad0QRdTtG6sLUP@cronus.toxiclabs.cc \
--to=cem@kernel.org \
--cc=alex@amutable.com \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=mason@kernel.org \
--cc=miklos@szeredi.hu \
--cc=stable@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.