Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2266406rdb; Tue, 3 Oct 2023 16:06:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMEb0sB1EVuvSUOHb4I9cY82IAccP56q+gXKLPrLK4TPcB3eFmxwV6+CCGdcucsrhCRBQa X-Received: by 2002:a05:6a00:13a9:b0:68c:3f2:5ff7 with SMTP id t41-20020a056a0013a900b0068c03f25ff7mr1038071pfg.1.1696374416736; Tue, 03 Oct 2023 16:06:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696374416; cv=none; d=google.com; s=arc-20160816; b=wevuS4o7LSR+WbdXD+fxS8Yp40NtQ8zyCcffnPiJgAFoxmrkRvqRhnIjDKLmx1zGGa 5+piYIvsGtrjfM8LJskKJk/YMNQvTtd2el3xUo34DIZma4Ut8KGRyAn4e3bCIwBCnzmP Hz6fqAXctREkd2m9VPU0Ww8ixxn3JRLJyosETNLHWzrHKrd53cD9NN9bN2jJNbNCBXn8 J+QWTaWnLk/Ky5DrEud5jHvpApJwiwT3KvLUz0kCLXYFEIzvm7PIrlMvPS9qyWxuqcld Kwk72h65FMgV9tCRLIgezqiGe5YpaN6/Dz45m6QlHvJ/bCaMNmxLUelaOqORvEJGgryx Mw/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=BED3t2aRrxtx0D0q4ZEBs+ApkSmWh8HJDsZNXZO2H1E=; fh=Oky2e2xWfEzOsGtouKk/n07hRhp9/cEeH42Wn81MMI4=; b=lMKGqIUvf3lYhwDbYfvrqA6A7Yq/cElPv6o8TzLeUKpiSkL4Ge7v2mlUMfDyEHw9hJ eChkSfeoxtaeLZKNR2dR8fxSPouAHIgg/Jwelldq9Mdxh/Xf3ioHW75JMXmk8b7Lt9D+ pwlI0HbTVMoshG0JBPCfCQr2i7C/8Zhq3XptXc72DsWAPafSCKmTFQoRGo8DuEjuXuwa AVq0sREujlWmwKpiwFCagHqXMbbgGGE7pZK6KZiuo59ZkjkaAPMvMJamu7SSLRwWeq4A 7TUDDxv5gBBkOU5SR6OQ6hv1tdShhVNrwphfGA2X/CsIQ1OOQfpZCSTKmoQ9j+Nyz6Mm 48pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=TJhdldhY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id j26-20020a633c1a000000b00573f89ac5a1si2109004pga.102.2023.10.03.16.06.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:06:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=TJhdldhY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 7196E80C5C87; Tue, 3 Oct 2023 16:06:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231855AbjJCXGq (ORCPT + 99 others); Tue, 3 Oct 2023 19:06:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231504AbjJCXGp (ORCPT ); Tue, 3 Oct 2023 19:06:45 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D02CAB for ; Tue, 3 Oct 2023 16:06:42 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-99c136ee106so268182466b.1 for ; Tue, 03 Oct 2023 16:06:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696374401; x=1696979201; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=BED3t2aRrxtx0D0q4ZEBs+ApkSmWh8HJDsZNXZO2H1E=; b=TJhdldhY/lq5NAoTeyNdXfSWa2OwK0PBlKYQII4OhYv7/eTz26t8J7BnCKJSEH40JC +BpPvq7HOxdk3r3JFa17jtKJPJ1ZfLa+FWbBrO6pHWiH4UsLrP/KH6t5xbzPEQtgVHTR Tj2nxh+2AtYbqzcAlpUM6LJBBDFwet6JXVB1WfrQ9N0rO6oUPIPqsIllni53MFANCRMq FfU7UKZfAs4EWCv5uOISuUtguyUISA/C9JPm5SnKjkbFGUmYYAHESoxyhhZCxjl/ZwDz cVAGW7c4uS9XDYb4NsdexcnD1lxc6r8BYsVQNhMr4aBsAYoBGAJXKrgNATKVcZGfflbu HcmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696374401; x=1696979201; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BED3t2aRrxtx0D0q4ZEBs+ApkSmWh8HJDsZNXZO2H1E=; b=ruIUQbMtwXPcdCFQs59bMc1m33AojBLkUBrM+J9aTm26c3C5QFXWmJKi/geUmPrWw3 HUjSvR6x5IPYxLfSXX3mzGKzwx6r7V/kcR1vX7as+EB+zfMB158k9ap2jJwzAbq/73+N yTazfajWqtq42RwvQmDrgqHhGeNUgYr7g+xW2kXY7fJK8+3Y3ps2Dn4V66jSW1qSjIB6 q4mhpc+n4tzDmGdkA8R7C/GHhRct1ByjB2iVyiz03/vDWKUEi6buUiFz9qRybaMrSIe5 AAzLGEvNmR5XSIUNEn6cxPOrCLqGbvIbItfk1DeVIXVgr/1CuA1lmYk7Af2IpKeFq9x/ C6bw== X-Gm-Message-State: AOJu0YwcvUd48aiypEcwA80bavCEjMF3/vwdMW8VgzUs9Z8QSPFC0oqR nwZu8PdP37EMFlAAdrMDYAVZx1D8ftiuaSnfHjYejQ== X-Received: by 2002:a17:906:74cc:b0:99b:ead0:2733 with SMTP id z12-20020a17090674cc00b0099bead02733mr593265ejl.72.1696374400964; Tue, 03 Oct 2023 16:06:40 -0700 (PDT) MIME-Version: 1.0 References: <20230929180611.work.870-kees@kernel.org> <20230929180746.3005922-5-keescook@chromium.org> In-Reply-To: <20230929180746.3005922-5-keescook@chromium.org> From: Justin Stitt Date: Tue, 3 Oct 2023 16:06:28 -0700 Message-ID: Subject: Re: [PATCH 5/5] mlxsw: spectrum_span: Annotate struct mlxsw_sp_span with __counted_by To: Kees Cook Cc: Ido Schimmel , Petr Machata , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 03 Oct 2023 16:06:53 -0700 (PDT) On Fri, Sep 29, 2023 at 11:08=E2=80=AFAM Kees Cook = wrote: > > Prepare for the coming implementation by GCC and Clang of the __counted_b= y > attribute. Flexible array members annotated with __counted_by can have > their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUND= S > (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family > functions). > > As found with Coccinelle[1], add __counted_by for struct mlxsw_sp_span. > > [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/c= ounted_by.cocci > > Cc: Ido Schimmel > Cc: Petr Machata > Cc: "David S. Miller" > Cc: Eric Dumazet > Cc: Jakub Kicinski > Cc: Paolo Abeni > Cc: netdev@vger.kernel.org > Signed-off-by: Kees Cook > --- Great patch! Crucially, span->entries_count is assigned before any flexible array accesses. span->entries_count =3D entries_count; ... for (i =3D 0; i < mlxsw_sp->span->entries_count; i++) mlxsw_sp->span->entries[i].id =3D i; Reviewed-by: Justin Stitt > drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c b/driver= s/net/ethernet/mellanox/mlxsw/spectrum_span.c > index b3472fb94617..af50ff9e5f26 100644 > --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c > +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c > @@ -31,7 +31,7 @@ struct mlxsw_sp_span { > refcount_t policer_id_base_ref_count; > atomic_t active_entries_count; > int entries_count; > - struct mlxsw_sp_span_entry entries[]; > + struct mlxsw_sp_span_entry entries[] __counted_by(entries_count); > }; > > struct mlxsw_sp_span_analyzed_port { > -- > 2.34.1 > > Thanks Justin