Skip to contentSkip to conversation

dev_ioctl: fix the type of ifr_flags

PATCH NAK Atlas Yu 3 participants 6 messages Sep 11, 2024 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Atlas Yu

author
#0 lore raw

PATCH 1/1 dev_ioctl: fix the type of ifr_flags

SIOCxIFFAGS call dev_get_flags/dev_change_flags under the hood, which take a unsigned int flags instead of short. This mismatch makes it impossible to get/set IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO that are beyond 16 bits.

---
 include/uapi/linux/if.h | 2 +-
 net/core/dev_ioctl.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/uapi/linux/if.h +1 -1
index 797ba2c1562a..b612b6cd7446 100644
@@ -244,7 +244,7 @@ struct ifreq {
 		struct	sockaddr ifru_broadaddr;
 		struct	sockaddr ifru_netmask;
 		struct  sockaddr ifru_hwaddr;
-		short	ifru_flags;
+		unsigned int	ifru_flags;
 		int	ifru_ivalue;
 		int	ifru_mtu;
 		struct  ifmap ifru_map;
net/core/dev_ioctl.c +1 -1
index 8592c052c0f4..4b317561e503 100644
@@ -145,7 +145,7 @@ static int dev_ifsioc_locked(struct net *net, struct ifreq *ifr, unsigned int cm
 
 	switch (cmd) {
 	case SIOCGIFFLAGS:	/* Get interface flags */
-		ifr->ifr_flags = (short) dev_get_flags(dev);
+		ifr->ifr_flags = dev_get_flags(dev);
 		return 0;
 
 	case SIOCGIFMETRIC:	/* Get the metric on the interface
Signature · 1 line
2.43.0
#1 lore raw

include/uapi/linux/if.h struct ifreq { · line 250

Quoted 13 lines · On Wed, 11 Sep 2024 11:46:08 +0800 Atlas Yu <[email protected]> wrote:
include/uapi/linux/if.h +1 -1
index 797ba2c1562a..b612b6cd7446 100644
@@ -244,7 +244,7 @@ struct ifreq {
 		struct	sockaddr ifru_broadaddr;
 		struct	sockaddr ifru_netmask;
 		struct  sockaddr ifru_hwaddr;
-		short	ifru_flags;
+		unsigned int	ifru_flags;
 		int	ifru_ivalue;
 		int	ifru_mtu;
 		struct  ifmap ifru_map;

NAK
This breaks userspace ABI. There is no guarantee that older application correctly zeros the upper flag bits.

author
#2 lore raw
Quoted 11 lines · Stephen Hemminger
Quoted 9 lines · On Wed, 11 Sep 2024 11:46:08 +0800 Atlas Yu <[email protected]> wrote:
include/uapi/linux/if.h +0 -1
index 797ba2c1562a..b612b6cd7446 100644
@@ -244,7 +244,7 @@ struct ifreq {
              struct  sockaddr ifru_broadaddr;
              struct  sockaddr ifru_netmask;
              struct  sockaddr ifru_hwaddr;
-             short   ifru_flags;
Quoted 8 lines

include/uapi/linux/if.h struct ifreq { · line 250

Quoted 4 lines
include/uapi/linux/if.h +1 -0
+             unsigned int    ifru_flags;
              int     ifru_ivalue;
              int     ifru_mtu;
              struct  ifmap ifru_map;

NAK
This breaks userspace ABI. There is no guarantee that older application correctly zeros the upper flag bits.

Thanks, any suggestions though? How about introducing another ioctl request for these extended bits.

A message that is not in the archive (sent off-list or not yet received): CAB55eyUZ=D-vnQZNaNEvLu6gVp33OXvsjJMmdeMiYqVR1FJ2XQ@mail.gmail.com

#4 lore raw
Quoted 23 lines · On Wed, 11 Sep 2024 12:17:24 +0800 Atlas Yu <[email protected]> wrote:
Quoted 11 lines · Stephen Hemminger
Quoted 9 lines · On Wed, 11 Sep 2024 11:46:08 +0800 Atlas Yu <[email protected]> wrote:
include/uapi/linux/if.h +0 -1
index 797ba2c1562a..b612b6cd7446 100644
@@ -244,7 +244,7 @@ struct ifreq {
              struct  sockaddr ifru_broadaddr;
              struct  sockaddr ifru_netmask;
              struct  sockaddr ifru_hwaddr;
-             short   ifru_flags;
Quoted 8 lines

include/uapi/linux/if.h struct ifreq { · line 250

Quoted 4 lines
include/uapi/linux/if.h +1 -0
+             unsigned int    ifru_flags;
              int     ifru_ivalue;
              int     ifru_mtu;
              struct  ifmap ifru_map;  

NAK
This breaks userspace ABI. There is no guarantee that older application correctly zeros the upper flag bits.

Quoted 2 lines

Thanks, any suggestions though? How about introducing another ioctl request for these extended bits.

Doing anything with ioctl's is hard, there are so many layers to deal with. Mostly, networking has treated ioctl's as legacy API and switched to using netlink for any new features.

#5 lore raw
Quoted 27 lines · Stephen Hemminger
Quoted 23 lines · On Wed, 11 Sep 2024 12:17:24 +0800 Atlas Yu <[email protected]> wrote:
Quoted 19 lines · Stephen Hemminger

include/uapi/linux/if.h struct ifreq { · line 250

Quoted 13 lines · On Wed, 11 Sep 2024 11:46:08 +0800 Atlas Yu <[email protected]> wrote:
include/uapi/linux/if.h +1 -1
index 797ba2c1562a..b612b6cd7446 100644
@@ -244,7 +244,7 @@ struct ifreq {
              struct  sockaddr ifru_broadaddr;
              struct  sockaddr ifru_netmask;
              struct  sockaddr ifru_hwaddr;
-             short   ifru_flags;
+             unsigned int    ifru_flags;
              int     ifru_ivalue;
              int     ifru_mtu;
              struct  ifmap ifru_map;

NAK
This breaks userspace ABI. There is no guarantee that older application correctly zeros the upper flag bits.

Quoted 6 lines
Quoted 2 lines

Thanks, any suggestions though? How about introducing another ioctl request for these extended bits.

Doing anything with ioctl's is hard, there are so many layers to deal with. Mostly, networking has treated ioctl's as legacy API and switched to using netlink for any new features.

Note that rtnetlink gets the 32bit flags already, this has been the case for 20 years or more.

include/uapi/linux/rtnetlink.h:566:     unsigned        ifi_flags;
         /* IFF_* flags  */

net/core/rtnetlink.c : rtnl_fill_ifinfo(...)

ifm->ifi_flags = dev_get_flags(dev);

iproute2 also displays more than 16 bits in print_link_flags()

author
#6 lore raw
Quoted 6 lines

On Wed, Sep 11, 2024 at 3:21 PM
Eric Dumazet <[email protected]> wrote:

Note that rtnetlink gets the 32bit flags already, this has been the case for 20 years or more.

Quoted 8 lines
include/uapi/linux/rtnetlink.h:566:     unsigned        ifi_flags;
         /* IFF_* flags  */

net/core/rtnetlink.c : rtnl_fill_ifinfo(...)

ifm->ifi_flags = dev_get_flags(dev);

iproute2 also displays more than 16 bits in print_link_flags()

Thank you Eric, I am switching to the netlink API for my use case.