From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.195.7 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796036627; b=JkcWK7e1V49bgJoJrZxwel1JD/inJRQ/KoBp6k41KuVww3lgZobS0/hJSIhF8hFr/VsJ SPJ4DO0myPS/3qyzMhLQT+n5lU69hKIqVIEkVdyKgnPVfw09GIrY55QD8/KjD/TfaPUT7 TQWdzcn9bcS0aPixukcSxc7/gxotCtJ5EvD4DwXdzzz3Qkz0vkASKYmsaDnqA3Yyc5Ut4 3Q0suTW0qoKEUZFnB6kS7zLxoD8LNLhHpuHyqrpQ6MyMBp8nwwKKel5xhKYrZDesshyj9 jwbh1N5+34ig0E5TNtrT8c81w4lK1AZrBMl8D8UQX91Osu2gRD+V+/k7GXR7C9QZLaQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796036627; h=DMARC-Filter:DKIM-Signature:Received:Received:Date:From:To:Cc: Subject:Message-ID:References:Content-Type:Content-Disposition: In-Reply-To:X-ClientProxiedBy:MIME-Version:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=OsfFYfMA5bg6WzdXv7o4JtnROQAq5fBopvD9YhVKEuM=; b=gKkXZkRh6hpYltNrfR7f9r1X7WvP4jxDolJJrcBZCCZ3Wa7h73CrGzbI2UJwIDR8lhhJ RefdqhY+DN0dQOh2ht4tSppHAYgg9uwyP4/o1gzUGhRbQXQi8JzOtco9DHn2GzmibOvbo 8GL99ky8sMt0fEWQv+Y02eW/5Atu73/GPookKAzTvxB5yMYWDQupUpzi3udy8vBJYb7jG FvlTMEJMNDAaUNqDneMCletq03NAsDSYxYQ833AAN2PMh4bAETr0IrLUPDwUR0JjPC50b QiT2eFIoi4UlEmIGgFu2obhP316S2fZxCnwGza65lZSu1bwO8FcJ4xVYjVp20JnOymg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=HadXJdDl; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.195.7 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012007.outbound.protection.outlook.com [40.93.195.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29A92606A32A for ; Mon, 30 Nov 2026 11:03:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 29A92606A32A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=HadXJdDl ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cLZtDKN2jKjhKd95d6tLcncV29iZ2LIoMMivSQ7ic3yHdFCfKQvQYO+3AbwwjpTxgQp6gjjrg7fxuZsf3iGNWGlhbnlUbmyTt1IJ21A8vkINx3YLBd8XWLbHaRdviKH35Lqp4ViJ3gZaPzKYyfVOMobnLvbQdymAWtrGROCH+02ZAE1sRd23rUl42SrdlNBCy+AHpfe7+W3v/4+bbtLYpr7KkN29FdOg0psCj+7O3FxeY66vAOnaWc68H3vOycBulLA2xg29zbagCtilDx9TE3Ss5/rvwVm52y63OZnSs162HFlCkZhrWxkwUBj87lqXmfy62Gk0pWNZDo3iw4ctWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OsfFYfMA5bg6WzdXv7o4JtnROQAq5fBopvD9YhVKEuM=; b=QJTpK5Ox+IlobIJhHxCQTaiEhPFkygWncMOpx8Rz7p0fn7fKhC97HNiiPrGgjR9wbKELOGVvmJOimV3qP2sxPer/jK3U5MjeU7+Alm6oTjAfXQQqtjDjJz6ubBekP/VAFd28DrsJ/2nOrs5hewKez8L2Ulf+qG3vzMq1y+ts7ICb+jzFjjzlWB1obwo/pu1ZVQwaOFbZ9WCW7Z1plUV98nO8yxfrk/0hv6beGRwotrlIq14i/mnUxZ7t+TKjzzx1Om8XTOS5YmoBMlXsC3WMC6+vOOZbTcRd2gyloGZTjMPCQ+Kl/xjVn/lJiO0bdpKZNI1UKpyrTEPMP3JShZfa/g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OsfFYfMA5bg6WzdXv7o4JtnROQAq5fBopvD9YhVKEuM=; b=HadXJdDlMUTMRTeDaZrnWuc/rh9+I7E5BEmmn0lUstMjrG0tT8+rjnxuiz3Rkex2zMztRS6hgCMED/OE/xZgNfxVas0BptrusT7qwUXyu1FX2szGmHpYTsGBRv5O9X1T61NakNtyo3Z7kGefQ7OGiEIcwIRkiOvvnl3UnsZEAegm0H8Wb3GjEjTbvVE/IIjkRQWoh2/CcKO/j0wLUdIw+Y9AOcCd6LqHzahIvB3NHwBg9+KxnwkYEb5koGaANScHtNadtTAJc5B1HtagMCVWUnUqP8uMc9doCm1GKvjXFtDujDmV/usLHYeDlagwckMrtTBOVP9psOxz5T0xrtwgIw== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BN9PR12MB5179.namprd12.prod.outlook.com (2603:10b6:408:11c::18) by PH7PR12MB6419.namprd12.prod.outlook.com (2603:10b6:510:1fd::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.12; Mon, 30 Nov 2026 11:03:43 +0000 Received: from BN9PR12MB5179.namprd12.prod.outlook.com ([fe80::cf08:f59b:d016:c95f]) by BN9PR12MB5179.namprd12.prod.outlook.com ([fe80::cf08:f59b:d016:c95f%4]) with mapi id 15.21.0662.012; Mon, 30 Nov 2026 11:03:43 +0000 Date: Mon, 30 Nov 2026 12:03:29 +0100 From: Andrea Righi To: Masoud Aghasi Cc: Tejun Heo , David Vernet , Changwoo Min , sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH sched_ext/for-7.4-fixes] sched_ext: Fix unbounded format string reads in the bstr kfuncs Message-ID: References: <20261130075303.1261456-1-arighi@nvidia.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: MI2PEPF000016AC.ITAP293.PROD.OUTLOOK.COM (2603:10a6:298:1::4e7) To CH0PR12MB5169.namprd12.prod.outlook.com (2603:10b6:610:b8::8) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN9PR12MB5179:EE_|PH7PR12MB6419:EE_ X-MS-Office365-Filtering-Correlation-Id: 998de4b0-41e3-4c37-f147-08df4ed198f5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|23010399003|10067099003|56012099006|11063799006|261021121427099003|261021123027099003|261026121527099003|261026140227099003|261022113327099003|261022115727099003|261022105027099003|261022075727099003|261009223027099003|261028144727099003|261102123227099003|22082099003|18002099003|4143699003|6133799003|3023799007; X-Microsoft-Antispam-Message-Info: oEyvBUUZfg2wnzT2XJqMf/Kt3+oH56MHA6cqEz5pxe8qnyC0H2FvOabstsbMjbq63yEtG7umsgBNgQFZLHYtLXNa1wb6f56/EDOrlF1rWwSdRiLdo1RIyLmAD1eGJV7jG2WXMaPoFm8mu8m3E2TjBvmosATY3Zzk+7QoKNg4uxZWpCI8rwH/VFl8+3vYIvTTTxl7IGLygloJO9ZIsGcGA6BylHUCyyJo+yKkIiLfaFQaBkPz9GALm7HySAdkGVtapWZOZI0dLjV98uFnAeZlcAwP1+tV/OrXRD/DfubW1xXYtmvZrdFfH7iWPqJvtQn2kVBKKAIxD7a6ZxQftTdNIi/VBwvLzWBzSZlI5Zz/uioAKg1zeMp8U4eBDzw+a4F1LCXR4yd+jLXSbv8a/PpjmnLQTRkng2grAYs53grfHxIA7CQKVVKSXxMYXqUo7i4v/dlK7naNleWE3J+5HSeKPHDPzsDCfL/IeN38D3XBgINJtLXirynEaKq+VNT4LlgR0xmNF9Djht+98RMVJZVAsbrCMOzmmbOHFbC63weaAXTeP5rUr0/mushYWons/ASKFkzyx7xFDZqFqLH4IFw+84HRfQbXy5QbqTf8Yl26111BLqTuiJB+5Js2vmBKOpc5hEtAN0Cef1Lak9spuhQJjPbzBEJTvXn3ONlP+kIOlEQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN9PR12MB5179.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(23010399003)(10067099003)(56012099006)(11063799006)(261021121427099003)(261021123027099003)(261026121527099003)(261026140227099003)(261022113327099003)(261022115727099003)(261022105027099003)(261022075727099003)(261009223027099003)(261028144727099003)(261102123227099003)(22082099003)(18002099003)(4143699003)(6133799003)(3023799007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?UxLHHJOwlEjDZfu3vFjM87vo32FbzlHDGEGEnVD29j2i2Wq++NU4LJiDq88z?= =?us-ascii?Q?PEt26hPE1ELEG21kAAoNPI4B2qC79b3II3JyBuk2FxwiJiKFU5Jo4QaXtS/y?= =?us-ascii?Q?QFoF7ImQdsImIzL7EmH567EMxnyvqVpL6lIvyHb+XV8seXVJ4hAyttyj4XVB?= =?us-ascii?Q?OAsDnobobgmRHxSJEdEmXJb5p6Vy7iR2VbfhM/ddMP3NtJ0sJl3d9TgWoHrL?= =?us-ascii?Q?4mflEwpaOUqFrFc4UU8MerHUlR3r7rJhLgfemVMcM5Hhb9d9dKCnrRU1cbXq?= =?us-ascii?Q?Mh9ADHI99ErmC4z4w4QXNqvU9bPCDN40nXdtmh9wftu4dPtchgOZR3UptfWh?= =?us-ascii?Q?0Q0Wds28sw+unJPxKNTN1pLd3XBw4UlRHR0JnS25ykMno85m0pNn8zR047UI?= =?us-ascii?Q?CwhcJ82OxYCP9KuVM5rjTrJaCW6ap0xHymmkfh73Xy1ctq9QP4NQnoQDa5j4?= =?us-ascii?Q?c8QCRmt4esTUstQy5XEQbxAyAnKZR+m2ptrntwlvrSEMAMl7tYyNimlHnxlp?= =?us-ascii?Q?G+zqJYOWc7WmzqezJN5elD3FAOv4oUvplMJAMJKBWVTaVHBpszSkI3IGfeUN?= =?us-ascii?Q?Vj1xOGMV31LNKXJr/RK/O8aqKb532I2CP3p+nWmLLXw2DYc9y0WVHySATEfk?= =?us-ascii?Q?VpZOp7SybCuWEw1ajrmWuBRvyhRoaDmp8XsIse3YMUNAtuQS5wZVkAv73oZ/?= =?us-ascii?Q?0OKiTt4Ty1k1190WZDGEOVocho5X1UZPJmnSKtSC2Sm1QRty6WmAiaF4/Lod?= =?us-ascii?Q?QgNvq0Qa6Q5V8XIDdb7i+Yo/iK0wlGiucgYLKVH+asjsR82cmhDoY9gK4TvR?= =?us-ascii?Q?PE9oK8cWpjhGlpg6eSkUCqaUJ3ncIn3EfRMVHAbTpYaYeKXHFNmHdK+Ougr9?= =?us-ascii?Q?xBOeLRnrIAevigEgYfbQbdNxYP9/UiCJrHrIB/UohjhMwbr8UltGpKv9vu9r?= =?us-ascii?Q?AkPM1YH/VOGKa7sWNtYtpLK2ii78XjRvaeFh3OOn7Ytqiyo/KwP8EMIyYVXz?= =?us-ascii?Q?0gNRev38/e53lbHY6mxMHaV/t2SWXu73jxXLfwbgo42ubkbmlXJ5yr1HSfDW?= =?us-ascii?Q?FSYOKRYyz/oB11KyLABU8OX1pjUorbaQgxHsWQA9XYV2rwTfoLdEcCSplLw7?= =?us-ascii?Q?KiG4SZMomDIPU37cdyY6YspuASlt0FFBfGORsOyJQsXtl1xlQpzDbUnMjj1f?= =?us-ascii?Q?5hFD6vKNEvR1e4TZnL4xM/O/xWH3NaM9SIwmuRYzego2WkUntbrYdVKIkEag?= =?us-ascii?Q?fDg5+y+QHTTqLsBJSUJFxhRRV3oNOvm/n+GsB9Th5yHICUTc6dvSMeABB+Og?= =?us-ascii?Q?FCjGUGpDjD5ToZZnPgkQxF2A4wxc06D7tKLz+/FRflxNZhVHoKeYa9Np2XeC?= =?us-ascii?Q?eJKBJRvfUzhdBIcdXzyXoic9dlMUP0hVBKbHBpFMAvc9SO0b+yanLaDlpTXZ?= =?us-ascii?Q?Ep/IjAmvCe+PZXFUhuReN6an3NMpbIN9I07k9VqytT0bMjw3O4qi2BfbbsBU?= =?us-ascii?Q?u7w8FU/xRK1finB078fXv/wgBb3vqh0OyZP/sJoJgjm7GAWWSct9vi4/ixwV?= =?us-ascii?Q?doloVmBZ/m1HLBjGT/dCfEbFvPMdhOW96WUNTtnqGRa2nMBw3S3MtfN35NF7?= =?us-ascii?Q?L1pEqFFswRpPI6RCqI7P4LMq9q9/LPHRpEH1Ecqp1eMJkBEFWfTzvL0UFOx5?= =?us-ascii?Q?UiRsBFiqxBCzEAK4aaOBGJiU9xsN4AEYxjr7zzN2bL1PBH9H?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 998de4b0-41e3-4c37-f147-08df4ed198f5 X-MS-Exchange-CrossTenant-AuthSource: CH0PR12MB5169.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2026 11:03:43.8520 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dtahQjuIFpqwetlsMAuhsTUJBAexkB0vJl602DE/mHQQqG0RZfcj/9SMghlllB0Ep8Ov2m8/7jMLS6ea/VHbYQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6419 Hi Masoud, On Mon, Nov 30, 2026 at 10:49:04AM +0000, Masoud Aghasi wrote: > Hi Andrea, > > On 30/11/2026 07:53, Andrea Righi wrote: > > The format string arguments of the sched_ext bstr kfuncs > > (scx_bpf_exit_bstr(), scx_bpf_error_bstr(), scx_bpf_dump_bstr() and > > scx_bpf_sub_kill_bstr()) are passed to bpf_bprintf_prepare() with a > > UINT_MAX length. The verifier only checks that the pointer is readable > > for a single byte, so an unterminated format makes strnchr() scan past > > the end of the BPF object, possibly into unmapped memory. If the scan > > covers more than INT_MAX bytes before finding a NUL, it can also > > overflow the int index of the parsing loop. > > > > Moreover, the format usually lives in a writable .data map, so it can be > > modified by the BPF program between bpf_bprintf_prepare() and > > bstr_printf(), making the latter interpret arguments that have not been > > validated and prepared. > > > > Fix this by taking a snapshot of the format into a private kernel buffer > > using a bounded, fault-safe read and using only the snapshot for both > > preparation and formatting. Formats of SCX_BSTR_FMT_LEN (1024) bytes or > > more, including the NUL, are rejected with -E2BIG, which doesn't affect > > any realistic format, as messages are already limited to > > SCX_EXIT_MSG_LEN. > > > > The snapshot is too large for the stack (these kfuncs can run in NMI), > > so store it next to the existing output buffers, which already have a > > single user at any time: scx_exit_info (per scheduler, written only by > > the winner of scx_claim_exit()) for the exit path, and scx_bstr_buf > > (serialized by scx_dump_lock) for the dump path. > > > > Note that the bounded read may still access memory beyond the BPF object > > up to SCX_BSTR_FMT_LEN bytes. This is not a concern, since loading a > > struct_ops program requires CAP_PERFMON, which already allows reading > > arbitrary kernel memory via bpf_probe_read_kernel_str(). > > > > The kfunc prototypes and the BPF-side wrappers are unchanged, so > > existing BPF schedulers keep working on fixed kernels and newly built > > ones keep working on older kernels. > > > > Fixes: f0e1a0643a59 ("sched_ext: Implement BPF extensible scheduler class") > > Cc: stable@vger.kernel.org # v6.12+ > > Reported-by: Masoud Aghasi > > Link: https://lore.kernel.org/r/20261130054957.570822-1-maghasi@disroot.org > > Signed-off-by: Andrea Righi > > --- > > kernel/sched/ext/ext.c | 50 ++++++++++++++++++++++++++----------- > > kernel/sched/ext/internal.h | 4 +++ > > kernel/sched/ext/types.h | 1 + > > 3 files changed, 41 insertions(+), 14 deletions(-) > > > > diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c > > index a4a93ed97f7b6..e06bd464dbd28 100644 > > --- a/kernel/sched/ext/ext.c > > +++ b/kernel/sched/ext/ext.c > > @@ -7389,6 +7389,7 @@ void scx_bypass(struct scx_sched *sch, bool bypass) > > static void free_exit_info(struct scx_exit_info *ei) > > { > > kvfree(ei->dump); > > + kfree(ei->fmt); > > kfree(ei->msg); > > kfree(ei->bt); > > kfree(ei); > > @@ -7405,9 +7406,10 @@ static struct scx_exit_info *alloc_exit_info(size_t exit_dump_len) > > ei->exit_cpu = -1; > > ei->bt = kzalloc_objs(ei->bt[0], SCX_EXIT_BT_LEN); > > ei->msg = kzalloc(SCX_EXIT_MSG_LEN, GFP_KERNEL); > > + ei->fmt = kzalloc(SCX_BSTR_FMT_LEN, GFP_KERNEL); > > ei->dump = kvzalloc(exit_dump_len, GFP_KERNEL); > > > > - if (!ei->bt || !ei->msg || !ei->dump) { > > + if (!ei->bt || !ei->msg || !ei->fmt || !ei->dump) { > > free_exit_info(ei); > > return NULL; > > } > > @@ -11355,14 +11357,35 @@ __bpf_kfunc void scx_bpf_reenqueue_local___v2(const struct bpf_prog_aux *aux) > > > > __bpf_kfunc_end_defs(); > > > > -__printf(5, 0) > > -static s32 __bstr_format(struct scx_sched *sch, u64 *data_buf, char *line_buf, > > - size_t line_size, char *fmt, unsigned long long *data, > > - u32 data__sz) > > +/* > > + * @fmt may be unterminated and writable by BPF, use only the bounded copy in > > + * @dst to prepare and format the string. > > + */ > > +static s32 scx_snapshot_fmt(char *dst, size_t size, const char *fmt) > > +{ > > + long ret = strncpy_from_kernel_nofault(dst, fmt, size); > > + > > + if (ret < 0) > > + return ret; > > + /* @size means truncated or NUL in the last byte, reject both */ > > + if (ret == size) > > + return -E2BIG; > > + return 0; > > +} > > + > > Thanks for the fix. I see 2 potential limitations with this approach: > 1- as you mentioned, the bounded nofault read does not establish > the actual readable object boundary. Right, the kernel doesn't know where the object containing the format ends, so an unterminated format can make the copy read past it. However, the formats generated by scx_bpf_exit/error/dump() are static variables in .data, which libbpf creates as a BPF_F_MMAPABLE array map. Such maps are backed by a dedicated, zeroed, page-aligned vmalloc area, followed by a vmalloc guard page. So, if the format is not terminated, the copy either hits the zero padding after the variables (finding a NUL), or the guard page, which strncpy_from_kernel_nofault() handles by returning -EFAULT. In both cases it never reads outside the map. Only a format passed explicitly from other memory could read into a neighbouring object, but the read is still bounded to SCX_BSTR_FMT_LEN, can't fault, and the program has CAP_PERFMON, which already allows reading arbitrary kernel memory via bpf_probe_read_kernel_str(). > > 2- couldn't the source be modified concurrently while the snapshot is > being copied? (e.g. through updating the writable array value > from userspace) Yes, the snapshot isn't atomic, but it doesn't need to be: what matters is that bpf_bprintf_prepare() and bstr_printf() see exactly the same bytes. Once copied, the snapshot is private and always NUL-terminated, so a concurrent writer can only produce a garbled message (or one rejected by bpf_bprintf_prepare()), but never a string that is formatted without being validated first. The data arguments already behave the same way. And the issue pointed out by Sashiko is also valid: https://lore.kernel.org/r/sashiko-outbox-240675@kernel.org However, calling scx_bpf_dump() from a tracing program doesn't really make sense IMHO: it's only meaningful from ops.dump() and friends, and called from any other CPU it just aborts the scheduler. I'll send a separate follow-up patch that adds scx_bpf_dump_bstr() to scx_kfunc_ids_no_tracing, rejecting such programs at load time. Thanks for reviewing this! -Andrea