2018-01-04 06:58:05

by syzbot

[permalink] [raw]
Subject: possible deadlock in ppp_dev_uninit

Hello,

syzkaller hit the following crash on
73005e1a35fd67c644b0645c9e4c1efabd0fe62c
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/master
compiler: gcc (GCC) 7.1.1 20170620
.config is attached
Raw console output is attached.
C reproducer is attached
syzkaller reproducer is attached. See https://goo.gl/kgGztJ
for information about syzkaller reproducers


IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: [email protected]
It will help syzbot understand when the bug is fixed. See footer for
details.
If you forward the report, please keep this part and the footer.

RBP: 0000000000000004 R08: 0000000000000001 R09: 0000000000000035
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000401f10
R13: 0000000000401fa0 R14: 0000000000000000 R15: 0000000000000000

============================================
WARNING: possible recursive locking detected
4.15.0-rc6-next-20180103+ #87 Not tainted
--------------------------------------------
syzkaller221540/3462 is trying to acquire lock:
(&pn->all_ppp_mutex){+.+.}, at: [<00000000709ea4fe>]
ppp_dev_uninit+0x1be/0x390 drivers/net/ppp/ppp_generic.c:1369

but task is already holding lock:
(&pn->all_ppp_mutex){+.+.}, at: [<00000000752caad5>] ppp_unit_register
drivers/net/ppp/ppp_generic.c:981 [inline]
(&pn->all_ppp_mutex){+.+.}, at: [<00000000752caad5>]
ppp_dev_configure+0x6a4/0xc40 drivers/net/ppp/ppp_generic.c:1066

other info that might help us debug this:
Possible unsafe locking scenario:

CPU0
----
lock(&pn->all_ppp_mutex);
lock(&pn->all_ppp_mutex);

*** DEADLOCK ***

May be due to missing lock nesting notation

3 locks held by syzkaller221540/3462:
#0: (ppp_mutex){+.+.}, at: [<000000000235c4ad>] ppp_ioctl+0x9e/0x2200
drivers/net/ppp/ppp_generic.c:598
#1: (rtnl_mutex){+.+.}, at: [<000000002fbce150>] rtnl_lock+0x17/0x20
net/core/rtnetlink.c:74
#2: (&pn->all_ppp_mutex){+.+.}, at: [<00000000752caad5>]
ppp_unit_register drivers/net/ppp/ppp_generic.c:981 [inline]
#2: (&pn->all_ppp_mutex){+.+.}, at: [<00000000752caad5>]
ppp_dev_configure+0x6a4/0xc40 drivers/net/ppp/ppp_generic.c:1066

stack backtrace:
CPU: 0 PID: 3462 Comm: syzkaller221540 Not tainted
4.15.0-rc6-next-20180103+ #87
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:17 [inline]
dump_stack+0x137/0x198 lib/dump_stack.c:53
print_deadlock_bug kernel/locking/lockdep.c:1756 [inline]
check_deadlock kernel/locking/lockdep.c:1800 [inline]
validate_chain kernel/locking/lockdep.c:2396 [inline]
__lock_acquire+0xec3/0x3cf0 kernel/locking/lockdep.c:3426
lock_acquire+0x16b/0x420 kernel/locking/lockdep.c:3914
__mutex_lock_common kernel/locking/mutex.c:756 [inline]
__mutex_lock+0xec/0x1550 kernel/locking/mutex.c:893
mutex_lock_nested+0x16/0x20 kernel/locking/mutex.c:908
ppp_dev_uninit+0x1be/0x390 drivers/net/ppp/ppp_generic.c:1369
register_netdevice+0x8bf/0xf30 net/core/dev.c:7835
ppp_unit_register drivers/net/ppp/ppp_generic.c:1009 [inline]
ppp_dev_configure+0x854/0xc40 drivers/net/ppp/ppp_generic.c:1066
ppp_create_interface drivers/net/ppp/ppp_generic.c:3027 [inline]
ppp_unattached_ioctl drivers/net/ppp/ppp_generic.c:866 [inline]
ppp_ioctl+0x1491/0x2200 drivers/net/ppp/ppp_generic.c:602
vfs_ioctl fs/ioctl.c:46 [inline]
do_vfs_ioctl+0x190/0xfe0 fs/ioctl.c:686
SYSC_ioctl fs/ioctl.c:701 [inline]
SyS_ioctl+0x8f/0xc0 fs/ioctl.c:692
entry_SYSCALL_64_fastpath+0x23/0x9a
RIP: 0033:0x440649
RSP: 002b:00007fff8dc7fdc8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000001 RCX: 0000000000440649
RDX: 0000000020001000 RSI: 00000000c004743e RDI: 0000000000000003
RBP: 0000000000000004 R08: 0000000000000001 R09: 0000000000000035
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000401f10
R13: 0000000000401fa0 R14: 0000000000000000 R15: 0000000000000000


---
This bug is generated by a dumb bot. It may contain errors.
See https://goo.gl/tpsmEJ for details.
Direct all questions to [email protected].

syzbot will keep track of this bug report.
If you forgot to add the Reported-by tag, once the fix for this bug is
merged
into any tree, please reply to this email with:
#syz fix: exact-commit-title
If you want to test a patch for this bug, please reply with:
#syz test: git://repo/address.git branch
and provide the patch inline or as an attachment.
To mark this as a duplicate of another syzbot report, please reply with:
#syz dup: exact-subject-of-another-report
If it's a one-off invalid bug report, please reply with:
#syz invalid
Note: if the crash happens again, it will cause creation of a new bug
report.
Note: all commands must start from beginning of the line in the email body.


Attachments:
config.txt (130.92 kB)
raw.log (7.72 kB)
repro.txt (578.00 B)
repro.c (3.04 kB)
Download all attachments

2018-01-05 18:22:53

by Guillaume Nault

[permalink] [raw]
Subject: Re: possible deadlock in ppp_dev_uninit

On Wed, Jan 03, 2018 at 10:58:01PM -0800, syzbot wrote:
> Hello,
>
> ============================================
> WARNING: possible recursive locking detected
> 4.15.0-rc6-next-20180103+ #87 Not tainted
> --------------------------------------------
> syzkaller221540/3462 is trying to acquire lock:
> (&pn->all_ppp_mutex){+.+.}, at: [<00000000709ea4fe>]
> ppp_dev_uninit+0x1be/0x390 drivers/net/ppp/ppp_generic.c:1369
>
> but task is already holding lock:
> (&pn->all_ppp_mutex){+.+.}, at: [<00000000752caad5>] ppp_unit_register
> drivers/net/ppp/ppp_generic.c:981 [inline]
> (&pn->all_ppp_mutex){+.+.}, at: [<00000000752caad5>]
> ppp_dev_configure+0x6a4/0xc40 drivers/net/ppp/ppp_generic.c:1066
>
ppp_unit_register() acquires pn->all_ppp_mutex while calling
register_netdevice(). If register_netdevice() fails, it can call
ppp_dev_uninit() which then tries to lock pn->all_ppp_mutex again.

Maybe unlocking pn->all_ppp_mutex before register_netdevice() would be
enough, but that'd make the unit visible while the PPP device isn't yet
registered. I'm going to check if that can be a problem.

That's probably worth a test anyway.

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git master

-------- 8< --------

diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
index d8e5747ff4e3..264d4af0bf69 100644
--- a/drivers/net/ppp/ppp_generic.c
+++ b/drivers/net/ppp/ppp_generic.c
@@ -1006,17 +1006,18 @@ static int ppp_unit_register(struct ppp *ppp, int unit, bool ifname_is_set)
if (!ifname_is_set)
snprintf(ppp->dev->name, IFNAMSIZ, "ppp%i", ppp->file.index);

+ mutex_unlock(&pn->all_ppp_mutex);
+
ret = register_netdevice(ppp->dev);
if (ret < 0)
goto err_unit;

atomic_inc(&ppp_unit_count);

- mutex_unlock(&pn->all_ppp_mutex);
-
return 0;

err_unit:
+ mutex_lock(&pn->all_ppp_mutex);
unit_put(&pn->units_idr, ppp->file.index);
err:
mutex_unlock(&pn->all_ppp_mutex);

2018-01-05 18:27:07

by Guillaume Nault

[permalink] [raw]
Subject: Re: possible deadlock in ppp_dev_uninit

On Fri, Jan 05, 2018 at 07:15:31PM +0100, Guillaume Nault wrote:
> That's probably worth a test anyway.
>
Copy/paste error :-/

Here's a version that should apply cleanly.

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git master

-------- 8< --------

diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
index d8e5747ff4e3..264d4af0bf69 100644
--- a/drivers/net/ppp/ppp_generic.c
+++ b/drivers/net/ppp/ppp_generic.c
@@ -1006,17 +1006,18 @@ static int ppp_unit_register(struct ppp *ppp, int unit, bool ifname_is_set)
if (!ifname_is_set)
snprintf(ppp->dev->name, IFNAMSIZ, "ppp%i", ppp->file.index);

+ mutex_unlock(&pn->all_ppp_mutex);
+
ret = register_netdevice(ppp->dev);
if (ret < 0)
goto err_unit;

atomic_inc(&ppp_unit_count);

- mutex_unlock(&pn->all_ppp_mutex);
-
return 0;

err_unit:
+ mutex_lock(&pn->all_ppp_mutex);
unit_put(&pn->units_idr, ppp->file.index);
err:
mutex_unlock(&pn->all_ppp_mutex);

2018-01-05 18:32:06

by syzbot

[permalink] [raw]
Subject: possible deadlock in ppp_dev_uninit

Hello,

syzbot has tested the proposed patch and the reproducer did not trigger
crash:

Reported-and-tested-by:
[email protected]

Note: the tag will also help syzbot to understand when the bug is fixed.

Tested on commit d1616f07e8f1a4a490d1791316d4a68906b284aa
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git/master
compiler: gcc (GCC) 7.1.1 20170620
Patch is attached.
Kernel config is attached.


---
There is no WARRANTY for the result, to the extent permitted by applicable
law.
Except when otherwise stated in writing syzbot provides the result "AS IS"
without warranty of any kind, either expressed or implied, but not limited
to,
the implied warranties of merchantability and fittness for a particular
purpose.
The entire risk as to the quality of the result is with you. Should the
result
prove defective, you assume the cost of all necessary servicing, repair or
correction.


Attachments:
config.txt (131.20 kB)
patch.txt (675.00 B)
Download all attachments

2018-01-05 18:41:04

by syzbot

[permalink] [raw]
Subject: possible deadlock in ppp_dev_uninit

Hello,

syzbot tried to test the proposed patch but build/boot failed:

failed to copy test binary to VM: failed to run /usr/bin/scp [scp -P 22 -i
/syzkaller/jobs/linux/image/key -F /dev/null -o
UserKnownHostsFile=/dev/null -o BatchMode=yes -o IdentitiesOnly=yes -o
StrictHostKeyChecking=no -o ConnectTimeout=10 /tmp/syzkaller180475523
[email protected]:./syzkaller180475523]: exit status 1
ssh: connect to host 10.128.0.60 port 22: Connection timed out
lost connection



Tested on commit d1616f07e8f1a4a490d1791316d4a68906b284aa
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git/master
compiler: gcc (GCC) 7.1.1 20170620
Patch is attached.
Kernel config is attached.



Attachments:
config.txt (131.20 kB)
patch.txt (675.00 B)
Download all attachments

2018-01-05 18:53:05

by syzbot

[permalink] [raw]
Subject: possible deadlock in ppp_dev_uninit

Hello,

syzbot has tested the proposed patch and the reproducer did not trigger
crash:

Reported-and-tested-by:
[email protected]

Note: the tag will also help syzbot to understand when the bug is fixed.

Tested on commit d1616f07e8f1a4a490d1791316d4a68906b284aa
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git/master
compiler: gcc (GCC) 7.1.1 20170620
Patch is attached.
Kernel config is attached.


---
There is no WARRANTY for the result, to the extent permitted by applicable
law.
Except when otherwise stated in writing syzbot provides the result "AS IS"
without warranty of any kind, either expressed or implied, but not limited
to,
the implied warranties of merchantability and fittness for a particular
purpose.
The entire risk as to the quality of the result is with you. Should the
result
prove defective, you assume the cost of all necessary servicing, repair or
correction.


Attachments:
config.txt (131.20 kB)
patch.txt (589.00 B)
Download all attachments

2018-01-05 19:05:04

by syzbot

[permalink] [raw]
Subject: possible deadlock in ppp_dev_uninit

Hello,

syzbot has tested the proposed patch and the reproducer did not trigger
crash:

Reported-and-tested-by:
[email protected]

Note: the tag will also help syzbot to understand when the bug is fixed.

Tested on commit d1616f07e8f1a4a490d1791316d4a68906b284aa
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git/master
compiler: gcc (GCC) 7.1.1 20170620
Patch is attached.
Kernel config is attached.


---
There is no WARRANTY for the result, to the extent permitted by applicable
law.
Except when otherwise stated in writing syzbot provides the result "AS IS"
without warranty of any kind, either expressed or implied, but not limited
to,
the implied warranties of merchantability and fittness for a particular
purpose.
The entire risk as to the quality of the result is with you. Should the
result
prove defective, you assume the cost of all necessary servicing, repair or
correction.


Attachments:
config.txt (131.20 kB)
patch.txt (589.00 B)
Download all attachments