From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90F39CE7A89 for ; Mon, 25 Sep 2023 07:09:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232419AbjIYHKC (ORCPT ); Mon, 25 Sep 2023 03:10:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232357AbjIYHKA (ORCPT ); Mon, 25 Sep 2023 03:10:00 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC097B8; Mon, 25 Sep 2023 00:09:53 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1725E1F38D; Mon, 25 Sep 2023 07:09:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1695625792; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=C0eOHy9J8tI0vJNwEUSpg51HLaOtlpzHMu3rel1MtGE=; b=dfrA12Qk77EK4VOjtFBeRlPf/2/rO0dIzJRbTm53kCKiKkjrhOAXyYwngWRjkdlWCKBy8L 4AlVHiKsDtPu7BeIozfsj7njYHSEkD3ibMDK3h4t71wMs5A28f/+Jysbs7EEhdTZ0h6DGy Kea5T6Zci15TAOzOFfZOntd5PKGozr0= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E57C61358F; Mon, 25 Sep 2023 07:09:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Hyz/ND8yEWWbMQAAMHmgww (envelope-from ); Mon, 25 Sep 2023 07:09:51 +0000 Date: Mon, 25 Sep 2023 09:09:51 +0200 From: Michal Hocko To: Kees Cook Cc: Andrew Morton , Shakeel Butt , Roman Gushchin , Johannes Weiner , "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: References: <20230922175327.work.985-kees@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230922175327.work.985-kees@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 22-09-23 10:53:28, 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 Acked-by: Michal Hocko > --- > 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); > }; > > struct mem_cgroup_thresholds { > -- > 2.34.1 -- Michal Hocko SUSE Labs