Message ID | 20230105192646.never.154-kees@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp465005wrt; Thu, 5 Jan 2023 11:37:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXsoCtoJEsfCh8RvM2ne1xqc78sYpDoPwkD70XL9D/wnls4bbm1GoQudMa54cDiywYBNzZaQ X-Received: by 2002:a50:eacc:0:b0:46c:ec6f:43d7 with SMTP id u12-20020a50eacc000000b0046cec6f43d7mr62617961edp.19.1672947477164; Thu, 05 Jan 2023 11:37:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672947477; cv=none; d=google.com; s=arc-20160816; b=vF+fG8qgvsicRmDx7oMflJs8C8Vj7vdJtS1hi8w3ptQ3k1YxYrqKnWKtqk6Okyw4+e yjxmwSENSqvNskYTEaixC3qlYNKxtEftc15PyNmQOCZNaP+M4cuov+9vraYFN94Vmkhf hwfmSAsJJYjIhHqkKDZw9/9ZLz2GrTKdM9ghmhakLJbpMYFtG6ATr0N8y372NWAwjJ0P v5exwds4WPDz/OGsXAh/2BVyFZJsauyOU/tejDU0kncQ2TJYNQ2fMRckR9+rliMI/4Zs mvfER8chajVKsO2uNXSm2VdY8BsGSlEvSuhBWUky/RZyS+1ya8jtfrhk9YEvQ3foUXSg PeGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=2M/SEDI3ZFLLpa6t8CMCD85tOj1o/kREvGLd7NUi0i0=; b=hjtbtAESBtRlI9vpVoliJedGS2QCt8z3vUWUtLqmSba49ytEdevJkzqSnitvoCCsjX PTLx9fvWSaZCSPOMkNeWY3SSDw/sCMmThFrLrfuodVJfU6IFKw9KsG6LUzFVPEWe5wu3 uQ5/Lyt8/fkZmh66SznMD6yu5PgvG1Cqpgv4G1bGJqtI6V+s2al3+IqwTYKi223U7GUj jgheeFeXJ5o9mfv/C0izvW1fqqvBMNrKMDHqig48pm1oKj52i48n8989jcgpp7xCWD1+ y4laksjz3CbAprA0cCevHD0InVFIHhB+Dj7pvm6Yzd2Ar8hYbS91CX4J11vR0WY51QEa OhIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bYiDK6co; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e3-20020a50fb83000000b0046a0331778dsi1502756edq.118.2023.01.05.11.37.33; Thu, 05 Jan 2023 11:37:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bYiDK6co; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235857AbjAETcU (ORCPT <rfc822;tmhikaru@gmail.com> + 99 others); Thu, 5 Jan 2023 14:32:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234830AbjAETbt (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 5 Jan 2023 14:31:49 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52EA5BC15 for <linux-kernel@vger.kernel.org>; Thu, 5 Jan 2023 11:26:51 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id w203so9451375pfc.12 for <linux-kernel@vger.kernel.org>; Thu, 05 Jan 2023 11:26:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=2M/SEDI3ZFLLpa6t8CMCD85tOj1o/kREvGLd7NUi0i0=; b=bYiDK6coyyNfhwS9yGGXA4g3BMzQ6EtUBqat3QdKBC+jcD4l7q4QlmZhqOwOHhADeq dgCWJrtIF1YSaHqo0PjnD+lhyqppr73VpPDLIYY+ucZnsBicoMpc2hDuVHmBHJWa1H0E IBv3xU8jja7IXJ1CZaK2VrzBiCxVdmzHkJlQM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2M/SEDI3ZFLLpa6t8CMCD85tOj1o/kREvGLd7NUi0i0=; b=2NP4xmMajRhpo5E9m3puJi2BY4VjFKK1XfbdPgD0KdH5GJUcUnwtz+yhzFXSMaMnHX pSUYgV02bAg/7Cuqe9FVsorTUeMnnvF0h0dU1LEtHuvuboSvqzCyOIww0vmgWDg3hVtk ec91wbZASOkuUtlE2u6kQWQV/09x/cTHjkgim2xog7dPp0L2u4KwLx2oQXK8zNB5d/d+ QwvoqtE8uBl7KunzDZ31b0wPDjmbPvWQ+1cnqKm+C7ZZtUYddA+ol6IoadfR0cBYa4x/ M0RY2iOsGTx0JxFJJBfs7nb1GVqetAUAcWiUIEY58PLWv8aZVliYp8+BLL6tU4u/3q4b UdYQ== X-Gm-Message-State: AFqh2kqpulpTwgaJuZJsdvU7KYpvpuNmO/kLeaqtKK/cYtHlurYFSwnh j/96vy6ry/otDZgj17qsuFocJg== X-Received: by 2002:a05:6a00:24cd:b0:581:4260:a650 with SMTP id d13-20020a056a0024cd00b005814260a650mr58589947pfv.33.1672946810834; Thu, 05 Jan 2023 11:26:50 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id x3-20020aa79563000000b005818d4284aasm16046250pfq.160.2023.01.05.11.26.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 11:26:50 -0800 (PST) From: Kees Cook <keescook@chromium.org> To: Alexei Starovoitov <ast@kernel.org> Cc: Kees Cook <keescook@chromium.org>, Daniel Borkmann <daniel@iogearbox.net>, John Fastabend <john.fastabend@gmail.com>, Andrii Nakryiko <andrii@kernel.org>, Martin KaFai Lau <martin.lau@linux.dev>, Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>, KP Singh <kpsingh@kernel.org>, Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>, Jiri Olsa <jolsa@kernel.org>, "Gustavo A. R. Silva" <gustavoars@kernel.org>, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] bpf: Replace 0-length arrays with flexible arrays Date: Thu, 5 Jan 2023 11:26:47 -0800 Message-Id: <20230105192646.never.154-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2101; h=from:subject:message-id; bh=V+hDTvfLNktsOza7//a0ww3JjY/DO434Oi3YuneAQho=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBjtyR3frN3HKMkFYai/Tm7ow/5jyykqQkgn4p54zvI 3udqhk6JAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCY7ckdwAKCRCJcvTf3G3AJiVXD/ oDGiZsOyCTBvLW5TFiKe3edkbxbWHr734/G3YbQEr15ayjIYmPo4HRfPl5f4ILDNVy24KjBoUFo9pB coVD7DTnVaFqeQ+kIbE59nyjzZZuUstSyyrFAFaps2VjYlcxhQclBM8ri1GFaIyeeAeR5Qs/IPdlMn dfxzky3v1L3HQQLLG0h26sTRl+pgOhaN4hiihyxZZV8rYS1nM++DZyMjbUQh+7lO525XIOd1p5Mk0j YHEwojOP1BDNZ+/5RgCCPCyPzKhQyOB4glMRpff7BPpi/gX1moSO9xjQOxp0U/nrB/zR267fq8DCVm zeRSUBCdQdpM05UACFsqZJHwiiZerLz5/rgFgiehgoulnCiidE19JcAYOMqBI9mJqx/yTPCWjxpHGr 89uZ9V8XbgjBTViH2Xvt/GHKdKXjfMYgolk3dblHqteV/PQ287MVj0V3uO+WumVw1TY+Fx4TsJfdyS DoNCgswbqTMlBlxy3IySs5RDgp/viDh0jA9TDeolIk/9rYQACGi6HbaoVnmuEF1UWMAaKgZFbLv4gw z4Y0hX5Dp7dw34matjSvTPGwhiVP0io9YetucAqYbuVziv6heiXkyobM4g2alSdqn6rlsKkV0h4SBx H8qunve472K7XsC1zmNiU1mTDwRwXYbu2D3KNs2eAAicfhq9o18tJj/R5Hxg== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754212573669926042?= X-GMAIL-MSGID: =?utf-8?q?1754212573669926042?= |
Series |
bpf: Replace 0-length arrays with flexible arrays
|
|
Commit Message
Kees Cook
Jan. 5, 2023, 7:26 p.m. UTC
Zero-length arrays are deprecated[1]. Replace struct bpf_array's
union of 0-length arrays with flexible arrays. (How are the
sizes of these arrays verified?) Detected with GCC 13, using
-fstrict-flex-arrays=3:
arch/x86/net/bpf_jit_comp.c: In function 'bpf_tail_call_direct_fixup':
arch/x86/net/bpf_jit_comp.c:606:37: warning: array subscript <unknown> is outside array bounds of 'void *[0]' [-Warray-bounds=]
606 | target = array->ptrs[poke->tail_call.key];
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
In file included from include/linux/filter.h:9,
from arch/x86/net/bpf_jit_comp.c:9:
include/linux/bpf.h:1527:23: note: while referencing 'ptrs'
1527 | void *ptrs[0] __aligned(8);
| ^~~~
[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Martin KaFai Lau <martin.lau@linux.dev>
Cc: Song Liu <song@kernel.org>
Cc: Yonghong Song <yhs@fb.com>
Cc: KP Singh <kpsingh@kernel.org>
Cc: Stanislav Fomichev <sdf@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: bpf@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
include/linux/bpf.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Comments
On Thu, Jan 5, 2023 at 11:26 AM Kees Cook <keescook@chromium.org> wrote: > > Zero-length arrays are deprecated[1]. Replace struct bpf_array's > union of 0-length arrays with flexible arrays. (How are the > sizes of these arrays verified?) Detected with GCC 13, using Haven't looked closely, but these arrays should be produced somewhere around kernel/bpf/arraymap.c (fd_array). > -fstrict-flex-arrays=3: > > arch/x86/net/bpf_jit_comp.c: In function 'bpf_tail_call_direct_fixup': > arch/x86/net/bpf_jit_comp.c:606:37: warning: array subscript <unknown> is outside array bounds of 'void *[0]' [-Warray-bounds=] > 606 | target = array->ptrs[poke->tail_call.key]; > | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~ > In file included from include/linux/filter.h:9, > from arch/x86/net/bpf_jit_comp.c:9: > include/linux/bpf.h:1527:23: note: while referencing 'ptrs' > 1527 | void *ptrs[0] __aligned(8); > | ^~~~ > > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays > > Cc: Alexei Starovoitov <ast@kernel.org> > Cc: Daniel Borkmann <daniel@iogearbox.net> > Cc: John Fastabend <john.fastabend@gmail.com> > Cc: Andrii Nakryiko <andrii@kernel.org> > Cc: Martin KaFai Lau <martin.lau@linux.dev> > Cc: Song Liu <song@kernel.org> > Cc: Yonghong Song <yhs@fb.com> > Cc: KP Singh <kpsingh@kernel.org> > Cc: Stanislav Fomichev <sdf@google.com> > Cc: Hao Luo <haoluo@google.com> > Cc: Jiri Olsa <jolsa@kernel.org> > Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org> > Cc: bpf@vger.kernel.org > Signed-off-by: Kees Cook <keescook@chromium.org> Acked-by: Stanislav Fomichev <sdf@google.com> > --- > include/linux/bpf.h | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > index 3de24cfb7a3d..2131000f711e 100644 > --- a/include/linux/bpf.h > +++ b/include/linux/bpf.h > @@ -1523,9 +1523,9 @@ struct bpf_array { > u32 index_mask; > struct bpf_array_aux *aux; > union { > - char value[0] __aligned(8); > - void *ptrs[0] __aligned(8); > - void __percpu *pptrs[0] __aligned(8); > + DECLARE_FLEX_ARRAY(char, value) __aligned(8); > + DECLARE_FLEX_ARRAY(void *, ptrs) __aligned(8); > + DECLARE_FLEX_ARRAY(void __percpu *, pptrs) __aligned(8); > }; > }; > > -- > 2.34.1 >
Hello: This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <daniel@iogearbox.net>: On Thu, 5 Jan 2023 11:26:47 -0800 you wrote: > Zero-length arrays are deprecated[1]. Replace struct bpf_array's > union of 0-length arrays with flexible arrays. (How are the > sizes of these arrays verified?) Detected with GCC 13, using > -fstrict-flex-arrays=3: > > arch/x86/net/bpf_jit_comp.c: In function 'bpf_tail_call_direct_fixup': > arch/x86/net/bpf_jit_comp.c:606:37: warning: array subscript <unknown> is outside array bounds of 'void *[0]' [-Warray-bounds=] > 606 | target = array->ptrs[poke->tail_call.key]; > | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~ > In file included from include/linux/filter.h:9, > from arch/x86/net/bpf_jit_comp.c:9: > include/linux/bpf.h:1527:23: note: while referencing 'ptrs' > 1527 | void *ptrs[0] __aligned(8); > | ^~~~ > > [...] Here is the summary with links: - bpf: Replace 0-length arrays with flexible arrays https://git.kernel.org/bpf/bpf-next/c/129d868ede1e You are awesome, thank you!
diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 3de24cfb7a3d..2131000f711e 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1523,9 +1523,9 @@ struct bpf_array { u32 index_mask; struct bpf_array_aux *aux; union { - char value[0] __aligned(8); - void *ptrs[0] __aligned(8); - void __percpu *pptrs[0] __aligned(8); + DECLARE_FLEX_ARRAY(char, value) __aligned(8); + DECLARE_FLEX_ARRAY(void *, ptrs) __aligned(8); + DECLARE_FLEX_ARRAY(void __percpu *, pptrs) __aligned(8); }; };