Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp1312249rwl; Thu, 5 Jan 2023 11:38:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXuirrglwwxoAMoNprj7kRR/0YP6HmvMzVhSw8a6IxAGVkm/MAZuiKJC1/UXgievEIJ7NYaT X-Received: by 2002:a05:6402:2932:b0:47e:bdb8:9133 with SMTP id ee50-20020a056402293200b0047ebdb89133mr51663494edb.38.1672947538493; Thu, 05 Jan 2023 11:38:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672947538; cv=none; d=google.com; s=arc-20160816; b=qTMp9YnOA78J3VARXy4i1PMLKcTSSrNgl1OUEBs8b3TM+IpLYigv5Ng6cDV3lj2Weq IOUF/Ys0mi/4XifB+CPlAuQXo4Px7x/mJ8brW2RUqy90kDfkAOSTYZmwdIYWRaaLiEC8 HHNsw96Jr4Lgn6q4Z4b/o0rYVBAhs3EUXfubWiKBwGhlRkF92xXzOipzrJxufxef4r5W esbJyuUgZorAZ58cNCG5pn+H7OgU9C1iFPWLz2ax6U6xX+pgyJtYFwlhErh1VhJ1CrPQ ZhiUXONdoFaOYbcjR8ybYM6kI2hrhL2wZy/pNzjEc2p6tPL6FNQ+3Pw0htrn8T/WaeuR ri7Q== 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 Return-Path: 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.38.45; Thu, 05 Jan 2023 11:38:58 -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 + 55 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 ); 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 ; Thu, 5 Jan 2023 11:26:51 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id w203so9451375pfc.12 for ; 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 To: Alexei Starovoitov Cc: Kees Cook , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , "Gustavo A. R. Silva" , 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 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 Cc: Daniel Borkmann Cc: John Fastabend Cc: Andrii Nakryiko Cc: Martin KaFai Lau Cc: Song Liu Cc: Yonghong Song Cc: KP Singh Cc: Stanislav Fomichev Cc: Hao Luo Cc: Jiri Olsa Cc: "Gustavo A. R. Silva" Cc: bpf@vger.kernel.org Signed-off-by: Kees Cook --- 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