From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 F1C4825B2F4; Tue, 14 Apr 2026 13:43:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776174237; cv=none; b=Ra3RXL+1JkVc7V2G51P/tAV7XYf+cC6y5tEjRwJeOuJjcNPNxNVPG4M7+gTiCZjrcYZ3OTST2szHZtRXPc6Gh1imuA17GO5Pb59gSNKyYqJzascUFNeSuJLI+IfulFidNTDgSchv6PgkQOpYdIkrOJS9or64h+IChhMuI7askvc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776174237; c=relaxed/simple; bh=7Qsjc8sieTy2NunPo1IUnobN9kKlNcjdypUZQ9CE4Zc=; h=Mime-Version:Content-Type:Date:Message-Id:Subject:Cc:From:To: References:In-Reply-To; b=g/GdwK/+9o4RfTLE6v/OasI8T6bqinevbmT59eIF5AYkRSEur9ON6lEi42Axw3z09s5c6D10psYUEOUnpknwrWaXAEHNo9U6rYOKYphsPClUyLs2ET8UV9VrW6zDgGSEeQhgkFkkR/fwG1YGoglia2FV0uxnvihcX9agGxOx8So= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=S6AAfSv+; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="S6AAfSv+" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 1406BC5AAAC; Tue, 14 Apr 2026 13:44:31 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id E416660410; Tue, 14 Apr 2026 13:43:53 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 450DD10450118; Tue, 14 Apr 2026 15:43:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1776174232; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=fBYaHCpG8hC1NEAoLKhT2eDDnp5ePCFis5i2nukgCY4=; b=S6AAfSv+oUeOvIrxD+z5bbdfpbvEOB21uXEtXvB4AqMh4FY8aCuyB3wHwx9r7WuVdHJYL+ rD0/08M7IBbmkTkrkT4y4rKcwWyqFckHbY0d9PtwNrkx7DaSk7KT0vztBafKaTOmUOws5w qAGaNH/SCsFaeSpXq+U1fXnRnSb6RTAFiP4wAme1fA2E/ecJefwxeRaUPgj3ZmXhRt7wxY aas0aDmqQnMSQ8xEcyHooL1//5S5S9RSul/ZsJlUWSIBozq2b3PI6l6xl3ldUHUduj47SE koioV9P/g0ItanZHdEow/RtOOTONKeljDR3QB5PLNB90x26lfEpu4eQqk7yUEg== 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 Content-Type: text/plain; charset=UTF-8 Date: Tue, 14 Apr 2026 15:43:42 +0200 Message-Id: Subject: Re: [PATCH RFC bpf-next 8/8] selftests/bpf: add tests to validate KASAN on JIT programs Cc: "Alexei Starovoitov" , "Daniel Borkmann" , "Andrii Nakryiko" , "Martin KaFai Lau" , "Eduard Zingerman" , "Kumar Kartikeya Dwivedi" , "Song Liu" , "Yonghong Song" , "Jiri Olsa" , "John Fastabend" , "David S. Miller" , "David Ahern" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , , "H. Peter Anvin" , "Shuah Khan" , "Maxime Coquelin" , "Alexandre Torgue" , "Andrey Ryabinin" , "Alexander Potapenko" , "Dmitry Vyukov" , "Vincenzo Frascino" , "Andrew Morton" , , "Bastien Curutchet" , "Thomas Petazzoni" , "Xu Kuohai" , , , , , , , , From: =?utf-8?q?Alexis_Lothor=C3=A9?= To: "Andrey Konovalov" , =?utf-8?b?QWxleGlzIExvdGhvcsOpIChlQlBGIEZvdW5kYXRpb24p?= X-Mailer: aerc 0.21.0-0-g5549850facc2 References: <20260413-kasan-v1-0-1a5831230821@bootlin.com> <20260413-kasan-v1-8-1a5831230821@bootlin.com> In-Reply-To: X-Last-TLS-Session-Version: TLSv1.3 On Tue Apr 14, 2026 at 12:20 AM CEST, Andrey Konovalov wrote: > On Mon, Apr 13, 2026 at 8:29=E2=80=AFPM Alexis Lothor=C3=A9 (eBPF Foundat= ion) > wrote: >> >> Add a basic KASAN test runner that loads and test-run programs that can >> trigger memory management bugs. The test captures kernel logs and ensure >> that the expected KASAN splat is emitted by searching for the >> corresponding first lines in the report. >> >> This version implements two faulty programs triggering either a >> user-after-free, or an out-of-bounds memory usage. The bugs are >> triggered thanks to some dedicated kfuncs in bpf_testmod.c, but two >> different techniques are used, as some cases can be quite hard to >> trigger in a pure "black box" approach: >> - for reads, we can make the used kfuncs return some faulty pointers >> that ebpf programs will manipulate, they will generate legitimate >> kasan reports as a consequence >> - applying the same trick for faulty writes is harder, as ebpf programs >> can't write kernel data freely. So ebpf programs can call another >> specific testing kfunc that will alter the shadow memory matching the >> passed memory (eg: a map). When the program will try to write to the >> corresponding memory, it will trigger a report as well. >> >> Signed-off-by: Alexis Lothor=C3=A9 (eBPF Foundation) >> --- >> The way of bringing kasan_poison into bpf_testmod is definitely not >> ideal. But I would like to validate the testing approach (triggering >> real faulty accesses, which is hard on some cases, VS manually poisoning >> BPF-manipulated memory) before eventually making clean bridges between >> KASAN APIs and bpf_testmod.c, if the latter approach is the valid one. > > Would it make sense to put these tests into KASAN KUnit tests in > mm/kasan/kasan_test_c.c? I assume there is a kernel API to JIT BPF > programs from the kernel itself? Possibly indeed, but I think one important use case will be the possibility to run those tests in BPF CI ([1]), and this depends on those tests being integrated in the test_progs framework (tools/testing/selftests/bpf) [1] https://github.com/kernel-patches/bpf/pulls > There, you can just call kasan_poison(), some tests already do this. > And you can also extend the KASAN KUnit test framework to find out > whether the bad access is a read or write, if you want to check this. Alexis --=20 Alexis Lothor=C3=A9, Bootlin Embedded Linux and Kernel engineering https://bootlin.com