* [PATCH locking/locktorture] Fixes for 4.7 @ 2016-04-12 15:46 Paul E. McKenney 2016-04-12 15:47 ` [PATCH locking/locktorture 1/2] locktorture: Fix deboosting nil ptr dereferencing Paul E. McKenney 2016-04-12 15:47 ` [PATCH locking/locktorture 2/2] locktorture: Fix nil pointer dereferencing for cleanup paths Paul E. McKenney 0 siblings, 2 replies; 5+ messages in thread From: Paul E. McKenney @ 2016-04-12 15:46 UTC (permalink / raw) To: linux-kernel Cc: mingo, jiangshanlai, dipankar, akpm, mathieu.desnoyers, josh, tglx, peterz, rostedt, dhowells, edumazet, dvhart, fweisbec, oleg, bobby.prani Hello! This series contains a couple of locktorture updates, both courtesy of Davidlohr Bueso: 1. Fix deboosting nil ptr dereferencing. 2. Fix nil pointer dereferencing for cleanup paths. Thanx, Paul ------------------------------------------------------------------------ locktorture.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH locking/locktorture 1/2] locktorture: Fix deboosting nil ptr dereferencing 2016-04-12 15:46 [PATCH locking/locktorture] Fixes for 4.7 Paul E. McKenney @ 2016-04-12 15:47 ` Paul E. McKenney 2016-04-13 7:30 ` [tip:locking/core] locking/locktorture: Fix deboosting NULL pointer dereference tip-bot for Davidlohr Bueso 2016-04-12 15:47 ` [PATCH locking/locktorture 2/2] locktorture: Fix nil pointer dereferencing for cleanup paths Paul E. McKenney 1 sibling, 1 reply; 5+ messages in thread From: Paul E. McKenney @ 2016-04-12 15:47 UTC (permalink / raw) To: linux-kernel Cc: mingo, jiangshanlai, dipankar, akpm, mathieu.desnoyers, josh, tglx, peterz, rostedt, dhowells, edumazet, dvhart, fweisbec, oleg, bobby.prani, Davidlohr Bueso, Davidlohr Bueso, Paul E. McKenney From: Davidlohr Bueso <dave@stgolabs.net> For the case of rtmutex torturing we will randomly call into the boost() handler, including upon module exiting when the tasks are deboosted before stopping. In such cases the task may or may not have already been boosted, and therefore the NULL being explicitly passed can occur anywhere. Currently we only assume that the task will is at a higher prio, and in consequence, dereference a nil pointer. This patch fixes the case of a rmmod locktorture exploding while pounding on the rtmutex lock (partial trace): [83317.452251] task: ffff88081026cf80 ti: ffff880816120000 task.ti: ffff880816120000 [83317.452258] RIP: 0010:[<ffffffffa05c6185>] [<ffffffffa05c6185>] torture_random+0x5/0x60 [torture] [83317.452261] RSP: 0018:ffff880816123eb0 EFLAGS: 00010206 [83317.452264] RAX: ffff88081026cf80 RBX: ffff880816bfa630 RCX: 0000000000160d1b [83317.452267] RDX: 0000000000000000 RSI: 0000000000000202 RDI: 0000000000000000 [83317.452269] RBP: ffff88081026cf80 R08: 000000000000001f R09: ffff88017c20ca80 [83317.452271] R10: 0000000000000000 R11: 000000000048c316 R12: ffffffffa05d1840 [83317.452273] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 [83317.452275] FS: 0000000000000000(0000) GS:ffff88203f880000(0000) knlGS:0000000000000000 [83317.452277] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [83317.452279] CR2: 0000000000000008 CR3: 0000000001c0a000 CR4: 00000000000406e0 [83317.452281] Stack: [83317.452288] ffffffffa05d141d ffff880816bfa630 ffffffffa05d1922 ffff88081e70c2c0 [83317.452295] ffff880816bfa630 ffffffff81095fed 0000000000000000 ffffffff8107bf60 [83317.452297] ffff880816bfa630 ffffffff00000000 ffff880800000000 ffff880816123f08 [83317.452297] Call Trace: [83317.452309] [<ffffffffa05d141d>] torture_rtmutex_boost+0x1d/0x90 [locktorture] [83317.452315] [<ffffffffa05d1922>] lock_torture_writer+0xe2/0x170 [locktorture] [83317.452321] [<ffffffff81095fed>] kthread+0xbd/0xe0 [83317.452325] [<ffffffff815cf40f>] ret_from_fork+0x3f/0x70 This patch ensures that if the random state pointer is not nil and current is not boosted, then do nothing. Signed-off-by: Davidlohr Bueso <dbueso@suse.de> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> --- kernel/locking/locktorture.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index 8ef1919d63b2..9e9c5f454f5c 100644 --- a/kernel/locking/locktorture.c +++ b/kernel/locking/locktorture.c @@ -394,12 +394,12 @@ static void torture_rtmutex_boost(struct torture_random_state *trsp) if (!rt_task(current)) { /* - * (1) Boost priority once every ~50k operations. When the + * Boost priority once every ~50k operations. When the * task tries to take the lock, the rtmutex it will account * for the new priority, and do any corresponding pi-dance. */ - if (!(torture_random(trsp) % - (cxt.nrealwriters_stress * factor))) { + if (trsp && !(torture_random(trsp) % + (cxt.nrealwriters_stress * factor))) { policy = SCHED_FIFO; param.sched_priority = MAX_RT_PRIO - 1; } else /* common case, do nothing */ -- 2.5.2 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [tip:locking/core] locking/locktorture: Fix deboosting NULL pointer dereference 2016-04-12 15:47 ` [PATCH locking/locktorture 1/2] locktorture: Fix deboosting nil ptr dereferencing Paul E. McKenney @ 2016-04-13 7:30 ` tip-bot for Davidlohr Bueso 0 siblings, 0 replies; 5+ messages in thread From: tip-bot for Davidlohr Bueso @ 2016-04-13 7:30 UTC (permalink / raw) To: linux-tip-commits Cc: torvalds, akpm, linux-kernel, peterz, tglx, mingo, dbueso, dave, paulmck, hpa Commit-ID: 1f190931893a98ffd5d4cfdfbfc2452ad0ed3e1b Gitweb: http://git.kernel.org/tip/1f190931893a98ffd5d4cfdfbfc2452ad0ed3e1b Author: Davidlohr Bueso <dave@stgolabs.net> AuthorDate: Tue, 12 Apr 2016 08:47:17 -0700 Committer: Ingo Molnar <mingo@kernel.org> CommitDate: Wed, 13 Apr 2016 08:52:23 +0200 locking/locktorture: Fix deboosting NULL pointer dereference For the case of rtmutex torturing we will randomly call into the boost() handler, including upon module exiting when the tasks are deboosted before stopping. In such cases the task may or may not have already been boosted, and therefore the NULL being explicitly passed can occur anywhere. Currently we only assume that the task will is at a higher prio, and in consequence, dereference a NULL pointer. This patch fixes the case of a rmmod locktorture exploding while pounding on the rtmutex lock (partial trace): task: ffff88081026cf80 ti: ffff880816120000 task.ti: ffff880816120000 RSP: 0018:ffff880816123eb0 EFLAGS: 00010206 RAX: ffff88081026cf80 RBX: ffff880816bfa630 RCX: 0000000000160d1b RDX: 0000000000000000 RSI: 0000000000000202 RDI: 0000000000000000 RBP: ffff88081026cf80 R08: 000000000000001f R09: ffff88017c20ca80 R10: 0000000000000000 R11: 000000000048c316 R12: ffffffffa05d1840 R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff88203f880000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000008 CR3: 0000000001c0a000 CR4: 00000000000406e0 Stack: ffffffffa05d141d ffff880816bfa630 ffffffffa05d1922 ffff88081e70c2c0 ffff880816bfa630 ffffffff81095fed 0000000000000000 ffffffff8107bf60 ffff880816bfa630 ffffffff00000000 ffff880800000000 ffff880816123f08 Call Trace: [<ffffffff81095fed>] kthread+0xbd/0xe0 [<ffffffff815cf40f>] ret_from_fork+0x3f/0x70 This patch ensures that if the random state pointer is not NULL and current is not boosted, then do nothing. RIP: 0010:[<ffffffffa05c6185>] [<ffffffffa05c6185>] torture_random+0x5/0x60 [torture] [<ffffffffa05d141d>] torture_rtmutex_boost+0x1d/0x90 [locktorture] [<ffffffffa05d1922>] lock_torture_writer+0xe2/0x170 [locktorture] Signed-off-by: Davidlohr Bueso <dbueso@suse.de> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: bobby.prani@gmail.com Cc: dhowells@redhat.com Cc: dipankar@in.ibm.com Cc: dvhart@linux.intel.com Cc: edumazet@google.com Cc: fweisbec@gmail.com Cc: jiangshanlai@gmail.com Cc: josh@joshtriplett.org Cc: mathieu.desnoyers@efficios.com Cc: oleg@redhat.com Cc: rostedt@goodmis.org Link: http://lkml.kernel.org/r/1460476038-27060-1-git-send-email-paulmck@linux.vnet.ibm.com Signed-off-by: Ingo Molnar <mingo@kernel.org> --- kernel/locking/locktorture.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index 8ef1919..9e9c5f4 100644 --- a/kernel/locking/locktorture.c +++ b/kernel/locking/locktorture.c @@ -394,12 +394,12 @@ static void torture_rtmutex_boost(struct torture_random_state *trsp) if (!rt_task(current)) { /* - * (1) Boost priority once every ~50k operations. When the + * Boost priority once every ~50k operations. When the * task tries to take the lock, the rtmutex it will account * for the new priority, and do any corresponding pi-dance. */ - if (!(torture_random(trsp) % - (cxt.nrealwriters_stress * factor))) { + if (trsp && !(torture_random(trsp) % + (cxt.nrealwriters_stress * factor))) { policy = SCHED_FIFO; param.sched_priority = MAX_RT_PRIO - 1; } else /* common case, do nothing */ ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH locking/locktorture 2/2] locktorture: Fix nil pointer dereferencing for cleanup paths 2016-04-12 15:46 [PATCH locking/locktorture] Fixes for 4.7 Paul E. McKenney 2016-04-12 15:47 ` [PATCH locking/locktorture 1/2] locktorture: Fix deboosting nil ptr dereferencing Paul E. McKenney @ 2016-04-12 15:47 ` Paul E. McKenney 2016-04-13 7:30 ` [tip:locking/core] locking/locktorture: Fix NULL pointer dereference " tip-bot for Davidlohr Bueso 1 sibling, 1 reply; 5+ messages in thread From: Paul E. McKenney @ 2016-04-12 15:47 UTC (permalink / raw) To: linux-kernel Cc: mingo, jiangshanlai, dipankar, akpm, mathieu.desnoyers, josh, tglx, peterz, rostedt, dhowells, edumazet, dvhart, fweisbec, oleg, bobby.prani, Davidlohr Bueso, Davidlohr Bueso, Paul E. McKenney From: Davidlohr Bueso <dave@stgolabs.net> It has been found that paths that invoke cleanups through lock_torture_cleanup() can incur in nil pointer dereferencing bugs during the statistics printing phase. This is mainly because we should not be calling into statistics before we are sure things have been setup correctly. Specifically, early checks (and the need for handling this in the cleanup call) only include parameter checks and basic statistics allocation. Once we start write/read kthreads we then consider the test as started. As such, update the func in question to check for cxt.lwsa writer stats, if not set, we either have a bogus parameter or ENOMEM situation and therefore only need to deal with general torture calls Reported-and-tested-by: Kefeng Wang <wangkefeng.wang@huawei.com> Signed-off-by: Davidlohr Bueso <dbueso@suse.de> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> --- kernel/locking/locktorture.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index 9e9c5f454f5c..d066a50dc87e 100644 --- a/kernel/locking/locktorture.c +++ b/kernel/locking/locktorture.c @@ -748,6 +748,15 @@ static void lock_torture_cleanup(void) if (torture_cleanup_begin()) return; + /* + * Indicates early cleanup, meaning that the test has not run, + * such as when passing bogus args when loading the module. As + * such, only perform the underlying torture-specific cleanups, + * and avoid anything related to locktorture. + */ + if (!cxt.lwsa) + goto end; + if (writer_tasks) { for (i = 0; i < cxt.nrealwriters_stress; i++) torture_stop_kthread(lock_torture_writer, @@ -776,6 +785,7 @@ static void lock_torture_cleanup(void) else lock_torture_print_module_parms(cxt.cur_ops, "End of test: SUCCESS"); +end: torture_cleanup_end(); } @@ -870,6 +880,7 @@ static int __init lock_torture_init(void) VERBOSE_TOROUT_STRING("cxt.lrsa: Out of memory"); firsterr = -ENOMEM; kfree(cxt.lwsa); + cxt.lwsa = NULL; goto unwind; } @@ -878,6 +889,7 @@ static int __init lock_torture_init(void) cxt.lrsa[i].n_lock_acquired = 0; } } + lock_torture_print_module_parms(cxt.cur_ops, "Start of test"); /* Prepare torture context. */ -- 2.5.2 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [tip:locking/core] locking/locktorture: Fix NULL pointer dereference for cleanup paths 2016-04-12 15:47 ` [PATCH locking/locktorture 2/2] locktorture: Fix nil pointer dereferencing for cleanup paths Paul E. McKenney @ 2016-04-13 7:30 ` tip-bot for Davidlohr Bueso 0 siblings, 0 replies; 5+ messages in thread From: tip-bot for Davidlohr Bueso @ 2016-04-13 7:30 UTC (permalink / raw) To: linux-tip-commits Cc: paulmck, akpm, tglx, dbueso, mingo, linux-kernel, torvalds, dave, wangkefeng.wang, peterz, hpa Commit-ID: c1c33b92db4fb274dfbff778ccf2459e4bebd48e Gitweb: http://git.kernel.org/tip/c1c33b92db4fb274dfbff778ccf2459e4bebd48e Author: Davidlohr Bueso <dave@stgolabs.net> AuthorDate: Tue, 12 Apr 2016 08:47:18 -0700 Committer: Ingo Molnar <mingo@kernel.org> CommitDate: Wed, 13 Apr 2016 08:52:23 +0200 locking/locktorture: Fix NULL pointer dereference for cleanup paths It has been found that paths that invoke cleanups through lock_torture_cleanup() can trigger NULL pointer dereferencing bugs during the statistics printing phase. This is mainly because we should not be calling into statistics before we are sure things have been set up correctly. Specifically, early checks (and the need for handling this in the cleanup call) only include parameter checks and basic statistics allocation. Once we start write/read kthreads we then consider the test as started. As such, update the function in question to check for cxt.lwsa writer stats, if not set, we either have a bogus parameter or -ENOMEM situation and therefore only need to deal with general torture calls. Reported-and-tested-by: Kefeng Wang <wangkefeng.wang@huawei.com> Signed-off-by: Davidlohr Bueso <dbueso@suse.de> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: bobby.prani@gmail.com Cc: dhowells@redhat.com Cc: dipankar@in.ibm.com Cc: dvhart@linux.intel.com Cc: edumazet@google.com Cc: fweisbec@gmail.com Cc: jiangshanlai@gmail.com Cc: josh@joshtriplett.org Cc: mathieu.desnoyers@efficios.com Cc: oleg@redhat.com Cc: rostedt@goodmis.org Link: http://lkml.kernel.org/r/1460476038-27060-2-git-send-email-paulmck@linux.vnet.ibm.com [ Improved the changelog. ] Signed-off-by: Ingo Molnar <mingo@kernel.org> --- kernel/locking/locktorture.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index 9e9c5f4..d066a50 100644 --- a/kernel/locking/locktorture.c +++ b/kernel/locking/locktorture.c @@ -748,6 +748,15 @@ static void lock_torture_cleanup(void) if (torture_cleanup_begin()) return; + /* + * Indicates early cleanup, meaning that the test has not run, + * such as when passing bogus args when loading the module. As + * such, only perform the underlying torture-specific cleanups, + * and avoid anything related to locktorture. + */ + if (!cxt.lwsa) + goto end; + if (writer_tasks) { for (i = 0; i < cxt.nrealwriters_stress; i++) torture_stop_kthread(lock_torture_writer, @@ -776,6 +785,7 @@ static void lock_torture_cleanup(void) else lock_torture_print_module_parms(cxt.cur_ops, "End of test: SUCCESS"); +end: torture_cleanup_end(); } @@ -870,6 +880,7 @@ static int __init lock_torture_init(void) VERBOSE_TOROUT_STRING("cxt.lrsa: Out of memory"); firsterr = -ENOMEM; kfree(cxt.lwsa); + cxt.lwsa = NULL; goto unwind; } @@ -878,6 +889,7 @@ static int __init lock_torture_init(void) cxt.lrsa[i].n_lock_acquired = 0; } } + lock_torture_print_module_parms(cxt.cur_ops, "Start of test"); /* Prepare torture context. */ ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-04-13 7:31 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-04-12 15:46 [PATCH locking/locktorture] Fixes for 4.7 Paul E. McKenney 2016-04-12 15:47 ` [PATCH locking/locktorture 1/2] locktorture: Fix deboosting nil ptr dereferencing Paul E. McKenney 2016-04-13 7:30 ` [tip:locking/core] locking/locktorture: Fix deboosting NULL pointer dereference tip-bot for Davidlohr Bueso 2016-04-12 15:47 ` [PATCH locking/locktorture 2/2] locktorture: Fix nil pointer dereferencing for cleanup paths Paul E. McKenney 2016-04-13 7:30 ` [tip:locking/core] locking/locktorture: Fix NULL pointer dereference " tip-bot for Davidlohr Bueso
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).