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 X-Spam-Level: X-Spam-Status: No, score=-8.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6058FC4338F for ; Wed, 18 Aug 2021 06:31:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E8D1B60720 for ; Wed, 18 Aug 2021 06:30:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E8D1B60720 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=perches.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 961516B0072; Wed, 18 Aug 2021 02:30:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E8AB6B0073; Wed, 18 Aug 2021 02:30:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 788758D0001; Wed, 18 Aug 2021 02:30:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0253.hostedemail.com [216.40.44.253]) by kanga.kvack.org (Postfix) with ESMTP id 5FC956B0072 for ; Wed, 18 Aug 2021 02:30:59 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EB9831F36A for ; Wed, 18 Aug 2021 06:30:58 +0000 (UTC) X-FDA: 78487228596.24.C2FBF06 Received: from smtprelay.hostedemail.com (smtprelay0188.hostedemail.com [216.40.44.188]) by imf11.hostedemail.com (Postfix) with ESMTP id A0F43F0058BE for ; Wed, 18 Aug 2021 06:30:58 +0000 (UTC) Received: from omf03.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay06.hostedemail.com (Postfix) with ESMTP id 46E201822186F; Wed, 18 Aug 2021 06:30:58 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf03.hostedemail.com (Postfix) with ESMTPA id D94EF13D97; Wed, 18 Aug 2021 06:30:53 +0000 (UTC) Message-ID: Subject: Re: [PATCH 2/5] slab: Add __alloc_size attributes for better bounds checking From: Joe Perches To: Kees Cook Cc: linux-kernel@vger.kernel.org, Daniel Micay , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , linux-mm@kvack.org, Miguel Ojeda , Nathan Chancellor , Nick Desaulniers , Dennis Zhou , Tejun Heo , Masahiro Yamada , Michal Marek , clang-built-linux@googlegroups.com, linux-kbuild@vger.kernel.org, linux-hardening@vger.kernel.org Date: Tue, 17 Aug 2021 23:30:52 -0700 In-Reply-To: <202108172312.7032A3E@keescook> References: <20210818050841.2226600-1-keescook@chromium.org> <20210818050841.2226600-3-keescook@chromium.org> <202108172312.7032A3E@keescook> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.40.0-1 MIME-Version: 1.0 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX18CHCANKQ9SjuGNd1lv9bArDZG2IJwopqI= X-HE-Tag: 1629268253-493183 Authentication-Results: imf11.hostedemail.com; dkim=none; spf=none (imf11.hostedemail.com: domain of joe@perches.com has no SPF policy when checking 216.40.44.188) smtp.mailfrom=joe@perches.com; dmarc=none X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A0F43F0058BE X-Stat-Signature: q7nthps38a63fpjgsrfk3chw4uekgi3d X-HE-Tag: 1629268258-806922 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, 2021-08-17 at 23:16 -0700, Kees Cook wrote: > On Tue, Aug 17, 2021 at 10:31:32PM -0700, Joe Perches wrote: > > On Tue, 2021-08-17 at 22:08 -0700, Kees Cook wrote: > > > As already done in GrapheneOS, add the __alloc_size attribute for > > > regular kmalloc interfaces, to provide additional hinting for bette= r > > > bounds checking, assisting CONFIG_FORTIFY_SOURCE and other compiler > > > optimizations. [] > > Lastly __alloc_size should probably be added to checkpatch >=20 > Oh, yes! Thanks for the reminder. >=20 > > Maybe: > > --- > > =A0scripts/checkpatch.pl | 3 ++- > > =A01 file changed, 2 insertions(+), 1 deletion(-) > >=20 > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > > index 161ce7fe5d1e5..1a166b5cf3447 100755 > > --- a/scripts/checkpatch.pl > > +++ b/scripts/checkpatch.pl > > @@ -489,7 +489,8 @@ our $Attribute =3D qr{ > > =A0 ____cacheline_aligned| > > =A0 ____cacheline_aligned_in_smp| > > =A0 ____cacheline_internodealigned_in_smp| > > - __weak > > + __weak| > > + __alloc_size\s*\(\s*\d+\s*(?:,\s*d+\s*){0,5}\) >=20 > Why the "{0,5}" bit here? I was expecting just "?". (i.e. it can have > either 1 or 2 arguments.) You are right. I misread the doc. I also missed a \ before the last d. So that last added line should maybe be: (totally untested btw) + __alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\)