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 45016C64EDA for ; Thu, 17 Aug 2023 21:49:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355373AbjHQVsu (ORCPT ); Thu, 17 Aug 2023 17:48:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355495AbjHQVsi (ORCPT ); Thu, 17 Aug 2023 17:48:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 741FF1FF3; Thu, 17 Aug 2023 14:48:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ECC5B61AC3; Thu, 17 Aug 2023 21:48:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB7B3C433C8; Thu, 17 Aug 2023 21:48:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692308909; bh=bexJ/xREDVWvZmu+lu8XL2wVApfsd/lRowROzQZizoc=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=DEBtayWkbf820tXs6npe3l1kydGysurs82ZhdJ046kH4/0n2Tga8dbgPpaWymLVVm wbAh3DD/ZYklGV8PE9XptJijDDarWoCERbZglkf6nHXnzdPvmOTi3dDia1ZIqE1+1b MHLA0S/dBZrzYmfEWqdLvRdZZpVxBKiDa/WqpZbVOtDXdFIctcoUUL6pHv8Xyizee8 4FgALKGCCGjpWKoBuOt8/yQUsLkcvL+g+IBo4Sz3ri7uWbsdAhgcEEirVzPGhV0tJ0 ddajm0l3zYAFXl2O4WCaJyftSIN9aFdV5pFLwBRaS13Yc9phxiI4wvVUdMZXKKGf4B uCZl4IeEREStw== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 18 Aug 2023 00:48:24 +0300 Message-Id: Cc: "Dmitry Kasatkin" , "Paul Moore" , "James Morris" , "Serge E. Hallyn" , , , "Nathan Chancellor" , "Nick Desaulniers" , "Tom Rix" , , , Subject: Re: [PATCH] integrity: Annotate struct ima_rule_opt_list with __counted_by From: "Jarkko Sakkinen" To: "Kees Cook" , "Mimi Zohar" X-Mailer: aerc 0.14.0 References: <20230817210327.never.598-kees@kernel.org> In-Reply-To: <20230817210327.never.598-kees@kernel.org> Precedence: bulk List-ID: On Fri Aug 18, 2023 at 12:03 AM EEST, Kees Cook wrote: > Prepare for the coming implementation by GCC and Clang of the __counted_b= y > attribute. Flexible array members annotated with __counted_by can have > their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUND= S > (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family > functions). > > As found with Coccinelle[1], add __counted_by for struct ima_rule_opt_lis= t. > Additionally, since the element count member must be set before accessing > the annotated flexible array member, move its initialization earlier. > > [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/c= ounted_by.cocci > > Cc: Mimi Zohar > Cc: Dmitry Kasatkin > Cc: Paul Moore > Cc: James Morris > Cc: "Serge E. Hallyn" > Cc: linux-integrity@vger.kernel.org > Cc: linux-security-module@vger.kernel.org > Signed-off-by: Kees Cook > --- > security/integrity/ima/ima_policy.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima= /ima_policy.c > index 69452b79686b..f69062617754 100644 > --- a/security/integrity/ima/ima_policy.c > +++ b/security/integrity/ima/ima_policy.c > @@ -68,7 +68,7 @@ enum policy_rule_list { IMA_DEFAULT_POLICY =3D 1, IMA_C= USTOM_POLICY }; > =20 > struct ima_rule_opt_list { > size_t count; > - char *items[]; > + char *items[] __counted_by(count); > }; > =20 > /* > @@ -342,6 +342,7 @@ static struct ima_rule_opt_list *ima_alloc_rule_opt_l= ist(const substring_t *src) > kfree(src_copy); > return ERR_PTR(-ENOMEM); > } > + opt_list->count =3D count; > =20 > /* > * strsep() has already replaced all instances of '|' with '\0', > @@ -357,7 +358,6 @@ static struct ima_rule_opt_list *ima_alloc_rule_opt_l= ist(const substring_t *src) > opt_list->items[i] =3D cur; > cur =3D strchr(cur, '\0') + 1; > } > - opt_list->count =3D count; > =20 > return opt_list; > } > --=20 > 2.34.1 Acked-by: Jarkko Sakkinen BR, Jarkko