From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yx1-f44.google.com (mail-yx1-f44.google.com [74.125.224.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF972325490 for ; Fri, 8 May 2026 04:26:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778214379; cv=none; b=qEjX/yr4SexAjTyx+g0wU4S/hgWs1EavGgYNcE2/nGIUFcI8qpfjTc8GioACbbM7RO2GmWwmIwu69jJ/aNr9SBdhdzZWRqBvWXunUbSRt3bs4gI7YNTqzLjktl6ZDV2EHUbebWr5IpDHW+dmB3Km3BVO+sylv7sbr+ZAqwf05cM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778214379; c=relaxed/simple; bh=pxBjKwtEH2t2rn+xDWBjfjE1VUT5Fue6VYkz2vk17xk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bX6sYrrHAGWTh73ajB70FECxDvBnnUwSRpl1vx/S5HFNo1Jdgo0iE08F2Iyl0uVLDtKfwqzfSFDOBJUUdq/5iudqyQItniapkvvEmT8Q2tlJDhxzqqPC06QBoYYo3K0/s6tKlcF4KNO4jCMZ0ia5O2Ams9RW2kGmrFMYGri4AfQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Nm3pIcpF; arc=none smtp.client-ip=74.125.224.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Nm3pIcpF" Received: by mail-yx1-f44.google.com with SMTP id 956f58d0204a3-65c83b7e2deso189343d50.2 for ; Thu, 07 May 2026 21:26:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778214377; x=1778819177; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=25hLrp+L6VZJrpAv7whXxLsdCJndsgyfb3zsbcFNsUI=; b=Nm3pIcpFqH/shLz01KYBgOunUpEpYKzMVwJrWIv3+kEYOaRMbme7LyZUMuyeqAiYgS f/NrogqFScxuQfb6+5uyW1fThtKWM59XOzJAMG+AtGWo7b+Txx6RUbLXzblXj9MsQLBi DrP7/Sg1JzhhykrqIpCo0jnD7yZIVoE3sEIP5906eE4IpUFNGdJPIFba9yF0FxwL3pAh q/9EJNRQqLsBDixg7A6qgxVST1FQx8v4Fg2Ld1S6pLs9cqXbAZSeoNpr38S2lSMkApLd q/DdGqSHM8g6st3ZHAEQovplRTJN7Hl2ojRkbQH+ZQjt9yiu4mq+2b5d1xdl5cWfKxIy 5ljQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778214377; x=1778819177; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=25hLrp+L6VZJrpAv7whXxLsdCJndsgyfb3zsbcFNsUI=; b=N0PV5zg1UOvrSxZfxn4NJEo2rRvNSbLFJGflBsGsniiX4J6yfzm4YSDMIQPzqfHnDK TdX2bXKvUMEAEdqLzAc0bu/v4FYzeTk1IyBfNqH+z3nOYVo4k44ZbgO0aEiZrOMUyyqK i/h/q1OqoPVlBkbvpkbnMVbrZnA9s193MzZ09ePK2njPNlTLtXJ4rwWymcQRrFZY8Kbk HZqnEE4otKbtgSQgokeRYZCbCQqcw4FMrAvrJE+t15IF6udmRKaEzt0WLPqFftJwcBH3 hfgoPpIyfi3wVS7PrzGVvBtaSPnm3f8xQG8uhCbm443LpqHp2uufau1tOhUJnVf7ZZ5d I07A== X-Gm-Message-State: AOJu0Yw2n2CeTe+5E0cvI41YC6w6rembH5ZBq7hIiv/Vujfc16qpbC4E 4uTWCSgcfZNesJRTiMkaR92y8LWKkUyr5aTkJKe7jMPyfd65igmODvCaha6G4Q== X-Gm-Gg: Acq92OEs7g9unHTZROEvkzMCaF1as6TytnidB79VokGpeCqf4W9mYwDZ1bqohp7+uIC L3SYsCdX88O+NpUHWDaedtpMQ0XV5esVknkp/2WpsNv8jCzjg80Dm/d5N4kbN0wxYit18B9VBYJ 3ncceoTGkuf1e+Dt7H5EMxNIktW4QGLUZXanRmObY5/rS4D+SV6JsjAf3L7ZIA1LIptb68ak4Qq niayRHCyZAT7wRjU7gGJlj9S1+6x3YS0qfOdu14iaS72vxMHKoWVBmycrQZVwMLLutRFVwlVbIR OH07M25DO4kOviEKeNstiJxTjcnXI9RKhYjCtVCQCM3exOVWrdVMdTSxaN0DwnENkxR1MjFnj75 oxxe4eHT3LTk6kFob+7hCk4Am1bec9ziS09vvv1xWigA+yXqV38ehy1IlNe5V2obfqQP2kPNu2O rm/V/GmzRdBL0f0Gv5TXD9NYKi X-Received: by 2002:a05:690e:dc1:b0:654:a4fd:ebdb with SMTP id 956f58d0204a3-65c7b8a9c29mr6332106d50.3.1778214376659; Thu, 07 May 2026 21:26:16 -0700 (PDT) Received: from localhost ([2a03:2880:21ff:54::]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-65d96c07dadsm249350d50.18.2026.05.07.21.26.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 21:26:16 -0700 (PDT) From: Wei Wang To: netdev@vger.kernel.org, Jakub Kicinski , Daniel Zahka , Willem de Bruijn , David Wei , Andrew Lunn , "David S . Miller" , Eric Dumazet , Paolo Abeni , Simon Horman Cc: Wei Wang Subject: [PATCH v14 net-next 1/5] psp: add admin/non-admin version of psp_device_get_locked Date: Thu, 7 May 2026 21:26:06 -0700 Message-ID: <20260508042611.130945-2-weibunny.kernel@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260508042611.130945-1-weibunny.kernel@gmail.com> References: <20260508042611.130945-1-weibunny.kernel@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Wei Wang Introduce 2 versions of psp_device_get_locked: 1. psp_device_get_locked_admin(): This version is used for operations that would change the status of the psd, and are currently used for dev-set and key-rotation. 2. psp_device_get_locked(): This is the non-admin version, which are used for broader user issued operations including: dev-get, rx-assoc, tx-assoc, get-stats. Following commit will be implementing both of the checks. Signed-off-by: Wei Wang Reviewed-by: Daniel Zahka --- Documentation/netlink/specs/psp.yaml | 4 ++-- net/psp/psp-nl-gen.c | 4 ++-- net/psp/psp-nl-gen.h | 2 ++ net/psp/psp.h | 2 +- net/psp/psp_main.c | 7 +++++- net/psp/psp_nl.c | 33 ++++++++++++++++++++-------- 6 files changed, 37 insertions(+), 15 deletions(-) diff --git a/Documentation/netlink/specs/psp.yaml b/Documentation/netlink/specs/psp.yaml index bfcd6e4ecb85..e3b0fe296e8f 100644 --- a/Documentation/netlink/specs/psp.yaml +++ b/Documentation/netlink/specs/psp.yaml @@ -196,7 +196,7 @@ operations: - psp-versions-ena reply: attributes: [] - pre: psp-device-get-locked + pre: psp-device-get-locked-admin post: psp-device-unlock - name: dev-change-ntf @@ -216,7 +216,7 @@ operations: reply: attributes: - id - pre: psp-device-get-locked + pre: psp-device-get-locked-admin post: psp-device-unlock - name: key-rotate-ntf diff --git a/net/psp/psp-nl-gen.c b/net/psp/psp-nl-gen.c index 953309952cef..a71dd629aeab 100644 --- a/net/psp/psp-nl-gen.c +++ b/net/psp/psp-nl-gen.c @@ -71,7 +71,7 @@ static const struct genl_split_ops psp_nl_ops[] = { }, { .cmd = PSP_CMD_DEV_SET, - .pre_doit = psp_device_get_locked, + .pre_doit = psp_device_get_locked_admin, .doit = psp_nl_dev_set_doit, .post_doit = psp_device_unlock, .policy = psp_dev_set_nl_policy, @@ -80,7 +80,7 @@ static const struct genl_split_ops psp_nl_ops[] = { }, { .cmd = PSP_CMD_KEY_ROTATE, - .pre_doit = psp_device_get_locked, + .pre_doit = psp_device_get_locked_admin, .doit = psp_nl_key_rotate_doit, .post_doit = psp_device_unlock, .policy = psp_key_rotate_nl_policy, diff --git a/net/psp/psp-nl-gen.h b/net/psp/psp-nl-gen.h index 599c5f1c82f2..977355455395 100644 --- a/net/psp/psp-nl-gen.h +++ b/net/psp/psp-nl-gen.h @@ -17,6 +17,8 @@ extern const struct nla_policy psp_keys_nl_policy[PSP_A_KEYS_SPI + 1]; int psp_device_get_locked(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info); +int psp_device_get_locked_admin(const struct genl_split_ops *ops, + struct sk_buff *skb, struct genl_info *info); int psp_assoc_device_get_locked(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info); void diff --git a/net/psp/psp.h b/net/psp/psp.h index 9f19137593a0..0f9c4e4e52cb 100644 --- a/net/psp/psp.h +++ b/net/psp/psp.h @@ -14,7 +14,7 @@ extern struct xarray psp_devs; extern struct mutex psp_devs_lock; void psp_dev_free(struct psp_dev *psd); -int psp_dev_check_access(struct psp_dev *psd, struct net *net); +int psp_dev_check_access(struct psp_dev *psd, struct net *net, bool admin); void psp_nl_notify_dev(struct psp_dev *psd, u32 cmd); diff --git a/net/psp/psp_main.c b/net/psp/psp_main.c index ccbbb2a5fa58..aaa44e6cb9ff 100644 --- a/net/psp/psp_main.c +++ b/net/psp/psp_main.c @@ -27,10 +27,15 @@ struct mutex psp_devs_lock; * psp_dev_check_access() - check if user in a given net ns can access PSP dev * @psd: PSP device structure user is trying to access * @net: net namespace user is in + * @admin: If true, only allow access from @psd's main device's netns, + * for admin operations like config changes and key rotation. + * If false, also allow access from network namespaces that have + * an associated device with @psd, for read-only and association + * management operations. * * Return: 0 if PSP device should be visible in @net, errno otherwise. */ -int psp_dev_check_access(struct psp_dev *psd, struct net *net) +int psp_dev_check_access(struct psp_dev *psd, struct net *net, bool admin) { if (dev_net(psd->main_netdev) == net) return 0; diff --git a/net/psp/psp_nl.c b/net/psp/psp_nl.c index 0cc744a6e1c9..b4f1b7f9b0c2 100644 --- a/net/psp/psp_nl.c +++ b/net/psp/psp_nl.c @@ -41,7 +41,8 @@ static int psp_nl_reply_send(struct sk_buff *rsp, struct genl_info *info) /* Device stuff */ static struct psp_dev * -psp_device_get_and_lock(struct net *net, struct nlattr *dev_id) +psp_device_get_and_lock(struct net *net, struct nlattr *dev_id, + bool admin) { struct psp_dev *psd; int err; @@ -56,7 +57,7 @@ psp_device_get_and_lock(struct net *net, struct nlattr *dev_id) mutex_lock(&psd->lock); mutex_unlock(&psp_devs_lock); - err = psp_dev_check_access(psd, net); + err = psp_dev_check_access(psd, net, admin); if (err) { mutex_unlock(&psd->lock); return ERR_PTR(err); @@ -65,17 +66,31 @@ psp_device_get_and_lock(struct net *net, struct nlattr *dev_id) return psd; } -int psp_device_get_locked(const struct genl_split_ops *ops, - struct sk_buff *skb, struct genl_info *info) +static int __psp_device_get_locked(const struct genl_split_ops *ops, + struct sk_buff *skb, struct genl_info *info, + bool admin) { if (GENL_REQ_ATTR_CHECK(info, PSP_A_DEV_ID)) return -EINVAL; info->user_ptr[0] = psp_device_get_and_lock(genl_info_net(info), - info->attrs[PSP_A_DEV_ID]); + info->attrs[PSP_A_DEV_ID], + admin); return PTR_ERR_OR_ZERO(info->user_ptr[0]); } +int psp_device_get_locked_admin(const struct genl_split_ops *ops, + struct sk_buff *skb, struct genl_info *info) +{ + return __psp_device_get_locked(ops, skb, info, true); +} + +int psp_device_get_locked(const struct genl_split_ops *ops, + struct sk_buff *skb, struct genl_info *info) +{ + return __psp_device_get_locked(ops, skb, info, false); +} + void psp_device_unlock(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info) @@ -160,7 +175,7 @@ static int psp_nl_dev_get_dumpit_one(struct sk_buff *rsp, struct netlink_callback *cb, struct psp_dev *psd) { - if (psp_dev_check_access(psd, sock_net(rsp->sk))) + if (psp_dev_check_access(psd, sock_net(rsp->sk), false)) return 0; return psp_nl_dev_fill(psd, rsp, genl_info_dump(cb)); @@ -310,7 +325,7 @@ int psp_assoc_device_get_locked(const struct genl_split_ops *ops, */ mutex_lock(&psd->lock); if (!psp_dev_is_registered(psd) || - psp_dev_check_access(psd, genl_info_net(info))) { + psp_dev_check_access(psd, genl_info_net(info), false)) { mutex_unlock(&psd->lock); psp_dev_put(psd); psd = NULL; @@ -334,7 +349,7 @@ int psp_assoc_device_get_locked(const struct genl_split_ops *ops, psp_dev_put(psd); } else { - psd = psp_device_get_and_lock(genl_info_net(info), id); + psd = psp_device_get_and_lock(genl_info_net(info), id, false); if (IS_ERR(psd)) { err = PTR_ERR(psd); goto err_sock_put; @@ -577,7 +592,7 @@ static int psp_nl_stats_get_dumpit_one(struct sk_buff *rsp, struct netlink_callback *cb, struct psp_dev *psd) { - if (psp_dev_check_access(psd, sock_net(rsp->sk))) + if (psp_dev_check_access(psd, sock_net(rsp->sk), false)) return 0; return psp_nl_stats_fill(psd, rsp, genl_info_dump(cb)); -- 2.52.0