From nobody Sat Feb 7 20:38:37 2026 Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA9C62D8DB0 for ; Thu, 18 Dec 2025 20:56:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766091371; cv=none; b=axFgMOjbslb3ePBmE6tZJDJuKmeKDc4CnMycb7K+trjM/OP6EfBMk5WmJn5GPtsK6kPAsK2Z9xxVXAwXpIUqa0d33z11u6KhQsiLC0pKrIaIq0wefvORhxcdIym+7slNP2XeyiuncIq1ZbI69RfNEo2mCkKxH54N398Sa1UEspo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766091371; c=relaxed/simple; bh=c6pCC0uNJAWdd4fao39X0vYPTeUC9jxy7Iq5vliz+E4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=FxqJPPeHIoTQSmJlx5DFHxc9NFeLKK4lYZgCg4LXLEqjuIo6ODRs9LAoa4B157ZIxBpMcZnnll8zrIqkvR1XSsvZs1wF/+uhBOki2ATU+niygy3KL4U7oY5nSSm/l1UJIaZNQRq7ft4vJwUVMy0aVDuPeyeplcd/2x0FHLF7U+8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=J66Awytj; arc=none smtp.client-ip=95.215.58.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="J66Awytj" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1766091365; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=C7WJGFzPgQgbOew4Nik7yqwK94tl6F+VcxmeN5CTI3c=; b=J66Awytj8ygIwxw+zjd2Kmu4idD3ts6dRYW5m49ISTg/x8/eNiIojqqsx++kq2/NFN31aV gNPB7Yore+WyDHhO4VdU/Qf39r3vGjshg2M6t4VmpUw/OorBr9Ts+xAl73gRYKZ9pJMOmY +v2WbzeYvGdxJV/tSfYchwRoKuZniuw= From: Shakeel Butt To: Andrew Morton , Matthew Wilcox , Andrii Nakryiko Cc: Shaurya Rane , "Darrick J . Wong" , Christoph Hellwig , Alexei Starovoitov , Daniel Borkmann , Meta kernel team , bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, syzbot+09b7d050e4806540153d@syzkaller.appspotmail.com, Christoph Hellwig Subject: [PATCH bpf v2] lib/buildid: use __kernel_read() for sleepable context Date: Thu, 18 Dec 2025 12:55:05 -0800 Message-ID: <20251218205505.2415840-1-shakeel.butt@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" 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. Reported-by: syzbot+09b7d050e4806540153d@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3D09b7d050e4806540153d Fixes: ad41251c290d ("lib/buildid: implement sleepable build_id_parse() API= ") Reviewed-by: Christoph Hellwig Signed-off-by: Shakeel Butt --- Changes since v1: - Fix handling of buf in freader_fetch_sync as pointed out by Andrii. lib/buildid.c | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/lib/buildid.c b/lib/buildid.c index aaf61dfc0919..93b3a06e7f7a 100644 --- a/lib/buildid.c +++ b/lib/buildid.c @@ -5,6 +5,7 @@ #include #include #include +#include #include =20 #define BUILD_ID 3 @@ -37,6 +38,29 @@ static void freader_put_folio(struct freader *r) r->folio =3D NULL; } =20 +/* + * Data is read directly into r->buf. Returns pointer to the buffer + * on success, NULL on failure with r->err set. + */ +static const void *freader_fetch_sync(struct freader *r, loff_t file_off, = size_t sz) +{ + ssize_t ret; + loff_t pos =3D file_off; + char *buf =3D r->buf; + + do { + ret =3D __kernel_read(r->file, buf, sz, &pos); + if (ret <=3D 0) { + r->err =3D ret ?: -EIO; + return NULL; + } + buf +=3D ret; + sz -=3D ret; + } while (sz > 0); + + return r->buf; +} + static int freader_get_folio(struct freader *r, loff_t file_off) { /* check if we can just reuse current folio */ @@ -46,20 +70,9 @@ static int freader_get_folio(struct freader *r, loff_t f= ile_off) =20 freader_put_folio(r); =20 - /* 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 =3D filemap_get_folio(r->file->f_mapping, file_off >> PAGE_SHIFT= ); =20 - /* 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 =3D 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); @@ -97,6 +110,16 @@ const void *freader_fetch(struct freader *r, loff_t fil= e_off, size_t sz) return r->data + file_off; } =20 + /* reject secretmem folios created with memfd_secret() */ + if (secretmem_mapping(r->file->f_mapping)) { + r->err =3D -EFAULT; + return NULL; + } + + /* use __kernel_read() for sleepable context */ + if (r->may_fault) + return freader_fetch_sync(r, file_off, sz); + /* fetch or reuse folio for given file offset */ r->err =3D freader_get_folio(r, file_off); if (r->err) --=20 2.47.3