Re: [PATCH v12 5/5] cachefiles: Preset the state xattr when creating a new file

From: Christian Brauner

Date: Wed Nov 18 2026 - 07:36:18 EST


On Fri, Sep 11, 2026 at 05:21:38PM -0300, Paulo Alcantara wrote:
> David Howells <dhowells@xxxxxxxxxx> writes:
> > + buf = kzalloc(sizeof(struct cachefiles_xattr) + min(len, sizeof(__be64)), GFP_KERNEL);
>
> You should use max() here.

Meh, this is in mainline since v7.4-rc1:

KASAN catches it reading a file through an -o fsc mount with an ext4
cache gives:

BUG: KASAN: slab-out-of-bounds in ext4_xattr_set_entry+0xf3d/0x1bd0
Read of size 58 by task kworker/u32:1/63
Workqueue: fscache fscache_cookie_worker
Call Trace:
__asan_memcpy+0x23/0x60
ext4_xattr_set_entry+0xf3d/0x1bd0
ext4_xattr_block_set+0x647/0x3080
ext4_xattr_set_handle+0xd19/0x1420
ext4_xattr_set+0x12a/0x380
__vfs_setxattr+0x10a/0x160
__vfs_setxattr_noperm+0xef/0x5d0
vfs_setxattr+0x148/0x3d0
cachefiles_preset_object_xattr+0x191/0x5e0
cachefiles_create_tmpfile+0x2c1/0x7f0
cachefiles_create_file+0x6a/0x2f0
cachefiles_look_up_object+0x715/0x8a0

With max() it's gone. David, unless you want to send it yourself I'll
put this into vfs.fixes:

diff --git a/fs/cachefiles/xattr.c b/fs/cachefiles/xattr.c
--- a/fs/cachefiles/xattr.c
+++ b/fs/cachefiles/xattr.c
@@ -44,7 +44,7 @@ int cachefiles_preset_object_xattr(struct cachefiles_object *object, struct file *file)
unsigned int len = object->cookie->aux_len;
int ret;

- buf = kzalloc(sizeof(struct cachefiles_xattr) + min(len, sizeof(__be64)), GFP_KERNEL);
+ buf = kzalloc(sizeof(struct cachefiles_xattr) + max(len, sizeof(__be64)), GFP_KERNEL);
if (!buf)
return -ENOMEM;


--