From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 386471C57B1; Tue, 15 Oct 2024 12:07:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728994060; cv=none; b=ABYEXi7dayySlUpq7l5prgWIj1rBjWbYOyyuf6lWS4bqXrktqOC/kHJtVmn1oJb3i2RjDepq7Ah0Jihxee5Kmkqc9BOpksEZUVTNdR3+1HCEXMJL/UMYlLkmOycFU05holO4Sp5jA/cmIb3PO23robpN9tYiYkplT8sPl1fWx6w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728994060; c=relaxed/simple; bh=0KfCz7JVCsTIoMva5pDI7GlGdWkWC8E1Kfi9n91MkYk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YApNybXa8Szt0GA70zcglEavEutxc7FhLVBROSTnqr/Z4w7d5UqR+PAgmsgxQxAl1Wq7VJNvdlseLxFHbPDBXuwF2HN7tNjitnSC7rEbBsCvAn3t6HSBaLlxrRBkGPCuAB6DdkCW70L0obvN+UXz1g3owdh4dovVBHW/bdOzYgc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=xu9uw++N; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="xu9uw++N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E3B6C4CEC6; Tue, 15 Oct 2024 12:07:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1728994060; bh=0KfCz7JVCsTIoMva5pDI7GlGdWkWC8E1Kfi9n91MkYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xu9uw++NWnddJehORpxQDfhJXSwgzCM0Zp/rAv2QWiW4/+4OMukelORNZp9CLZeLb K+C/k5StknWrPpLdkf5akjoGJhBHN2SB/DlQ9p0GkgT0hUihf7CpZLQ8r+3ZXlz3qH jNMNVGYfyDalknFpB1KxeCBuoiIokK+ajTGnIqGE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jinke Han , Tao Chen , Andrii Nakryiko , Jiri Olsa , Sasha Levin Subject: [PATCH 5.15 596/691] bpf: Check percpu map value size first Date: Tue, 15 Oct 2024 13:29:04 +0200 Message-ID: <20241015112503.999471862@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241015112440.309539031@linuxfoundation.org> References: <20241015112440.309539031@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tao Chen [ Upstream commit 1d244784be6b01162b732a5a7d637dfc024c3203 ] Percpu map is often used, but the map value size limit often ignored, like issue: https://github.com/iovisor/bcc/issues/2519. Actually, percpu map value size is bound by PCPU_MIN_UNIT_SIZE, so we can check the value size whether it exceeds PCPU_MIN_UNIT_SIZE first, like percpu map of local_storage. Maybe the error message seems clearer compared with "cannot allocate memory". Signed-off-by: Jinke Han Signed-off-by: Tao Chen Signed-off-by: Andrii Nakryiko Acked-by: Jiri Olsa Acked-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20240910144111.1464912-2-chen.dylane@gmail.com Signed-off-by: Sasha Levin --- kernel/bpf/arraymap.c | 3 +++ kernel/bpf/hashtab.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c index c76870bfd8167..2788da290c216 100644 --- a/kernel/bpf/arraymap.c +++ b/kernel/bpf/arraymap.c @@ -74,6 +74,9 @@ int array_map_alloc_check(union bpf_attr *attr) * access the elements. */ return -E2BIG; + /* percpu map value size is bound by PCPU_MIN_UNIT_SIZE */ + if (percpu && round_up(attr->value_size, 8) > PCPU_MIN_UNIT_SIZE) + return -E2BIG; return 0; } diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index f53b4f04b935c..d08fe64e0e453 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c @@ -464,6 +464,9 @@ static int htab_map_alloc_check(union bpf_attr *attr) * kmalloc-able later in htab_map_update_elem() */ return -E2BIG; + /* percpu map value size is bound by PCPU_MIN_UNIT_SIZE */ + if (percpu && round_up(attr->value_size, 8) > PCPU_MIN_UNIT_SIZE) + return -E2BIG; return 0; } -- 2.43.0