Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp683654rdb; Fri, 6 Oct 2023 16:02:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGN/FFasB70QmNrGYxew0PhUYCaK6Rs0n1nqg9NNsVRRofjdl5yK/t+UJI7Wmb/aWHYEECD X-Received: by 2002:a05:6a20:7d84:b0:15c:b7ba:9137 with SMTP id v4-20020a056a207d8400b0015cb7ba9137mr11795203pzj.2.1696633365852; Fri, 06 Oct 2023 16:02:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696633365; cv=none; d=google.com; s=arc-20160816; b=fuCjI11vIfZbWbVovqpu18Q6FZK8DnzsZn1neWrfJIweX77A9/4xa7QZtp4DnibhBY QBn8R/jhCBKLajbbcRMdUS6Iz33DCTkkkixYfCErkDCoBf90ftR8x2brlvJ6+MVKfc14 0phpdvcHCcpgUHZV66KZZflGi1GVFvcjUBbM0HWJFq+YtAUBdDuezGn3FuGVQGJHq8+y IOY/CSVLGLhzsg47bNEZMK9I9wO/N7G6P3xKsnd005/1lerk3REKrfbk8oody27uVG8w UP1EOc9Ol2wqPXUhpRb60B+yLr5ELS8oUbh0iJ+vAPdJEo3S1QIkYPvw80WpCngscBY0 zgYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=D1jWl+Tzg11Q4/gxmIXK9n2WMBr7aaQFJ8hHOf2UdsQ=; fh=aTWOeQYNYmaDoKsrCQxh+qHKOv+wPawD3eZ0N9Cdr0I=; b=rjVkYLh/BQgdqXhZUCmhYCvKWL2EVTSE02LT4UMiVtp0bpY66POb272lzPRLyWI4dk jBWMUstWtJaoSdYfcCX2pr1JwGz1cylkbCJAdEiriSKy5vDYsq61/9xVYhgnqxcnR9Xy e0ruVU7m+3pEmyff3gQUsc7Z583iZb2qOMWdJjHTNJHyfaMX6aPhXAhCXGt5rjtbRGYb lIjeBX46zZqB/IHwu0pEBRX1dCAtkvF0kt22C5q91GDskf/Sctnu180Cfkozfc9hEL+8 28QWKs0MB222+/gewC2Fzj8cjyx3RdDy0hB3/2gmMIe19dL8L/Nuw2ziid5nzNZP4oZi PPGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b="ePX/sYbp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id w10-20020a170902e88a00b001c6223663b2si4881725plg.339.2023.10.06.16.02.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 16:02:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b="ePX/sYbp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 1E79C802A9FA; Fri, 6 Oct 2023 16:02:43 -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 S233881AbjJFXCQ (ORCPT + 99 others); Fri, 6 Oct 2023 19:02:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233820AbjJFXCO (ORCPT ); Fri, 6 Oct 2023 19:02:14 -0400 Received: from omta038.useast.a.cloudfilter.net (omta038.useast.a.cloudfilter.net [44.202.169.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4351F9C; Fri, 6 Oct 2023 16:02:12 -0700 (PDT) Received: from eig-obgw-6005a.ext.cloudfilter.net ([10.0.30.201]) by cmsmtp with ESMTP id orRIqdGkHqBU3otpjqVuis; Fri, 06 Oct 2023 23:02:11 +0000 Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with ESMTPS id otpiqd15fsqNFotpiqdcYf; Fri, 06 Oct 2023 23:02:10 +0000 X-Authority-Analysis: v=2.4 cv=aPzjFJxm c=1 sm=1 tr=0 ts=652091f2 a=1YbLdUo/zbTtOZ3uB5T3HA==:117 a=Dx1Zrv+1i3YEdDUMOX3koA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10 a=bhdUkHdE2iEA:10 a=wYkD_t78qR0A:10 a=VwQbUJbxAAAA:8 a=hWMQpYRtAAAA:8 a=pGLkceISAAAA:8 a=1XWaLZrsAAAA:8 a=NEAV23lmAAAA:8 a=cm27Pg_UAAAA:8 a=GO2MODqShKhmYEK19rIA:9 a=QEXdDO2ut3YA:10 a=AjGcO6oz07-iQ99wixmX:22 a=KCsI-UfzjElwHeZNREa_:22 a=xmb-EsYY8bH0VWELuYED:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=D1jWl+Tzg11Q4/gxmIXK9n2WMBr7aaQFJ8hHOf2UdsQ=; b=ePX/sYbpKTIU/yGeXz9L+5lgna Hr5tQZm1PJJuwoB480gET8ruoogLBVGfA6PEAsSTnl81iBF57gow0WycKxTc7MEliqABUbmKpBzrB PmVcQihYF9wJMLqh2wA/lEAlECvczrvlmxKNWsgYylZcR7RvBsoQsRREHuW1HL6d1KoKXzwnrSRgX hsfGq194ZqjEHxoF1jT+6f1gQoGIoG8Y8dC9nmLX68LfJ/oq1bpJNr0gZJQOR0OF5640Gf+RDIYld 9nqlCB42qcwp4tXelWk75+PJ8DZ6u/s1ZpVSC6wtvKT68KhCYmi9kgRSD7dGGB6g2VziLJlTOOZUX iWJ2TQWg==; Received: from 94-238-9-39.abo.bbox.fr ([94.238.9.39]:47408 helo=[192.168.1.98]) by gator4166.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96.1) (envelope-from ) id 1qorm9-001Bge-1M; Fri, 06 Oct 2023 15:50:21 -0500 Message-ID: <6b203ddd-d8d9-46e3-acbd-89d658f80e3a@embeddedor.com> Date: Fri, 6 Oct 2023 22:50:15 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] bpf: Annotate struct bpf_stack_map with __counted_by Content-Language: en-US To: Kees Cook , Song Liu Cc: Jiri Olsa , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , "Gustavo A. R. Silva" , bpf@vger.kernel.org, linux-hardening@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev References: <20231006201657.work.531-kees@kernel.org> From: "Gustavo A. R. Silva" In-Reply-To: <20231006201657.work.531-kees@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 94.238.9.39 X-Source-L: No X-Exim-ID: 1qorm9-001Bge-1M X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 94-238-9-39.abo.bbox.fr ([192.168.1.98]) [94.238.9.39]:47408 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 0 X-Org: HG=hgshared;ORG=hostgator; X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfPbIlqTGL6AuBhAaU/RqerWqzU9CWVTp3Q4V017J421Xs7UiLFH7qNBwND26g4H0OrN2bExfYRtVpC/dWpNok8zBA2QN2U5+0oY2NPq4jcqmno0tTkVW I5hFBqdX3ODmtm52YikTT0qn1nCU6kLELF+gV/tifgMMIHvLglEfDLX22gIlyAlrMlpx84GFgOGD1ilh+G3d0G0aMRRHGjhyFGVmHAt3HwPI++3l7qSFsLZZ DGkjYkt7XLtjXoL4tS/9uv98izIAU6b7wHLqmUW2+ZbClN9TW1x8e4kt62HjQphE X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no 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]); Fri, 06 Oct 2023 16:02:43 -0700 (PDT) X-Spam-Level: *** On 10/6/23 22:17, Kees Cook wrote: > Prepare for the coming implementation by GCC and Clang of the __counted_by > attribute. Flexible array members annotated with __counted_by can have > their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for > array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family > functions). > > As found with Coccinelle[1], add __counted_by for struct bpf_stack_map. > > Cc: Song Liu > Cc: Jiri Olsa > Cc: Alexei Starovoitov > Cc: Daniel Borkmann > Cc: Andrii Nakryiko > Cc: Martin KaFai Lau > Cc: Yonghong Song > Cc: John Fastabend > Cc: KP Singh > Cc: Stanislav Fomichev > Cc: Hao Luo > Cc: "Gustavo A. R. Silva" > Cc: bpf@vger.kernel.org > Cc: linux-hardening@vger.kernel.org > Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1] > Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva Thanks! -- Gustavo > --- > kernel/bpf/stackmap.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c > index 458bb80b14d5..d6b277482085 100644 > --- a/kernel/bpf/stackmap.c > +++ b/kernel/bpf/stackmap.c > @@ -28,7 +28,7 @@ struct bpf_stack_map { > void *elems; > struct pcpu_freelist freelist; > u32 n_buckets; > - struct stack_map_bucket *buckets[]; > + struct stack_map_bucket *buckets[] __counted_by(n_buckets); > }; > > static inline bool stack_map_use_build_id(struct bpf_map *map)