Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3829409rwa; Tue, 23 Aug 2022 10:50:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR49YH+fFKYgJpSYzSTQaDgMvC8TXfby7Ve6t5zGmT+163ifVcgiUveH8+bUsnuOBVBl8NTO X-Received: by 2002:a63:1660:0:b0:42a:7efe:d554 with SMTP id 32-20020a631660000000b0042a7efed554mr12876109pgw.110.1661277000911; Tue, 23 Aug 2022 10:50:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661277000; cv=none; d=google.com; s=arc-20160816; b=d1Wdz+wWigxTrZjFE9P419aEymP8Y7YGjNrmgf0uIIf3YUoNyAqMMyPMbEUvDoW2rr BTWsAyfHjpnw2yg7YmlAvfJ3q3eVbj3RW0G+NDjT94ERGEPvhvsacDoGLdX787EU0mim G/JET7einVUalqDMmhBF26l+sNLgT5dvZYxIZEFXp5i/AE2IUv6Vsd5vGYutnJD0Zk56 HxVlcD0H+nfJFIZ9AuU3ZoBXXVmnNAnEBUUXiVKKJ3zTNtoxr1fLe/Pk/yuvDgt5Yf1K Xs9+l9YSvENlV9phqD4qh7kMw1NiHZpcWo6IxZTL7p+VD5biIZpnQ3Ym2qFpVqP2Yd1g nBBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=KzJ7OVZydgDsIAkOjoSU2WWljXEG5D+tvBLDZQIFVZg=; b=SkDpZkOTD4oLVZzVe2NhOs6lPudT2c8wxaPPMDQjppAf7MUfTw/G7iXgvu89sZlLyg DRwGz15gtn5OHMsT8LJ1/uGFwy4XbtRlsJkgcIw2brF5i/tq0uGP+ZkJFX+qkntOwODx mO3FhMF3EmhnIML+EjGjhhHccYHCk/8m5K77gLiOmPrSLHhFcADnr9jUbbfTcY/m9w5y clAODHVCyhBu3fmTLbh7KuHzynm/Cfvlhzd3bIUdJqjFas63lfKOxgnYkbDtbcIzUKVL jXDYauZQIzgO/8ASE+NZ6PFnGChgHOASpympkrzKLKQ7DNZSIzr8LH3S5yHi7TFoTU5B KfeA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d67-20020a636846000000b00429a15b4d01si15775217pgc.814.2022.08.23.10.49.49; Tue, 23 Aug 2022 10:50:00 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234214AbiHWR0Z (ORCPT + 99 others); Tue, 23 Aug 2022 13:26:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235136AbiHWRZm (ORCPT ); Tue, 23 Aug 2022 13:25:42 -0400 Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CB918FD43; Tue, 23 Aug 2022 08:02:20 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4MBskz1KQ3z9v7Gw; Tue, 23 Aug 2022 22:56:59 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP2 (Coremail) with SMTP id GxC2BwBnIhqd6wRjjU5GAA--.52413S6; Tue, 23 Aug 2022 16:01:51 +0100 (CET) From: Roberto Sassu To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, mykolal@fb.com, corbet@lwn.net, dhowells@redhat.com, jarkko@kernel.org, rostedt@goodmis.org, mingo@redhat.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, shuah@kernel.org Cc: 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 Subject: [PATCH v13 04/10] KEYS: Move KEY_LOOKUP_ to include/linux/key.h Date: Tue, 23 Aug 2022 17:00:29 +0200 Message-Id: <20220823150035.711534-5-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220823150035.711534-1-roberto.sassu@huaweicloud.com> References: <20220823150035.711534-1-roberto.sassu@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: GxC2BwBnIhqd6wRjjU5GAA--.52413S6 X-Coremail-Antispam: 1UD129KBjvJXoW7urW3JFWkJrWUXr1kZFW8Zwb_yoW8Cr1UpF WDCFyUKry8CFy7W3s3GFsFya1ak3y3Gr17XF9Igwn0gFsaq3y8Jrn7KF13uF13urWUua42 qr42ga15uw1DA3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBvb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6r1F6r1fM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWUJVWUCwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv6xkF7I0E 14v26r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrV C2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE 7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x02628vn2kIc2xKxwCF04k20x vY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I 3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2Ij64vIr41lIx AIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI 42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z2 80aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07UZo7tUUUUU= X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAQANBF1jj4I6SAACsL X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 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. 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 + +static inline int key_lookup_flags_check(u64 flags) +{ + if (flags & ~(KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL)) + return -EINVAL; + + return 0; +} + struct seq_file; struct user_struct; struct signal_struct; diff --git a/security/keys/internal.h b/security/keys/internal.h index 9b9cf3b6fcbb..3c1e7122076b 100644 --- a/security/keys/internal.h +++ b/security/keys/internal.h @@ -165,8 +165,6 @@ extern struct key *request_key_and_link(struct key_type *type, extern bool lookup_user_key_possessed(const struct key *key, const struct key_match_data *match_data); -#define KEY_LOOKUP_CREATE 0x01 -#define KEY_LOOKUP_PARTIAL 0x02 extern long join_session_keyring(const char *name); extern void key_change_session_keyring(struct callback_head *twork); -- 2.25.1