From nobody Fri Dec 19 17:23:05 2025 Received: from forward100b.mail.yandex.net (forward100b.mail.yandex.net [178.154.239.147]) (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 BD1B3301492; Thu, 6 Nov 2025 20:59:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762462787; cv=none; b=MyM4OgL7ixWQb7sNY28iykdWDtG+MNJPx8jHjq64Alu8Heu9o4TkBTyMC2zLMXu5f/CLz4uNgzZXoIFigQQrbUXnHZXdVuzMtcK1SU2+GLQ3QaTZxvaDw9fafcipwVS4U/GmI5M5dLlQK8Acc50d061lkQN7/oj6meY19r86hYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762462787; c=relaxed/simple; bh=IC0x0oZUh4X2mLDEyPdhQd0SMBfCZdh7lBBnf0a64+0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=XC9kWsY4HgeWgeDIli0D4QnYylKxFE9bUvraDVrbxIqFhZl4utVhaKpE4oRz8WNdNojL6d7z5SgShWNpDNPIDkLRtERphVpA6+XFIfKbvzSjTZcho31DhwJ40172ipRSAz/PeUiNcDwBqe1FmEw+FyBXITiYJDXzt2r4Qwrs+y4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rosa.ru; spf=pass smtp.mailfrom=rosa.ru; dkim=pass (1024-bit key) header.d=rosa.ru header.i=@rosa.ru header.b=a8gVwRda; arc=none smtp.client-ip=178.154.239.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rosa.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rosa.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=rosa.ru header.i=@rosa.ru header.b="a8gVwRda" Received: from mail-nwsmtp-smtp-production-main-89.sas.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-89.sas.yp-c.yandex.net [IPv6:2a02:6b8:c08:ec27:0:640:5ac1:0]) by forward100b.mail.yandex.net (Yandex) with ESMTPS id 7738D806DA; Thu, 06 Nov 2025 23:59:32 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-89.sas.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id SxtU1pGLB8c0-00FU0989; Thu, 06 Nov 2025 23:59:31 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rosa.ru; s=mail; t=1762462771; bh=I+5fGidXHttPZIAH5EDKfTztWLspei5KA1OZ0w7FGW0=; h=Message-ID:Date:Cc:Subject:To:From; b=a8gVwRdaYw2G7dQAosh0BHR1bg3IcXH6JpVIzYthGWR12rL7v86A2EPtRFm0VkSt0 OQLoKub+R9qK7FmQxVzPwpPdAjIxKTCWlssGbVpVoDflFtnH54kyZCOUD59AlVqvYs ELs0u5fSgC7nFXcroRBVQX5x4Y5sSey3x9SuCnH8= Authentication-Results: mail-nwsmtp-smtp-production-main-89.sas.yp-c.yandex.net; dkim=pass header.i=@rosa.ru From: Alexei Safin To: Alexei Starovoitov Cc: Alexei Safin , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Yafang Shao , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-patches@linuxtesting.org, stable@vger.kernel.org Subject: [PATCH] bpf: hashtab: fix 32-bit overflow in memory usage calculation Date: Thu, 6 Nov 2025 23:58:44 +0300 Message-ID: <20251106205852.45511-1-a.safin@rosa.ru> X-Mailer: git-send-email 2.50.1 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" The intermediate product value_size * num_possible_cpus() is evaluated in 32-bit arithmetic and only then promoted to 64 bits. On systems with large value_size and many possible CPUs this can overflow and lead to an underestimated memory usage. Cast value_size to u64 before multiplying. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 304849a27b34 ("bpf: hashtab memory usage") Cc: stable@vger.kernel.org Signed-off-by: Alexei Safin --- kernel/bpf/hashtab.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index 570e2f723144..7ad6b5137ba1 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c @@ -2269,7 +2269,7 @@ static u64 htab_map_mem_usage(const struct bpf_map *m= ap) usage +=3D htab->elem_size * num_entries; =20 if (percpu) - usage +=3D value_size * num_possible_cpus() * num_entries; + usage +=3D (u64)value_size * num_possible_cpus() * num_entries; else if (!lru) usage +=3D sizeof(struct htab_elem *) * num_possible_cpus(); } else { @@ -2281,7 +2281,7 @@ static u64 htab_map_mem_usage(const struct bpf_map *m= ap) usage +=3D (htab->elem_size + LLIST_NODE_SZ) * num_entries; if (percpu) { usage +=3D (LLIST_NODE_SZ + sizeof(void *)) * num_entries; - usage +=3D value_size * num_possible_cpus() * num_entries; + usage +=3D (u64)value_size * num_possible_cpus() * num_entries; } } return usage; --=20 2.50.1 (Apple Git-155)