lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Mon, 26 Jun 2023 09:16:42 -0700
From: Kuniyuki Iwashima <kuniyu@...zon.com>
To: <edumazet@...gle.com>
CC: <davem@...emloft.net>, <kuba@...nel.org>, <kuni1840@...il.com>,
	<kuniyu@...zon.com>, <netdev@...r.kernel.org>, <pabeni@...hat.com>,
	<syzbot+5da61cf6a9bc1902d422@...kaller.appspotmail.com>
Subject: Re: [PATCH v1 net] netlink: Add sock_i_ino_irqsaved() for __netlink_diag_dump().

From: Eric Dumazet <edumazet@...gle.com>
Date: Mon, 26 Jun 2023 09:21:30 +0200
> On Sun, Jun 25, 2023 at 6:14 PM Kuniyuki Iwashima <kuniyu@...zon.com> wrote:
> >
> > syzbot reported a warning in __local_bh_enable_ip(). [0]
> >
> > Commit 8d61f926d420 ("netlink: fix potential deadlock in
> > netlink_set_err()") converted read_lock(&nl_table_lock) to
> > read_lock_irqsave() in __netlink_diag_dump() to prevent a deadlock.
> >
> > However, __netlink_diag_dump() calls sock_i_ino() that uses
> > read_lock_bh() and read_unlock_bh().  read_unlock_bh() finally
> > enables BH even though it should stay disabled until the following
> > read_unlock_irqrestore().
> >
> > Using read_lock() in sock_i_ino() would trigger a lockdep splat
> > in another place that was fixed in commit f064af1e500a ("net: fix
> > a lockdep splat"), so let's add another function that would be safe
> > to use under BH disabled.
> >
> > [0]:
> >
> > Fixes: 8d61f926d420 ("netlink: fix potential deadlock in netlink_set_err()")
> > Reported-by: syzbot+5da61cf6a9bc1902d422@...kaller.appspotmail.com
> > Closes: https://syzkaller.appspot.com/bug?extid=5da61cf6a9bc1902d422
> > Signed-off-by: Kuniyuki Iwashima <kuniyu@...zon.com>
> > ---
> >
> 
> Hi Kuniyuki, thanks for the fix, I mistakenly released this syzbot
> bug/report the other day ;)
> 
> I wonder if we could use __sock_i_ino() instead of sock_i_ino_bh_disabled(),
> and perhaps something like the following to have less copy/pasted code ?

Ah, that's much cleaner and nice name :)
Will post v2 with the diff.

Thanks, Eric!


> 
> diff --git a/net/core/sock.c b/net/core/sock.c
> index 6e5662ca00fe5638881db11c71c46169d59a2746..146a83c50c5d329fee2e833c4f2ba29e896d7766
> 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -2550,13 +2550,25 @@ kuid_t sock_i_uid(struct sock *sk)
>  }
>  EXPORT_SYMBOL(sock_i_uid);
> 
> -unsigned long sock_i_ino(struct sock *sk)
> +/* Must be called while interrupts are disabled. */
> +unsigned long __sock_i_ino(struct sock *sk)
>  {
>         unsigned long ino;
> 
> -       read_lock_bh(&sk->sk_callback_lock);
> +       read_lock(&sk->sk_callback_lock);
>         ino = sk->sk_socket ? SOCK_INODE(sk->sk_socket)->i_ino : 0;
> -       read_unlock_bh(&sk->sk_callback_lock);
> +       read_unlock(&sk->sk_callback_lock);
> +       return ino;
> +}
> +EXPORT_SYMBOL(__sock_i_ino);
> +
> +unsigned long sock_i_ino(struct sock *sk)
> +{
> +       unsigned long ino;
> +
> +       local_bh_disable();
> +       ino = __sock_i_ino(sk);
> +       local_bh_enable();
>         return ino;
>  }
>  EXPORT_SYMBOL(sock_i_ino);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ