mirror of
https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9.git
synced 2026-09-09 00:08:12 +08:00
Merge: CVE-2026-23002: lib/buildid: use __kernel_read() for sleepable context
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/8297 JIRA: https://redhat.atlassian.net/browse/RHEL-189963 CVE: CVE-2026-23002 Backported from tree(s): linux ``` lib/buildid: use __kernel_read() for sleepable context Prevent a "BUG: unable to handle kernel NULL pointer dereference in filemap_read_folio". For the sleepable context, convert freader to use __kernel_read() instead of direct page cache access via read_cache_folio(). This simplifies the faultable code path by using the standard kernel file reading interface which handles all the complexity of reading file data. At the moment we are not changing the code for non-sleepable context which uses filemap_get_folio() and only succeeds if the target folios are already in memory and up-to-date. The reason is to keep the patch simple and easier to backport to stable kernels. Syzbot repro does not crash the kernel anymore and the selftests run successfully. In the follow up we will make __kernel_read() with IOCB_NOWAIT work for non-sleepable contexts. In addition, I would like to replace the secretmem check with a more generic approach and will add fstest for the buildid code. Link: https://lkml.kernel.org/r/20251222205859.3968077-1-shakeel.butt@linux.dev Fixes: ad41251c290d ("lib/buildid: implement sleepable build_id_parse() API") Reported-by: syzbot+09b7d050e4806540153d@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=09b7d050e4806540153d Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev> Reviewed-by: Christoph Hellwig <hch@lst.de> Tested-by: Jinchao Wang <wangjinchao600@gmail.com> Link: https://lkml.kernel.org/r/aUteBPWPYzVWIZFH@ndev Reviewed-by: Christian Brauner <brauner@kernel.org> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Andrii Nakryiko <andrii@kernel.org> Cc: Daniel Borkman <daniel@iogearbox.net> Cc: "Darrick J. Wong" <djwong@kernel.org> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit 777a8560fd29738350c5094d4166fe5499452409) ``` Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com> [^footer]: Created 2026-06-29 12:51 UTC by backporter - [KWF FAQ](https://red.ht/kernel_workflow_doc) - [Slack #team-kernel-workflow](https://redhat-internal.slack.com/archives/C04LRUPMJQ5) - [Source](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/webhook/utils/backporter.py) - [Documentation](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/docs/README.backporter.md) - [Report an issue](https://redhat.atlassian.net/secure/CreateIssueDetails!init.jspa?pid=11779&issuetype=10016&priority=10001&summary=backporter+webhook+issue&components=66291) [^footer] Approved-by: Ines Qian <iqian@redhat.com> Approved-by: Rafael Aquini <raquini@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: CKI GitLab Kmaint Pipeline Bot <26919896-cki-kmaint-pipeline-bot@users.noreply.gitlab.com>
This commit is contained in:
+20
-12
@@ -5,6 +5,7 @@
|
||||
#include <linux/elf.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/pagemap.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/secretmem.h>
|
||||
|
||||
#define BUILD_ID 3
|
||||
@@ -65,20 +66,9 @@ static int freader_get_folio(struct freader *r, loff_t file_off)
|
||||
|
||||
freader_put_folio(r);
|
||||
|
||||
/* reject secretmem folios created with memfd_secret() */
|
||||
if (secretmem_mapping(r->file->f_mapping))
|
||||
return -EFAULT;
|
||||
|
||||
/* only use page cache lookup - fail if not already cached */
|
||||
r->folio = filemap_get_folio(r->file->f_mapping, file_off >> PAGE_SHIFT);
|
||||
|
||||
/* if sleeping is allowed, wait for the page, if necessary */
|
||||
if (r->may_fault && (IS_ERR(r->folio) || !folio_test_uptodate(r->folio))) {
|
||||
filemap_invalidate_lock_shared(r->file->f_mapping);
|
||||
r->folio = read_cache_folio(r->file->f_mapping, file_off >> PAGE_SHIFT,
|
||||
NULL, r->file);
|
||||
filemap_invalidate_unlock_shared(r->file->f_mapping);
|
||||
}
|
||||
|
||||
if (IS_ERR(r->folio) || !folio_test_uptodate(r->folio)) {
|
||||
if (!IS_ERR(r->folio))
|
||||
folio_put(r->folio);
|
||||
@@ -116,6 +106,24 @@ static const void *freader_fetch(struct freader *r, loff_t file_off, size_t sz)
|
||||
return r->data + file_off;
|
||||
}
|
||||
|
||||
/* reject secretmem folios created with memfd_secret() */
|
||||
if (secretmem_mapping(r->file->f_mapping)) {
|
||||
r->err = -EFAULT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* use __kernel_read() for sleepable context */
|
||||
if (r->may_fault) {
|
||||
ssize_t ret;
|
||||
|
||||
ret = __kernel_read(r->file, r->buf, sz, &file_off);
|
||||
if (ret != sz) {
|
||||
r->err = (ret < 0) ? ret : -EIO;
|
||||
return NULL;
|
||||
}
|
||||
return r->buf;
|
||||
}
|
||||
|
||||
/* fetch or reuse folio for given file offset */
|
||||
r->err = freader_get_folio(r, file_off);
|
||||
if (r->err)
|
||||
|
||||
Reference in New Issue
Block a user