Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2832353rwb; Thu, 17 Nov 2022 17:13:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf7AmThvQS4pQA08fKa42JZOaR9PhAhPOmhaBOZ3lsWtoNk0zUvpiIgedi+YrnoCuzu2iUit X-Received: by 2002:a17:903:2d2:b0:186:827f:88f3 with SMTP id s18-20020a17090302d200b00186827f88f3mr5359012plk.75.1668734027373; Thu, 17 Nov 2022 17:13:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668734027; cv=none; d=google.com; s=arc-20160816; b=IDGGxEuaKHcH3pOp++agngoepI1L5xI2GcC6+B7KrdabzYoeYurKtERJc2HHXULTv5 B8adRNkCpCH68uhzBP3an73wHr+XhdgC6HCdTDqL1cTjgNIR5/Y7WvGT1Ymz5sGBd6z4 zb2I4B3IkBf1+HTlFzAIJIGEKBiupW3fL1ojNp6cV4PfpMUkkaGMQMQCcF79TZvMNF+n a4A9ShIj7Yeon4vhgatKCa9xvLO4BC2avjbtFvs0OpgtB1zuwQL83qHLpAtL9hUdwbTH p8BxmxuW4YeU+gO4xhy2RinO6QSpVcCltQCdBFG6Swz7nE4Jdsp4pibaBJykOkpJfanf kREQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=XvIoWSd0xrw6RZJQp73B+S5uCJ5LMxazrUmMxPfNjuQ=; b=Pu7EvVRlUBQVzDnbbBula4WDArdsfurHY2AIVovzWWV41xw5gCeeXM+ssXGUR4JJ9A o6XPQwqx532fo/Ba0qWQbDRLIS/BEieRCMNyWBxhZ1TywVQtbH3QjP15wpZjZxRXg4mo 3C5fK0s8G9yBYCyF9WhLdi/12+aYKjxixPeBC4oRATbu4Yv04aIauQjwukup8Sv9guSy q2G05haqbtnvBwsDCwrJYUCVB4e4bXQiI5U4KVWjSuk2Z04JhMavPhFrHC+FO25+e5kD FRJ2Vq+FI4RyR7QME/4uDD+nV5FHC/VFA8EziEpyUBZrKA7TLj/5A+7MhwGcTFGVRzPn xiEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Ywx/QwtK"; 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 z14-20020a170903018e00b00186e9ff4edcsi2557615plg.408.2022.11.17.17.13.35; Thu, 17 Nov 2022 17:13:47 -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="Ywx/QwtK"; 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 S234928AbiKRAyh (ORCPT + 91 others); Thu, 17 Nov 2022 19:54:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240769AbiKRAyf (ORCPT ); Thu, 17 Nov 2022 19:54:35 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCCA085EE8 for ; Thu, 17 Nov 2022 16:54:34 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id v4-20020a17090a088400b00212cb0ed97eso3600414pjc.5 for ; Thu, 17 Nov 2022 16:54:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=XvIoWSd0xrw6RZJQp73B+S5uCJ5LMxazrUmMxPfNjuQ=; b=Ywx/QwtKH8VAB4UddTVRkYxOW2k+PyRwVVpR4TEzkhDl4DjNzjqniVbWpNQeGC15uz THTgtgOC2tJtLxcn+N6qnN3Uy3FVT4qmUSr3XOZgiLlJCWs0v/93AF1Vt/H6ei2/0on5 d7zw7FPkZM/4CTydhHhG2fL1TGCDWupJAjNhw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=XvIoWSd0xrw6RZJQp73B+S5uCJ5LMxazrUmMxPfNjuQ=; b=KVZmD8R9nvX4CRyzex9ijtuce4WrMiJd42IVvHlsSjignYO7CCaUGqiE+M0ux78ezX oQRa4I1FVLncX9PlUaX1vt5aDK1J9AqPy9DL7EIPqWgz9o0knAll6eWBYxe5tiDj8d+U Fa91fSBEs/cM0vmhxHL4Et+c7bpSOFt20RQU5oUDTSzNZPri/uhuo2GQHnjxwCWatI18 ESk1j+ZWIis7QR7rjKye8b6wwmeU1JVGbUz0WmV7n49hcwxspbESOIS3ctFeH5J8K2Vs /D1hNsDB1usqdLSdey+1E0NnrK7pUyFy0LKYxFUel8VJdKNze7f3t/gBf4HbGmYKlOcI N9Mw== X-Gm-Message-State: ANoB5pkl9XlNdQZ4z0WzPYyILjhpRUYJz0UbGvH0tsDQwPcD1ppoHHxH esjImJatlaABwaY5Xp4F8GDMBk27xRI9EQ== X-Received: by 2002:a17:902:c652:b0:186:af8e:7ed4 with SMTP id s18-20020a170902c65200b00186af8e7ed4mr5223346pls.7.1668732874435; Thu, 17 Nov 2022 16:54:34 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id j6-20020a17090276c600b00172b87d9770sm2073855plt.81.2022.11.17.16.54.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 16:54:33 -0800 (PST) Date: Thu, 17 Nov 2022 16:54:33 -0800 From: Kees Cook To: sdf@google.com Cc: wangkailong@jari.cn, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Subject: Re: [PATCH] samples/seccomp: fix array_size.cocci warning Message-ID: <202211171653.0E3BA8E71B@keescook> References: <2b3f2420.130.184706d34e6.Coremail.wangkailong@jari.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 On Mon, Nov 14, 2022 at 09:15:35AM -0800, sdf@google.com wrote: > On 11/13, wangkailong@jari.cn wrote: > > Fix following coccicheck warning: > > > samples/seccomp/bpf-fancy.c:83:39-40: WARNING: Use ARRAY_SIZE > > samples/seccomp/bpf-fancy.c:86:44-45: WARNING: Use ARRAY_SIZE > > Not sure this should go via bpf tree. CC'ed Kees > > > Signed-off-by: KaiLong Wang > > --- > > samples/seccomp/bpf-fancy.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > diff --git a/samples/seccomp/bpf-fancy.c b/samples/seccomp/bpf-fancy.c > > index 1ccb435025b6..548f038924d6 100644 > > --- a/samples/seccomp/bpf-fancy.c > > +++ b/samples/seccomp/bpf-fancy.c > > @@ -80,10 +80,10 @@ int main(int argc, char **argv) > > }; > > struct sock_fprog prog = { > > .filter = filter, > > - .len = (unsigned short)(sizeof(filter)/sizeof(filter[0])), > > + .len = (unsigned short)(ARRAY_SIZE(filter)), > > }; > > ssize_t bytes; > > - bpf_resolve_jumps(&l, filter, sizeof(filter)/sizeof(*filter)); > > + bpf_resolve_jumps(&l, filter, ARRAY_SIZE(filter)); Hm, this is the "samples" tree, so this was intentionally avoiding these kinds of kernel-isms, but perhaps that doesn't realistically matter? -Kees > > > if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) { > > perror("prctl(NO_NEW_PRIVS)"); > > -- > > 2.25.1 -- Kees Cook