diff mbox series

[net] ipv4: Fix address dump when IPv4 is disabled on an interface

Message ID 20240523110257.334315-1-idosch@nvidia.com (mailing list archive)
State Accepted
Commit 7b05ab85e28f615e70520d24c075249b4512044e
Delegated to: Netdev Maintainers
Headers show
Series [net] ipv4: Fix address dump when IPv4 is disabled on an interface | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 907 this patch: 907
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 909 this patch: 909
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 911 this patch: 911
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 13 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 1 this patch: 1
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-05-23--12-00 (tests: 1038)

Commit Message

Ido Schimmel May 23, 2024, 11:02 a.m. UTC
Cited commit started returning an error when user space requests to dump
the interface's IPv4 addresses and IPv4 is disabled on the interface.
Restore the previous behavior and do not return an error.

Before cited commit:

 # ip address show dev dummy1
 10: dummy1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
     link/ether e2:40:68:98:d0:18 brd ff:ff:ff:ff:ff:ff
     inet6 fe80::e040:68ff:fe98:d018/64 scope link proto kernel_ll
        valid_lft forever preferred_lft forever
 # ip link set dev dummy1 mtu 67
 # ip address show dev dummy1
 10: dummy1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 67 qdisc noqueue state UNKNOWN group default qlen 1000
     link/ether e2:40:68:98:d0:18 brd ff:ff:ff:ff:ff:ff

After cited commit:

 # ip address show dev dummy1
 10: dummy1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
     link/ether 32:2d:69:f2:9c:99 brd ff:ff:ff:ff:ff:ff
     inet6 fe80::302d:69ff:fef2:9c99/64 scope link proto kernel_ll
        valid_lft forever preferred_lft forever
 # ip link set dev dummy1 mtu 67
 # ip address show dev dummy1
 RTNETLINK answers: No such device
 Dump terminated

With this patch:

 # ip address show dev dummy1
 10: dummy1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
     link/ether de:17:56:bb:57:c0 brd ff:ff:ff:ff:ff:ff
     inet6 fe80::dc17:56ff:febb:57c0/64 scope link proto kernel_ll
        valid_lft forever preferred_lft forever
 # ip link set dev dummy1 mtu 67
 # ip address show dev dummy1
 10: dummy1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 67 qdisc noqueue state UNKNOWN group default qlen 1000
     link/ether de:17:56:bb:57:c0 brd ff:ff:ff:ff:ff:ff

I fixed the exact same issue for IPv6 in commit c04f7dfe6ec2 ("ipv6: Fix
address dump when IPv6 is disabled on an interface"), but noted [1] that
I am not doing the change for IPv4 because I am not aware of a way to
disable IPv4 on an interface other than unregistering it. I clearly
missed the above case.

[1] https://lore.kernel.org/netdev/20240321173042.2151756-1-idosch@nvidia.com/

Fixes: cdb2f80f1c10 ("inet: use xa_array iterator to implement inet_dump_ifaddr()")
Reported-by: Carolina Jubran <cjubran@nvidia.com>
Reported-by: Yamen Safadi <ysafadi@nvidia.com>
Tested-by: Carolina Jubran <cjubran@nvidia.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
 net/ipv4/devinet.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Eric Dumazet May 23, 2024, 1:28 p.m. UTC | #1
On Thu, May 23, 2024 at 1:04 PM Ido Schimmel <idosch@nvidia.com> wrote:
>
> Cited commit started returning an error when user space requests to dump
> the interface's IPv4 addresses and IPv4 is disabled on the interface.
> Restore the previous behavior and do not return an error.
>
> Before cited commit:
>
>  # ip address show dev dummy1
>  10: dummy1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
>      link/ether e2:40:68:98:d0:18 brd ff:ff:ff:ff:ff:ff
>      inet6 fe80::e040:68ff:fe98:d018/64 scope link proto kernel_ll
>         valid_lft forever preferred_lft forever
>  # ip link set dev dummy1 mtu 67
>  # ip address show dev dummy1
>  10: dummy1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 67 qdisc noqueue state UNKNOWN group default qlen 1000
>      link/ether e2:40:68:98:d0:18 brd ff:ff:ff:ff:ff:ff
>
> After cited commit:
>
>  # ip address show dev dummy1
>  10: dummy1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
>      link/ether 32:2d:69:f2:9c:99 brd ff:ff:ff:ff:ff:ff
>      inet6 fe80::302d:69ff:fef2:9c99/64 scope link proto kernel_ll
>         valid_lft forever preferred_lft forever
>  # ip link set dev dummy1 mtu 67
>  # ip address show dev dummy1
>  RTNETLINK answers: No such device
>  Dump terminated
>
> With this patch:
>
>  # ip address show dev dummy1
>  10: dummy1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
>      link/ether de:17:56:bb:57:c0 brd ff:ff:ff:ff:ff:ff
>      inet6 fe80::dc17:56ff:febb:57c0/64 scope link proto kernel_ll
>         valid_lft forever preferred_lft forever
>  # ip link set dev dummy1 mtu 67
>  # ip address show dev dummy1
>  10: dummy1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 67 qdisc noqueue state UNKNOWN group default qlen 1000
>      link/ether de:17:56:bb:57:c0 brd ff:ff:ff:ff:ff:ff
>
> I fixed the exact same issue for IPv6 in commit c04f7dfe6ec2 ("ipv6: Fix
> address dump when IPv6 is disabled on an interface"), but noted [1] that
> I am not doing the change for IPv4 because I am not aware of a way to
> disable IPv4 on an interface other than unregistering it. I clearly
> missed the above case.
>
> [1] https://lore.kernel.org/netdev/20240321173042.2151756-1-idosch@nvidia.com/
>
> Fixes: cdb2f80f1c10 ("inet: use xa_array iterator to implement inet_dump_ifaddr()")
> Reported-by: Carolina Jubran <cjubran@nvidia.com>
> Reported-by: Yamen Safadi <ysafadi@nvidia.com>
> Tested-by: Carolina Jubran <cjubran@nvidia.com>
> Reviewed-by: Petr Machata <petrm@nvidia.com>
> Signed-off-by: Ido Schimmel <idosch@nvidia.com>
> ---

Reviewed-by: Eric Dumazet <edumazet@google.com>

Thanks !
David Ahern May 23, 2024, 10:04 p.m. UTC | #2
On 5/23/24 5:02 AM, Ido Schimmel wrote:
> Cited commit started returning an error when user space requests to dump
> the interface's IPv4 addresses and IPv4 is disabled on the interface.
> Restore the previous behavior and do not return an error.
> 
> Before cited commit:
> 
>  # ip address show dev dummy1
>  10: dummy1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
>      link/ether e2:40:68:98:d0:18 brd ff:ff:ff:ff:ff:ff
>      inet6 fe80::e040:68ff:fe98:d018/64 scope link proto kernel_ll
>         valid_lft forever preferred_lft forever
>  # ip link set dev dummy1 mtu 67
>  # ip address show dev dummy1
>  10: dummy1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 67 qdisc noqueue state UNKNOWN group default qlen 1000
>      link/ether e2:40:68:98:d0:18 brd ff:ff:ff:ff:ff:ff
> 
> After cited commit:
> 
>  # ip address show dev dummy1
>  10: dummy1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
>      link/ether 32:2d:69:f2:9c:99 brd ff:ff:ff:ff:ff:ff
>      inet6 fe80::302d:69ff:fef2:9c99/64 scope link proto kernel_ll
>         valid_lft forever preferred_lft forever
>  # ip link set dev dummy1 mtu 67
>  # ip address show dev dummy1
>  RTNETLINK answers: No such device
>  Dump terminated
> 
> With this patch:
> 
>  # ip address show dev dummy1
>  10: dummy1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
>      link/ether de:17:56:bb:57:c0 brd ff:ff:ff:ff:ff:ff
>      inet6 fe80::dc17:56ff:febb:57c0/64 scope link proto kernel_ll
>         valid_lft forever preferred_lft forever
>  # ip link set dev dummy1 mtu 67
>  # ip address show dev dummy1
>  10: dummy1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 67 qdisc noqueue state UNKNOWN group default qlen 1000
>      link/ether de:17:56:bb:57:c0 brd ff:ff:ff:ff:ff:ff
> 
> I fixed the exact same issue for IPv6 in commit c04f7dfe6ec2 ("ipv6: Fix
> address dump when IPv6 is disabled on an interface"), but noted [1] that
> I am not doing the change for IPv4 because I am not aware of a way to
> disable IPv4 on an interface other than unregistering it. I clearly
> missed the above case.
> 
> [1] https://lore.kernel.org/netdev/20240321173042.2151756-1-idosch@nvidia.com/
> 
> Fixes: cdb2f80f1c10 ("inet: use xa_array iterator to implement inet_dump_ifaddr()")
> Reported-by: Carolina Jubran <cjubran@nvidia.com>
> Reported-by: Yamen Safadi <ysafadi@nvidia.com>
> Tested-by: Carolina Jubran <cjubran@nvidia.com>
> Reviewed-by: Petr Machata <petrm@nvidia.com>
> Signed-off-by: Ido Schimmel <idosch@nvidia.com>
> ---
>  net/ipv4/devinet.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 

Reviewed-by: David Ahern <dsahern@kernel.org>
patchwork-bot+netdevbpf@kernel.org May 28, 2024, midnight UTC | #3
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 23 May 2024 14:02:57 +0300 you wrote:
> Cited commit started returning an error when user space requests to dump
> the interface's IPv4 addresses and IPv4 is disabled on the interface.
> Restore the previous behavior and do not return an error.
> 
> Before cited commit:
> 
>  # ip address show dev dummy1
>  10: dummy1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
>      link/ether e2:40:68:98:d0:18 brd ff:ff:ff:ff:ff:ff
>      inet6 fe80::e040:68ff:fe98:d018/64 scope link proto kernel_ll
>         valid_lft forever preferred_lft forever
>  # ip link set dev dummy1 mtu 67
>  # ip address show dev dummy1
>  10: dummy1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 67 qdisc noqueue state UNKNOWN group default qlen 1000
>      link/ether e2:40:68:98:d0:18 brd ff:ff:ff:ff:ff:ff
> 
> [...]

Here is the summary with links:
  - [net] ipv4: Fix address dump when IPv4 is disabled on an interface
    https://git.kernel.org/netdev/net/c/7b05ab85e28f

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 96accde527da..e827da128c5f 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1887,10 +1887,11 @@  static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
 			goto done;
 
 		if (fillargs.ifindex) {
-			err = -ENODEV;
 			dev = dev_get_by_index_rcu(tgt_net, fillargs.ifindex);
-			if (!dev)
+			if (!dev) {
+				err = -ENODEV;
 				goto done;
+			}
 			in_dev = __in_dev_get_rcu(dev);
 			if (!in_dev)
 				goto done;