mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chandradhar Kumar <chandradhar.2003@gmail.com>
To: dhowells@redhat.com
Cc: netfs@lists.linux.dev, linux-kernel@vger.kernel.org,
	Chandradhar Kumar <chandradhar.2003@gmail.com>,
	syzbot+62b392c7348147ad767d@syzkaller.appspotmail.com
Subject: [PATCH] cachefiles: Fix OOB access in coherency trace
Date: Mon, 17 Aug 2026 00:25:48 +0530	[thread overview]
Message-ID: <20260816185548.292045-1-chandradhar.2003@gmail.com> (raw)

The coherency trace read the first 8 bytes of the auxiliary data with
be64_to_cpup(). However the auxiliary data stored in a cachefiles
xattr is variable length.

9P uses the 4-byte QID version as auxiliary data. Thus buf->data
contains only those 4 bytes, but the coherency trace unconditionally
reads 8 bytes from it, causing KASAN slab-out-of-bounds report.

Copy up to the first 8 bytes of the auxiliary data into an 8-byte
buffer before reading it as a big-endian value.

Fixes: 229105e5cfd9 ("cachefiles: Add auxiliary data trace")
Reported-by: syzbot+62b392c7348147ad767d@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=62b392c7348147ad767d
Signed-off-by: Chandradhar Kumar <chandradhar.2003@gmail.com>
---
 fs/cachefiles/xattr.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/fs/cachefiles/xattr.c b/fs/cachefiles/xattr.c
index f8ae78b3f7b6..e4cd635e8abe 100644
--- a/fs/cachefiles/xattr.c
+++ b/fs/cachefiles/xattr.c
@@ -25,6 +25,14 @@ struct cachefiles_xattr {
 	__u8	data[];		/* netfs coherency data */
 } __packed;
 
+static u64 cachefiles_get_aux_u64(const void *data, unsigned int len)
+{
+	__be64 aux = 0;
+
+	memcpy(&aux, data, min_t(unsigned int, len, sizeof(aux)));
+	return be64_to_cpup(&aux);
+}
+
 static const char cachefiles_xattr_cache[] =
 	XATTR_USER_PREFIX "CacheFiles.cache";
 
@@ -77,7 +85,7 @@ int cachefiles_set_object_xattr(struct cachefiles_object *object)
 		trace_cachefiles_vfs_error(object, file_inode(file), ret,
 					   cachefiles_trace_setxattr_error);
 		trace_cachefiles_coherency(object, file_inode(file)->i_ino,
-					   be64_to_cpup((__be64 *)buf->data),
+					   cachefiles_get_aux_u64(buf->data, len),
 					   buf->content,
 					   cachefiles_coherency_set_fail);
 		if (ret != -ENOMEM)
@@ -86,7 +94,7 @@ int cachefiles_set_object_xattr(struct cachefiles_object *object)
 				"Failed to set xattr with error %d", ret);
 	} else {
 		trace_cachefiles_coherency(object, file_inode(file)->i_ino,
-					   be64_to_cpup((__be64 *)buf->data),
+					   cachefiles_get_aux_u64(buf->data, len),
 					   buf->content,
 					   cachefiles_coherency_set_ok);
 	}
@@ -148,7 +156,7 @@ int cachefiles_check_auxdata(struct cachefiles_object *object, struct file *file
 
 out:
 	trace_cachefiles_coherency(object, file_inode(file)->i_ino,
-				   be64_to_cpup((__be64 *)buf->data),
+				   cachefiles_get_aux_u64(buf->data, len),
 				   buf->content, why);
 	kfree(buf);
 	return ret;
-- 
2.55.0


                 reply	other threads:[~2026-08-16 18:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260816185548.292045-1-chandradhar.2003@gmail.com \
    --to=chandradhar.2003@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netfs@lists.linux.dev \
    --cc=syzbot+62b392c7348147ad767d@syzkaller.appspotmail.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

all inboxes | Powered by JetHome®