Skip to contentSkip to conversation

inet_diag: fix inet_diag_msg_attrs_fill() for net_cls cgroup

PATCH In review Patryk Sondej 3 participants 5 messages May 8, 2023 – May 9, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 inet_diag: fix inet_diag_msg_attrs_fill() for net_cls cgroup

This commit fixes inet_diag_msg_attrs_fill() function in the ipv4/inet_diag.c file. The problem was that the function was using CONFIG_SOCK_CGROUP_DATA to check for the net_cls cgroup. However, the net_cls cgroup is defined by CONFIG_CGROUP_NET_CLASSID instead.

Therefore, this commit updates the #ifdef statement to CONFIG_CGROUP_NET_CLASSID, and uses the sock_cgroup_classid() function to retrieve the classid from the socket cgroup.

This change ensures that the function correctly retrieves the classid for the net_cls cgroup and fixes any issues related to the use of the function in this context.

---
 net/ipv4/inet_diag.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/inet_diag.c +1 -1
index b812eb36f0e3..7017f88911a6 100644
@@ -157,7 +157,7 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
 	    ext & (1 << (INET_DIAG_TCLASS - 1))) {
 		u32 classid = 0;
 
-#ifdef CONFIG_SOCK_CGROUP_DATA
+#ifdef CONFIG_CGROUP_NET_CLASSID
 		classid = sock_cgroup_classid(&sk->sk_cgrp_data);
 #endif
 		/* Fallback to socket priority if class id isn't set.
Signature · 1 line
2.37.1 (Apple Git-137.1)
#1 lore raw
Quoted 10 lines · Patryk Sondej

This commit fixes inet_diag_msg_attrs_fill() function in the ipv4/inet_diag.c file. The problem was that the function was using CONFIG_SOCK_CGROUP_DATA to check for the net_cls cgroup. However, the net_cls cgroup is defined by CONFIG_CGROUP_NET_CLASSID instead.

Therefore, this commit updates the #ifdef statement to CONFIG_CGROUP_NET_CLASSID, and uses the sock_cgroup_classid() function to retrieve the classid from the socket cgroup.

This change ensures that the function correctly retrieves the classid for the net_cls cgroup and fixes any issues related to the use of the function in this context.

Please add Fixes line here.

Quoted 10 lines
---
 net/ipv4/inet_diag.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/inet_diag.c +0 -0
index b812eb36f0e3..7017f88911a6 100644

net/ipv4/inet_diag.c int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb, · line 160

Quoted 5 lines
net/ipv4/inet_diag.c +1 -1
@@ -157,7 +157,7 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
 	    ext & (1 << (INET_DIAG_TCLASS - 1))) {
 		u32 classid = 0;
 
-#ifdef CONFIG_SOCK_CGROUP_DATA
+#ifdef CONFIG_CGROUP_NET_CLASSID

This ifdef should be deleted as sock_cgroup_classid() already has right ifdef.

  809 static inline u32 sock_cgroup_classid(const struct sock_cgroup_data *skcd)
  810 {
  811 #ifdef CONFIG_CGROUP_NET_CLASSID
  812         return READ_ONCE(skcd->classid);
  813 #else
  814         return 0;
  815 #endif
  816 }
  817
Quoted 7 lines
net/ipv4/inet_diag.c +0 -0
 		classid = sock_cgroup_classid(&sk->sk_cgrp_data);
 #endif
 		/* Fallback to socket priority if class id isn't set.
Signature · 1 line
2.37.1 (Apple Git-137.1)
#2 lore raw

From: Leon Romanovsky <[email protected]>
Date: Mon, 8 May 2023 09:17:49 +0300

Quoted 27 lines · Patryk Sondej
Quoted 10 lines

This commit fixes inet_diag_msg_attrs_fill() function in the ipv4/inet_diag.c file. The problem was that the function was using CONFIG_SOCK_CGROUP_DATA to check for the net_cls cgroup. However, the net_cls cgroup is defined by CONFIG_CGROUP_NET_CLASSID instead.

Therefore, this commit updates the #ifdef statement to CONFIG_CGROUP_NET_CLASSID, and uses the sock_cgroup_classid() function to retrieve the classid from the socket cgroup.

This change ensures that the function correctly retrieves the classid for the net_cls cgroup and fixes any issues related to the use of the function in this context.

Please add Fixes line here.

Quoted 13 lines
---
 net/ipv4/inet_diag.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/inet_diag.c +0 -0
index b812eb36f0e3..7017f88911a6 100644
@@ -157,7 +157,7 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
 	    ext & (1 << (INET_DIAG_TCLASS - 1))) {
 		u32 classid = 0;
 
Quoted 4 lines

net/ipv4/inet_diag.c int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb, · line 160

Quoted 2 lines
net/ipv4/inet_diag.c +1 -1
-#ifdef CONFIG_SOCK_CGROUP_DATA
+#ifdef CONFIG_CGROUP_NET_CLASSID

This ifdef should be deleted as sock_cgroup_classid() already has right ifdef.

sock_cgroup_classid() is defined under #ifdef CONFIG_SOCK_CGROUP_DATA, so removing this guard will cause an error at compile time if we disable CONFIG_SOCK_CGROUP_DATA.

I think we can keep the old #ifdef as is for consistensy with another CONFIG_SOCK_CGROUP_DATA use just below for sock_cgroup_ptr() in inet_diag_msg_attrs_fill().

If we enable CONFIG_SOCK_CGROUP_DATA without CONFIG_CGROUP_NET_CLASSID, I guess gcc will optimize it and remove the zero assignment.

Quoted 17 lines
  809 static inline u32 sock_cgroup_classid(const struct sock_cgroup_data *skcd)
  810 {
  811 #ifdef CONFIG_CGROUP_NET_CLASSID
  812         return READ_ONCE(skcd->classid);
  813 #else
  814         return 0;
  815 #endif
  816 }
  817
Quoted 5 lines
net/ipv4/inet_diag.c +0 -0
 		classid = sock_cgroup_classid(&sk->sk_cgrp_data);
 #endif
 		/* Fallback to socket priority if class id isn't set.
Signature · 1 line
2.37.1 (Apple Git-137.1)
#3 lore raw
Quoted 29 lines · Kuniyuki Iwashima

From: Leon Romanovsky <[email protected]>
Date: Mon, 8 May 2023 09:17:49 +0300

Quoted 27 lines · Patryk Sondej
Quoted 10 lines

This commit fixes inet_diag_msg_attrs_fill() function in the ipv4/inet_diag.c file. The problem was that the function was using CONFIG_SOCK_CGROUP_DATA to check for the net_cls cgroup. However, the net_cls cgroup is defined by CONFIG_CGROUP_NET_CLASSID instead.

Therefore, this commit updates the #ifdef statement to CONFIG_CGROUP_NET_CLASSID, and uses the sock_cgroup_classid() function to retrieve the classid from the socket cgroup.

This change ensures that the function correctly retrieves the classid for the net_cls cgroup and fixes any issues related to the use of the function in this context.

Please add Fixes line here.

Quoted 13 lines
---
 net/ipv4/inet_diag.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/inet_diag.c +0 -0
index b812eb36f0e3..7017f88911a6 100644
@@ -157,7 +157,7 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
 	    ext & (1 << (INET_DIAG_TCLASS - 1))) {
 		u32 classid = 0;
 
Quoted 6 lines
Quoted 4 lines

net/ipv4/inet_diag.c int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb, · line 160

Quoted 2 lines
net/ipv4/inet_diag.c +1 -1
-#ifdef CONFIG_SOCK_CGROUP_DATA
+#ifdef CONFIG_CGROUP_NET_CLASSID

This ifdef should be deleted as sock_cgroup_classid() already has right ifdef.

sock_cgroup_classid() is defined under #ifdef CONFIG_SOCK_CGROUP_DATA,

Not in my kernel tree, where do you see it?

https://elixir.bootlin.com/linux/v6.4-rc1/source/include/linux/cgroup-defs.h#L809
include/linux/cgroup-defs.h
809 static inline u32 sock_cgroup_classid(const struct sock_cgroup_data *skcd) 810 {
811 #ifdef CONFIG_CGROUP_NET_CLASSID
812 return READ_ONCE(skcd->classid);
813 #else
814 return 0;
815 #endif
816 }

Thanks

#4 lore raw
Quoted 30 lines · Leon Romanovsky
Quoted 29 lines · Kuniyuki Iwashima

From: Leon Romanovsky <[email protected]>
Date: Mon, 8 May 2023 09:17:49 +0300

Quoted 27 lines · Patryk Sondej
Quoted 10 lines

This commit fixes inet_diag_msg_attrs_fill() function in the ipv4/inet_diag.c file. The problem was that the function was using CONFIG_SOCK_CGROUP_DATA to check for the net_cls cgroup. However, the net_cls cgroup is defined by CONFIG_CGROUP_NET_CLASSID instead.

Therefore, this commit updates the #ifdef statement to CONFIG_CGROUP_NET_CLASSID, and uses the sock_cgroup_classid() function to retrieve the classid from the socket cgroup.

This change ensures that the function correctly retrieves the classid for the net_cls cgroup and fixes any issues related to the use of the function in this context.

Please add Fixes line here.

Quoted 13 lines
---
 net/ipv4/inet_diag.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/inet_diag.c +0 -0
index b812eb36f0e3..7017f88911a6 100644
@@ -157,7 +157,7 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
 	    ext & (1 << (INET_DIAG_TCLASS - 1))) {
 		u32 classid = 0;
 
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

net/ipv4/inet_diag.c int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb, · line 160

Quoted 2 lines
net/ipv4/inet_diag.c +1 -1
-#ifdef CONFIG_SOCK_CGROUP_DATA
+#ifdef CONFIG_CGROUP_NET_CLASSID

This ifdef should be deleted as sock_cgroup_classid() already has right ifdef.

sock_cgroup_classid() is defined under #ifdef CONFIG_SOCK_CGROUP_DATA,

Not in my kernel tree, where do you see it?

Ohh, I'm sorry, I found it.

Yes, I agree with you this patch is not needed at the end.

Thanks