Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp2184099rwe; Sun, 28 Aug 2022 05:48:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR4Sla1j2IWvsrGo5arOWoeqY3FqIaNDjYnvjJVDnnrJdDvrtoPe9wjfwCeFAMBsGzd2x7df X-Received: by 2002:a05:6a00:1a14:b0:52d:3e35:5b38 with SMTP id g20-20020a056a001a1400b0052d3e355b38mr12284929pfv.11.1661690906838; Sun, 28 Aug 2022 05:48:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661690906; cv=none; d=google.com; s=arc-20160816; b=lojevCLIcI61wlavbWlk8hYJP8D+GRFnZ6c07S4BoR771YvgXIzxCOHbdWtJWkBRdp sKW4ChJykhE/JXm2NPTJ6yLpmWg7IOGEBeIDcOzpG9tNsxrgWgGwtejfVsmuXGXWBoxq ETRz3Q8qqEF3TlFK+hYK5dl/l0UxZyh6muwCIvUVPJBVQZZKjs/mhi+ZL8Kx1poXmvFW wCsPBkPggMu0eKSqQkumTJk/6Y1vhz3tpmLk6Of8jnjQziZ1ghsAnYrr2iQ/ZdbZsnKb agoo3hsXo0AC3uEa8uGQV4RU2igdFdZ9Vly877FlICHiDiaM+94MVcopYxkK5eYs0+NH PuiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=QnDpIvzrNan/ql9Cui0VfN9yT3G33NJo7lAq5bBpUpo=; b=JEFpokkmk6rih0ufND0SywzvvdJPVRCTkbZYpeWcsparSBjyS+qnqZCi81j04/5wzc Rr2tTZTuLvJZ8pcORC9j0UUmxlEmQb/JGD41DvdGkLcVT7rHHZuFn9p7q33HIzjg4g02 HBp9Spbt1z6VC91a2BJF5Fnd6sMweC7Qr0dxzPemuF2b0oC+GmIU0oKaXkSH7PimoxUi rjWHfvoYrthRHXL1g7whikmLT520ddx3tzDUp8C4afGfAOvw4uiebJ6V3fL1Jgi4OTqC ZnF16Pz2u1Q/y4hmnps8zBrFklVpPzjSa3PTm6WYdaCAxp9/k4r7GEFqpf+yyur22niD SZGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SHAE+kGe; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r26-20020a63515a000000b0041d9a9bb77fsi6488978pgl.45.2022.08.28.05.47.55; Sun, 28 Aug 2022 05:48:26 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=SHAE+kGe; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229812AbiH1MEo (ORCPT + 99 others); Sun, 28 Aug 2022 08:04:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbiH1MEm (ORCPT ); Sun, 28 Aug 2022 08:04:42 -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 6F2E81CFC9 for ; Sun, 28 Aug 2022 05:04:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EBA5960FEE for ; Sun, 28 Aug 2022 12:04:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58593C43470 for ; Sun, 28 Aug 2022 12:04:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661688279; bh=EPbkOq8JPEc2kCjTiNGhxLiypn6VkEpuIIxi7EoZbZ0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=SHAE+kGe2sPxFytEMt95ciLuQ+18eacjczlKIjy44AFd4UEoXYe01I/7x9RXuUiaL Lh0xeXhH8x1IxacIkT1oe6NXLdIVp7M+W0MmgsMjkVfEVTLfkTx/91XGQ60ZV6m47S lEMjN340CoOKfGn+bofyy7jYNGSeCj8uQXLhqMFNgpifExeVu7cwfd8Qymz3wX69RM E4laPXbt9RAg/8OBKxNrKX7KdzgQK9DbT5zI3DqeOuWplLDH5+JdyrKfCeNci0D+ee /qGKjunCYPpJKnKbaJds/8RPKFNJH44hlP5PZhs9FbPQ5GDG6fB3mNclT0bDGWj0p+ TJyU69cbQXBxQ== Received: by mail-qt1-f175.google.com with SMTP id e28so4415362qts.1 for ; Sun, 28 Aug 2022 05:04:39 -0700 (PDT) X-Gm-Message-State: ACgBeo05DgjRHusrEvPHOoDvYzzTCSN71C2AsgvnGXmWw6QSa/z6iIwm K2SANqMD0eO9y30AdSAy8tEyZ5UNpuoSjXCZyIDkKg== X-Received: by 2002:a05:620a:45a3:b0:6bb:d296:aa0d with SMTP id bp35-20020a05620a45a300b006bbd296aa0dmr5219938qkb.525.1661688267813; Sun, 28 Aug 2022 05:04:27 -0700 (PDT) MIME-Version: 1.0 References: <20220818152929.402605-1-roberto.sassu@huaweicloud.com> <20220818152929.402605-5-roberto.sassu@huaweicloud.com> In-Reply-To: From: KP Singh Date: Sun, 28 Aug 2022 14:04:17 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v12 04/10] KEYS: Move KEY_LOOKUP_ to include/linux/key.h To: Jarkko Sakkinen Cc: Roberto Sassu , ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, sdf@google.com, haoluo@google.com, jolsa@kernel.org, mykolal@fb.com, corbet@lwn.net, dhowells@redhat.com, rostedt@goodmis.org, mingo@redhat.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, shuah@kernel.org, bpf@vger.kernel.org, linux-doc@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, deso@posteo.net, Roberto Sassu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Sun, Aug 28, 2022 at 5:57 AM Jarkko Sakkinen wrote: > > On Fri, Aug 26, 2022 at 09:14:09AM +0200, Roberto Sassu wrote: > > On Fri, 2022-08-26 at 08:42 +0300, Jarkko Sakkinen wrote: > > > On Thu, Aug 18, 2022 at 05:29:23PM +0200, > > > roberto.sassu@huaweicloud.com wrote: > > > > From: Roberto Sassu > > > > > > > > In preparation for the patch that introduces the > > > > bpf_lookup_user_key() eBPF > > > > kfunc, move KEY_LOOKUP_ definitions to include/linux/key.h, to be > > > > able to > > > > validate the kfunc parameters. > > > > > > > > Also, introduce key_lookup_flags_check() directly in > > > > include/linux/key.h, > > > > to reduce the risk that the check is not in sync with currently > > > > defined > > > > flags. > > > > > > Missing the description what the heck this function even is. > > > > > > Please, explain that. > > > > Hi Jarkko > > > > sorry, forgot to update the commit description. Will do it. > > > > > Also, the short subject is misleading because this *just* > > > does not move flags. > > > > > > > Signed-off-by: Roberto Sassu > > > > Reviewed-by: KP Singh > > > > --- > > > > include/linux/key.h | 11 +++++++++++ > > > > security/keys/internal.h | 2 -- > > > > 2 files changed, 11 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/include/linux/key.h b/include/linux/key.h > > > > index 7febc4881363..b5bbae77a9e7 100644 > > > > --- a/include/linux/key.h > > > > +++ b/include/linux/key.h > > > > @@ -88,6 +88,17 @@ enum key_need_perm { > > > > KEY_DEFER_PERM_CHECK, /* Special: permission check is > > > > deferred */ > > > > }; > > > > > > > > +#define KEY_LOOKUP_CREATE 0x01 > > > > +#define KEY_LOOKUP_PARTIAL 0x02 > > > > + > > > > > > /* > > > * Explain what the heck this function is. > > > */ > > > > +static inline int key_lookup_flags_check(u64 flags) > > > > +{ > > > > + if (flags & ~(KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL)) > > > > + return -EINVAL; > > > > + > > > > + return 0; > > > > +} > > > > > > This is essentially a boolean function, right? > > > > > > I.e. the implementation can be just: > > > > > > !!(flags & ~(KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL)) > > > > Absolutely fine with that, if you prefer. > > It can be either, it more depends on if a new function > is needed in the first place. > > E.g. if you are worried about maintaining you could just > as well define a constant containing the mask, right? +1 A mask is better. > > > > > > Not even sure if this is needed in the first place, or > > > would it be better just to open code it. How many call > > > sites does it have anyway? > > > > > > > Daniel preferred to have this check here. > > How many call sites? > > BR, Jarkko