mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] fs/proc/proc_sysctl.c: always initialize i_uid/i_gid
@ 2024-03-22 19:51 ` Thomas Weißschuh
  2024-03-22 22:07   ` Kuniyuki Iwashima
  2024-03-28 20:42   ` Joel Granados
  0 siblings, 2 replies; 3+ messages in thread
From: Thomas Weißschuh @ 2024-03-22 19:51 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Dmitry Torokhov, Eric W. Biederman, Joel Granados
  Cc: netdev, linux-kernel, Luis Chamberlain, Kuniyuki Iwashima,
	stable, Thomas Weißschuh

Commit e79c6a4fc923 ("net: make net namespace sysctls belong to container's owner")
added default values for i_uid/i_gid.
These however are only used when ctl_table_root->set_ownership is not
implemented.
But the callbacks themselves could fail to compute i_uid/i_gid and they
all need to have the same fallback logic for this case.

This is unnecessary code duplication and prone to errors.
For example net_ctl_set_ownership() missed the fallback.

Instead always initialize i_uid/i_gid inside the sysfs core so
set_ownership() can safely skip setting them.

Fixes: e79c6a4fc923 ("net: make net namespace sysctls belong to container's owner")
Cc: stable@vger.kernel.org
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Changes in v2:
- Move the fallback logic to the sysctl core
- Link to v1: https://lore.kernel.org/r/20240315-sysctl-net-ownership-v1-1-2b465555a292@weissschuh.net
---
 fs/proc/proc_sysctl.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 37cde0efee57..9e34ab9c21e4 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -479,12 +479,10 @@ static struct inode *proc_sys_make_inode(struct super_block *sb,
 			make_empty_dir_inode(inode);
 	}
 
+	inode->i_uid = GLOBAL_ROOT_UID;
+	inode->i_gid = GLOBAL_ROOT_GID;
 	if (root->set_ownership)
 		root->set_ownership(head, table, &inode->i_uid, &inode->i_gid);
-	else {
-		inode->i_uid = GLOBAL_ROOT_UID;
-		inode->i_gid = GLOBAL_ROOT_GID;
-	}
 
 	return inode;
 }

---
base-commit: ff9c18e435b042596c9d48badac7488e3fa76a55
change-id: 20240315-sysctl-net-ownership-bc4e17eaeea6

Best regards,
-- 
Thomas Weißschuh <linux@weissschuh.net>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] fs/proc/proc_sysctl.c: always initialize i_uid/i_gid
  2024-03-22 19:51 ` [PATCH v2] fs/proc/proc_sysctl.c: always initialize i_uid/i_gid Thomas Weißschuh
@ 2024-03-22 22:07   ` Kuniyuki Iwashima
  2024-03-28 20:42   ` Joel Granados
  1 sibling, 0 replies; 3+ messages in thread
From: Kuniyuki Iwashima @ 2024-03-22 22:07 UTC (permalink / raw)
  To: linux
  Cc: davem, dmitry.torokhov, ebiederm, edumazet, j.granados, kuba,
	kuniyu, linux-kernel, mcgrof, netdev, pabeni, stable

From: "Thomas Weißschuh" <linux@weissschuh.net>
Date: Fri, 22 Mar 2024 20:51:11 +0100
> Commit e79c6a4fc923 ("net: make net namespace sysctls belong to container's owner")
> added default values for i_uid/i_gid.

The commit that added the default is 5ec27ec735ba ("fs/proc/proc_sysctl.c:
fix the default values of i_uid/i_gid on /proc/sys inodes.")


> These however are only used when ctl_table_root->set_ownership is not
> implemented.
> But the callbacks themselves could fail to compute i_uid/i_gid and they
> all need to have the same fallback logic for this case.
> 
> This is unnecessary code duplication and prone to errors.
> For example net_ctl_set_ownership() missed the fallback.
> 
> Instead always initialize i_uid/i_gid inside the sysfs core so
> set_ownership() can safely skip setting them.
> 
> Fixes: e79c6a4fc923 ("net: make net namespace sysctls belong to container's owner")
> Cc: stable@vger.kernel.org
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
> Changes in v2:
> - Move the fallback logic to the sysctl core
> - Link to v1: https://lore.kernel.org/r/20240315-sysctl-net-ownership-v1-1-2b465555a292@weissschuh.net
> ---
>  fs/proc/proc_sysctl.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
> index 37cde0efee57..9e34ab9c21e4 100644
> --- a/fs/proc/proc_sysctl.c
> +++ b/fs/proc/proc_sysctl.c
> @@ -479,12 +479,10 @@ static struct inode *proc_sys_make_inode(struct super_block *sb,
>  			make_empty_dir_inode(inode);
>  	}
>  
> +	inode->i_uid = GLOBAL_ROOT_UID;
> +	inode->i_gid = GLOBAL_ROOT_GID;
>  	if (root->set_ownership)
>  		root->set_ownership(head, table, &inode->i_uid, &inode->i_gid);
> -	else {
> -		inode->i_uid = GLOBAL_ROOT_UID;
> -		inode->i_gid = GLOBAL_ROOT_GID;
> -	}
>  
>  	return inode;
>  }
> 
> ---
> base-commit: ff9c18e435b042596c9d48badac7488e3fa76a55
> change-id: 20240315-sysctl-net-ownership-bc4e17eaeea6
> 
> Best regards,
> -- 
> Thomas Weißschuh <linux@weissschuh.net>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] fs/proc/proc_sysctl.c: always initialize i_uid/i_gid
  2024-03-22 19:51 ` [PATCH v2] fs/proc/proc_sysctl.c: always initialize i_uid/i_gid Thomas Weißschuh
  2024-03-22 22:07   ` Kuniyuki Iwashima
@ 2024-03-28 20:42   ` Joel Granados
  1 sibling, 0 replies; 3+ messages in thread
From: Joel Granados @ 2024-03-28 20:42 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Dmitry Torokhov, Eric W. Biederman, netdev, linux-kernel,
	Luis Chamberlain, Kuniyuki Iwashima, stable

[-- Attachment #1: Type: text/plain, Size: 2452 bytes --]

On Fri, Mar 22, 2024 at 08:51:11PM +0100, Thomas Weißschuh wrote:
> Commit e79c6a4fc923 ("net: make net namespace sysctls belong to container's owner")
> added default values for i_uid/i_gid.
> These however are only used when ctl_table_root->set_ownership is not
> implemented.
> But the callbacks themselves could fail to compute i_uid/i_gid and they
> all need to have the same fallback logic for this case.
All this text is related to commit e79c6a4fc923; which is not the one at
fault. I think mentioning e79c6a4fc923 here is incorrect. Please mention
5ec27ec735ba0 ("fs/proc/proc_sysctl.c: fix the default values of
i_uid/i_gid on /proc/sys inodes") and how it missed adjusting
net_ctl_set_ownership when it was committed.

> 
> This is unnecessary code duplication and prone to errors.
> For example net_ctl_set_ownership() missed the fallback.
This paragraph can be dropped

> 
> Instead always initialize i_uid/i_gid inside the sysfs core so
> set_ownership() can safely skip setting them.
> 
> Fixes: e79c6a4fc923 ("net: make net namespace sysctls belong to container's owner")
Why did you leave this? Do you disagree with my comment in
https://lore.kernel.org/all/20240319130716.vne4nhb3mbwtabfb@joelS2.panther.com/?

> Cc: stable@vger.kernel.org
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
> Changes in v2:
> - Move the fallback logic to the sysctl core
> - Link to v1: https://lore.kernel.org/r/20240315-sysctl-net-ownership-v1-1-2b465555a292@weissschuh.net
> ---
>  fs/proc/proc_sysctl.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
> index 37cde0efee57..9e34ab9c21e4 100644
> --- a/fs/proc/proc_sysctl.c
> +++ b/fs/proc/proc_sysctl.c
> @@ -479,12 +479,10 @@ static struct inode *proc_sys_make_inode(struct super_block *sb,
>  			make_empty_dir_inode(inode);
>  	}
>  
> +	inode->i_uid = GLOBAL_ROOT_UID;
> +	inode->i_gid = GLOBAL_ROOT_GID;
>  	if (root->set_ownership)
>  		root->set_ownership(head, table, &inode->i_uid, &inode->i_gid);
> -	else {
> -		inode->i_uid = GLOBAL_ROOT_UID;
> -		inode->i_gid = GLOBAL_ROOT_GID;
> -	}
>  
>  	return inode;
>  }
> 
> ---
> base-commit: ff9c18e435b042596c9d48badac7488e3fa76a55
Now that v6.9-rc1 is out, I would rebase your next version there.


The change looks good, but the commit message still needs work.
-- 

Joel Granados

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-28 20:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20240322195138eucas1p14ff532294e26ed63a400321066f03d98@eucas1p1.samsung.com>
2024-03-22 19:51 ` [PATCH v2] fs/proc/proc_sysctl.c: always initialize i_uid/i_gid Thomas Weißschuh
2024-03-22 22:07   ` Kuniyuki Iwashima
2024-03-28 20:42   ` Joel Granados

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®