From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DCEE343882 for ; Tue, 9 Jun 2026 08:43:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.65 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780994635; cv=none; b=WY/SxrYuNu2jq8mgjL6Zv8K1cViF4JgL411Sbd8kIVsA6ExiGz8Wrr3cPCA1Gv+7UfIfiX2gK96mxVVoWiofkgY8dWuHCvpguqicUlUUdvnizgQcxH6topVk8AVhEoqMEvXeNO3OwR0eHm0WTMxWrZY2SYMoFUdtWE5iIalIwlo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780994635; c=relaxed/simple; bh=4rTCpYdKEey/fxpJBzRiYD23VkjVM1koVws/Fj54klA=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=sFvyhHZXEWldyFoQaexK3htilEueKLoTWnpVGwwq+cmR0RFQxyqHpaZFcVdIyHM1P+QGNL/TpWNzX0cEpNriniRzw45UkPyM/hhysp1EnjwvKa8QaN2rA5nLTFcELOfjeC669AAwUT7GjYPAbTr30vxYMNGH/XxtscJ4gqOV3OI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MPAkhf1u; arc=none smtp.client-ip=209.85.221.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MPAkhf1u" Received: by mail-wr1-f65.google.com with SMTP id ffacd0b85a97d-45eecb8bf67so3946962f8f.2 for ; Tue, 09 Jun 2026 01:43:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780994633; x=1781599433; darn=vger.kernel.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=4rTCpYdKEey/fxpJBzRiYD23VkjVM1koVws/Fj54klA=; b=MPAkhf1uquZqzFn6EULJov+ZxAnSdVdGje6+ibL577WuH8w69cfqy/zmD36dPcNysJ lw7EWhjKnbUo94gp9tGq6tjvv3UWGuFCRiC0e6NN6XLEkVSw6taCWkiiBmhgvi3ki0uH QNu8CUqYp2FmCiPxJmtIcdcEDeCCQtfLaxAHQHHhF4IuHI9u3EVHrhlRZPstaYX0XAKS oiB2fInu+VDd7Ynw4KLaCpdByGW9imd4dKr9DmFbI11wMpfPVs9adFQLzAmN8iBYzZlX JRYM3sIJxIpmtm0Bvs30+q6qLWiHMjLfaGvjhsWkfxjNsJvURrWbBq+Fzk7F2HzkG71q mTTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780994633; x=1781599433; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4rTCpYdKEey/fxpJBzRiYD23VkjVM1koVws/Fj54klA=; b=AjkrW6avy/cDNgw1yo41a+IkPcDXkiGjHKRcKt5j61hXi3OCY/IO09SeaHN4D6FNbN RGDB8/oRhEDu7SVWqChYDXZcLVMrxFlwk4AfdHMgsgCASwLrWq4RfT8ky3YjirqDfbMv jr7Oq+lfwp5T3k3lyqGTMZ9azEaBND/bUokvbmx6TbEXbdd7YuxHu+Y3tXE5yGo4nbEi wkg4LrF5W2n2YM4vMHJ0bgz1DVyWrX646XBfV0Bq1Qzdi5XL61zDD7tzxGXq3mgVIBgY Q9a000i6YehxzP2Fz5tXPT0QQLo+VKYydO7pJt06aTM+qaiRJdJlxFuEz4JIrWu5zyPX ISAg== X-Forwarded-Encrypted: i=1; AFNElJ9ORLgdG2KmrGFMlDBvE+vDhK0kcONiu/aD9Ni8Vz9vQcL/0xnrupcozPW3OA+spRSNVZ6ahuBGkSkyuR0=@vger.kernel.org X-Gm-Message-State: AOJu0YwhR0W4/CmTtU4IIuTMdP6LGB4+J/bZGoza243hdsQEGw3uwrJI D6J36Q2Rn4D0sMwuot9QTD8e8a2t05cjY/AFHJMVTzQXh2UuHhrVlhSt X-Gm-Gg: Acq92OGLdAp7/RHI3UBS0WCTHDv+FlM+0P4CsrotFNhzxTXq4UmDaaY++GIQ3hIo3Vy TRlPAI7xXUKesVh7ZZMmnGMyRc4b2Hf6+YE7bkL4W2j9a4bgztwTU+BXBYtgcGquk2BKimmDlGW zHC1P8//047wcS1XiTStgjowmRy7EIIxE2ZzIzJghqZN0sBVClT507Of+9SEEcPRsE68H//LiWO ZmG2YPtCErmqAAhH4LsF4HTzv8FVGPA3N/EfdV8TtEdbwqvSEB4e+ppKjE1AbX+quryKN2+NzhV 0gxCWP5WCAwNMCKP5fCrUM1XXVsvZ4Ea/BJoyx5UDLc65zuJQZM6sRU21WP8KNX+uCGWcjsdEGc qKCmwvh9iqKmJCZeWPqb/Jft9ecHAeep7U3MbTDV9Qj9DT9UUtO0WhYXkGII5HgGLeB5pSQ3pcF igJAsBZhvHRr5twydd6zapyL5Vr+KXkBqC8IRzwOwopM/S8L5WO9u+NDAkkELQ/FGPTFWKCvtLL OA1/tjowlpAcMsv4kTXgnq0pfBYb+D6OX7tturaKvRT24kB4SFB0YLKLTZnA/dsy/eZF6bBbt/m X-Received: by 2002:adf:e30e:0:b0:460:1233:ecf2 with SMTP id ffacd0b85a97d-46030609798mr22356467f8f.30.1780994632620; Tue, 09 Jun 2026 01:43:52 -0700 (PDT) Received: from localhost (nat-icclus-192-26-29-3.epfl.ch. [192.26.29.3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2dcb13sm60610866f8f.2.2026.06.09.01.43.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2026 01:43:51 -0700 (PDT) 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, 09 Jun 2026 10:43:51 +0200 Message-Id: Cc: , , , , , Subject: Re: [PATCH bpf] bpf: Validate BTF repeated field counts before expansion From: "Kumar Kartikeya Dwivedi" To: "Eduard Zingerman" , "Paul Moses" , , , , , , X-Mailer: aerc 0.21.0 References: <20260605234301.1109063-1-p@1g4.org> <189a79443144cacf4a257f0627586f917d8d18a2.camel@gmail.com> In-Reply-To: <189a79443144cacf4a257f0627586f917d8d18a2.camel@gmail.com> On Mon Jun 8, 2026 at 10:01 PM CEST, Eduard Zingerman wrote: > On Fri, 2026-06-05 at 23:43 +0000, Paul Moses wrote: >> btf_parse_struct_metas() walks user-supplied BTF during BPF_BTF_LOAD, >> and btf_repeat_fields() expands repeatable fields from array elements >> into the fixed BTF_FIELDS_MAX scratch array used by btf_parse_fields(). >> >> The remaining-capacity check performs the expanded field count calculati= on >> in u32. A malformed BTF can wrap that calculation, causing the check to >> pass even when the expanded field count exceeds the scratch array >> capacity. The following memcpy() can then write past the end of the >> array. >> >> Use checked addition and multiplication before copying repeated fields >> and reject impossible counts. >> >> Fixes: 797d73ee232d ("bpf: Check the remaining info_cnt before repeating= btf fields") >> Cc: stable@vger.kernel.org >> Signed-off-by: Paul Moses >> --- > > Regardless of the sibling email I sent, I think that this is a good > defensive practice to use check_{add,mul}_overflow() here. > Having said that, it would be nice to have a selftest in the patch-set. > > Acked-by: Eduard Zingerman > Paul, Please follow up with a selftest reproducer to exercise the bug. > [...]