diff mbox series

[net] net-sysfs: initialize uid and gid before calling net_ns_get_ownership

Message ID a1d7fda6a8e54a766fc9922e3abec8411120c3ac.1635143508.git.lucien.xin@gmail.com (mailing list archive)
State Accepted
Commit f7a1e76d0f608961cc2fc681f867a834f2746bce
Delegated to: Netdev Maintainers
Headers show
Series [net] net-sysfs: initialize uid and gid before calling net_ns_get_ownership | expand

Checks

Context Check Description
netdev/cover_letter success Single patches do not need cover letters
netdev/fixes_present success Fixes tag present in non-next series
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net
netdev/subject_prefix success Link
netdev/cc_maintainers warning 3 maintainers not CCed: alexanderduyck@fb.com weiwan@google.com atenart@kernel.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Fixes tag looks correct
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 11 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 1 this patch: 1
netdev/header_inline success No static functions without inline keyword in header files

Commit Message

Xin Long Oct. 25, 2021, 6:31 a.m. UTC
Currently in net_ns_get_ownership() it may not be able to set uid or gid
if make_kuid or make_kgid returns an invalid value, and an uninit-value
issue can be triggered by this.

This patch is to fix it by initializing the uid and gid before calling
net_ns_get_ownership(), as it does in kobject_get_ownership()

Fixes: e6dee9f3893c ("net-sysfs: add netdev_change_owner()")
Reported-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/core/net-sysfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Christian Brauner Oct. 25, 2021, 8:46 a.m. UTC | #1
On Mon, Oct 25, 2021 at 02:31:48AM -0400, Xin Long wrote:
> Currently in net_ns_get_ownership() it may not be able to set uid or gid
> if make_kuid or make_kgid returns an invalid value, and an uninit-value
> issue can be triggered by this.
> 
> This patch is to fix it by initializing the uid and gid before calling
> net_ns_get_ownership(), as it does in kobject_get_ownership()
> 
> Fixes: e6dee9f3893c ("net-sysfs: add netdev_change_owner()")
> Reported-by: Paolo Abeni <pabeni@redhat.com>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> ---

Looks good,
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
patchwork-bot+netdevbpf@kernel.org Oct. 25, 2021, 3:20 p.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:

On Mon, 25 Oct 2021 02:31:48 -0400 you wrote:
> Currently in net_ns_get_ownership() it may not be able to set uid or gid
> if make_kuid or make_kgid returns an invalid value, and an uninit-value
> issue can be triggered by this.
> 
> This patch is to fix it by initializing the uid and gid before calling
> net_ns_get_ownership(), as it does in kobject_get_ownership()
> 
> [...]

Here is the summary with links:
  - [net] net-sysfs: initialize uid and gid before calling net_ns_get_ownership
    https://git.kernel.org/netdev/net/c/f7a1e76d0f60

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index f6197774048b..b2e49eb7001d 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -1973,9 +1973,9 @@  int netdev_register_kobject(struct net_device *ndev)
 int netdev_change_owner(struct net_device *ndev, const struct net *net_old,
 			const struct net *net_new)
 {
+	kuid_t old_uid = GLOBAL_ROOT_UID, new_uid = GLOBAL_ROOT_UID;
+	kgid_t old_gid = GLOBAL_ROOT_GID, new_gid = GLOBAL_ROOT_GID;
 	struct device *dev = &ndev->dev;
-	kuid_t old_uid, new_uid;
-	kgid_t old_gid, new_gid;
 	int error;
 
 	net_ns_get_ownership(net_old, &old_uid, &old_gid);