Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp3013778rdb; Fri, 22 Sep 2023 15:31:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGwWrkryMzaFyKmIDC/59CaT2Sd1yEC6SP/3qHsaYMtgIMaOq2dlaOmb92EpCEIIG0hC9sh X-Received: by 2002:a17:902:d34c:b0:1b2:676d:1143 with SMTP id l12-20020a170902d34c00b001b2676d1143mr1226920plk.15.1695421873480; Fri, 22 Sep 2023 15:31:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695421873; cv=none; d=google.com; s=arc-20160816; b=SrXgqaaYJOyQTIFnm/mdhHvEFGvrshEJYP4MDDQmKlKKU5cNyW+kOasl3ooSmxEv/2 i57uhmG9vFRUdFdJ5NFWofTvfFWMVAoR6noJ+wZzPNK+jWo41gRw2Ts96tYeuTPjlVCI ayCux75Z5OGw+Tl2h8LZbNKK09C7DuPKQT7xzNPuhMCFzRgkhGTaOjsucRCzoihoK8wM eZgc8OGy912p87OulHTiVs5mYqcPnz0mPnsisGTqdBXMvLqpYRhtWpBb1sThF644E3u7 LUBf1grRLezy53+p8YL22f7Qwyayff/xSQmzkVb6dIeOb0eSby3Q2fnrXefyqhziSKgP 0cAA== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ngBf+ICvbxi0AiCYVulY76r9llgqXQtbJzL3HizOtVw=; fh=DjKFw7KB6qMx1yejZYyOriJuqgBFl4X0ZsyCR0cez54=; b=TKlFJAD915c84k519GRFSI2l5uOgGFoQ5+pLId1dFdI+EGowX61Un9HtV0fApk1+0v +rrxcQnycV7zN/QpNMgluFSrOD7Gv5e43dRsOJ7oFdZAgnd7VLR7kxv0f9ZCReQ5kISx J5gaJqGmphC8WpEz/fc8V7NGljLh8sBCnx31ykgFCq5LD9xKEQPAkQo0uPN4wuAglnwM pQDNT7GcGPszubWFNEL9e+qSAVh0Hq3IACCr0Ffri6NQ3CljbjNfNmZhcSaNGAP2NgtO Dqh5Ase5sKrsXNQPzFSYH75AyVH3o1uBQZuJFYHasTnAG6X+A3JdQMQCHobOdWPpoMGm PlWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="THn26/uo"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id f18-20020a170902ce9200b001b9d5f07068si4747372plg.585.2023.09.22.15.30.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 15:31:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="THn26/uo"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id C86DB82C1331; Fri, 22 Sep 2023 11:32:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233220AbjIVScM (ORCPT + 99 others); Fri, 22 Sep 2023 14:32:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233267AbjIVScL (ORCPT ); Fri, 22 Sep 2023 14:32:11 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3A09C1 for ; Fri, 22 Sep 2023 11:32:03 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-578a62c088cso2984697a12.1 for ; Fri, 22 Sep 2023 11:32:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695407523; x=1696012323; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=ngBf+ICvbxi0AiCYVulY76r9llgqXQtbJzL3HizOtVw=; b=THn26/uovqc6YYrJhCHEn9NZwjIxqhMByK+6Z6snN6B/UuS3mnUduGhdG5MDM3Hikg RYmbD/9kfrbH629kT36/LB9VTzVTWSXoHsKuZpwt2ZhCamkHYVGK5KSnjrwqI0M9R0z4 fNlbdFxf012kTFbatXD2Bp1HGu27p87yUEiVc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695407523; x=1696012323; h=in-reply-to:content-transfer-encoding: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=ngBf+ICvbxi0AiCYVulY76r9llgqXQtbJzL3HizOtVw=; b=B0mA17HrDzOOw+9VQ+XWU85yXV/axogRU5FMjn+plaXdXt0ysHE6w7438quTh5WBAU n5adrrtU3UmM9s3altFFO9EWOdd70r/v92lIq841fVQYDZ0C7rb9rlZE/xVA8xsBpSW0 V9E2PTLnVe/sQ+8pVSRPDANq0dIzeyJEYVaa8mpRWZxz2PSl7JUwMIo1LndW97GzJe9l kZ59gk+d67o3uqvGT6SsoB6nozonFrxauLS+Y1Cxg8u0HHGEnAEu/NHIYxCeHR1W3x9I 2D/4MLevmLeaNallPa9f2yRmNtagKzu/B2TUaJQU84UJHfOdmQgpV5WWAt6ZWhzMWRii HEiw== X-Gm-Message-State: AOJu0Yzk7BsN0VLo2+jhqf9YmsZx3HfBOEy2uFAM/AB0RI7HLDjdugaG lzD5cxnLqXn1yE5ZkZibNolO/g== X-Received: by 2002:a17:90a:428b:b0:268:535f:7c15 with SMTP id p11-20020a17090a428b00b00268535f7c15mr5122344pjg.0.1695407523130; Fri, 22 Sep 2023 11:32:03 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id 14-20020a17090a004e00b0025dc5749b4csm5726599pjb.21.2023.09.22.11.32.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 11:32:02 -0700 (PDT) Date: Fri, 22 Sep 2023 11:32:02 -0700 From: Kees Cook To: Shakeel Butt Cc: Andrew Morton , Roman Gushchin , Johannes Weiner , Michal Hocko , "Matthew Wilcox (Oracle)" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Yosry Ahmed , Yu Zhao , Miaohe Lin , Yafang Shao , Kefeng Wang , Qi Zheng , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org Subject: Re: [PATCH] mm/memcg: Annotate struct mem_cgroup_threshold_ary with __counted_by Message-ID: <202309221128.6AC35E3@keescook> References: <20230922175327.work.985-kees@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Fri, 22 Sep 2023 11:32:15 -0700 (PDT) On Fri, Sep 22, 2023 at 11:25:56AM -0700, Shakeel Butt wrote: > On Fri, Sep 22, 2023 at 10:53 AM 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 checking 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 mem_cgroup_threshold_ary. > > > > [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci > > > > Cc: Andrew Morton > > Cc: Shakeel Butt > > Cc: Roman Gushchin > > Cc: Johannes Weiner > > Cc: Michal Hocko > > Cc: "Matthew Wilcox (Oracle)" > > Signed-off-by: Kees Cook > > --- > > include/linux/memcontrol.h | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > > index 45d0c10e86cc..e0cfab58ab71 100644 > > --- a/include/linux/memcontrol.h > > +++ b/include/linux/memcontrol.h > > @@ -143,7 +143,7 @@ struct mem_cgroup_threshold_ary { > > /* Size of entries[] */ > > unsigned int size; > > /* Array of thresholds */ > > - struct mem_cgroup_threshold entries[]; > > + struct mem_cgroup_threshold entries[] __counted_by(size); > > Does 'size' here have to be a member of the same struct as entries? We > have nodeinfo[] in struct mem_cgroup whose size is nr_node_ids which > is global. Will __counted_by() work for that? Not presently, no. This may come in future expansions of the feature. We're also hoping to gain expressions for places where a size isn't a native count, like for big endian, or a byte count that includes the entire struct, etc. For now, though, the feature is narrowly scoped just to get the common case landed. -Kees -- Kees Cook