mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Cc: Hillf Danton <hdanton@sina.com>, Ingo Molnar <mingo@kernel.org>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	linux-kernel@vger.kernel.org, mcgrof@kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>,
	syzkaller-bugs@googlegroups.com,
	syzbot <syzbot+6cd18e123583550cf469@syzkaller.appspotmail.com>
Subject: Re: [syzbot] WARNING: locking bug in umh_complete
Date: Fri, 3 Feb 2023 13:00:54 +0100	[thread overview]
Message-ID: <Y9z3dvOH4SkQhU7w@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <9d9b9652-c1ac-58e9-2eab-9256c17b1da2@I-love.SAKURA.ne.jp>

On Fri, Feb 03, 2023 at 07:22:43PM +0900, Tetsuo Handa wrote:
> On 2023/01/27 10:41, Hillf Danton wrote:

> >> Call Trace:
> >>  <TASK>
> >>  lock_acquire kernel/locking/lockdep.c:5668 [inline]
> >>  lock_acquire+0x1e3/0x630 kernel/locking/lockdep.c:5633
> >>  __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline]
> >>  _raw_spin_lock_irqsave+0x3d/0x60 kernel/locking/spinlock.c:162
> >>  complete+0x1d/0x1f0 kernel/sched/completion.c:32
> >>  umh_complete+0x32/0x90 kernel/umh.c:59
> >>  call_usermodehelper_exec_sync kernel/umh.c:144 [inline]
> >>  call_usermodehelper_exec_work+0x115/0x180 kernel/umh.c:167
> >>  process_one_work+0x9bf/0x1710 kernel/workqueue.c:2289
> >>  worker_thread+0x669/0x1090 kernel/workqueue.c:2436
> >>  kthread+0x2e8/0x3a0 kernel/kthread.c:376
> >>  ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308
> >>  </TASK>
> > 
> > This is an interesting case - given done initialized on stack, no garbage
> > should have been detected by lockdep.
> > 
> > One explanation to the report is uaf on the waker side, and it can be
> > tested with the diff below when a reproducer is available.
> > 
> > Hillf
> > 
> > --- a/kernel/umh.c
> > +++ b/kernel/umh.c
> > @@ -452,6 +452,12 @@ int call_usermodehelper_exec(struct subp
> >  		/* umh_complete() will see NULL and free sub_info */
> >  		if (xchg(&sub_info->complete, NULL))
> >  			goto unlock;
> > +		else {
> > +			/* wait for umh_complete() to finish in a bid to avoid
> > +			 * uaf because done is destructed
> > +			 */

Invalid comment style at the very least.

> > +			wait_for_completion(&done);
> > +		}
> >  	}
> >  
> >  wait_done:
> > --
> 
> Yes, this bug is caused by commit f5d39b020809 ("freezer,sched: Rewrite core freezer
> logic"), for that commit for unknown reason omits wait_for_completion(&done) call
> when wait_for_completion_state(&done, state) returned -ERESTARTSYS.
> 
> Peter, is it safe to restore wait_for_completion(&done) call?

Urgh, that code is terrible.. the way I read it was that it would
wait_for_completion_killable() if KILLABLE and assumed the
second wait_for_completion() would NOP out because we'd already
completed on the first.

I don't see how adding a second wait is correct in the case of
-ERESTARTSYS, what's the stop this second wait to also get interrupted
like that?

Should there be a loop?

  parent reply	other threads:[~2023-02-03 12:01 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20230127014137.4906-1-hdanton@sina.com>
2023-02-03 10:22 ` Tetsuo Handa
2023-02-03 10:48   ` Tetsuo Handa
2023-02-03 12:19     ` Peter Zijlstra
2023-02-03 12:30       ` Peter Zijlstra
2023-02-03 12:59         ` Tetsuo Handa
2023-02-03 14:31           ` Peter Zijlstra
2023-02-04  0:48             ` Tetsuo Handa
2023-02-06 15:51               ` Luis Chamberlain
2023-02-13 15:14                 ` Peter Zijlstra
2023-02-13 15:27                 ` Peter Zijlstra
2023-02-14  2:31                   ` Schspa Shi
2023-02-21 21:54                     ` Luis Chamberlain
2023-02-22  9:34                     ` Peter Zijlstra
2023-02-27  7:57                       ` Schspa Shi
2023-02-13 15:34               ` Peter Zijlstra
2023-02-14 11:16                 ` Tetsuo Handa
2023-02-15 10:33             ` [tip: sched/urgent] freezer,umh: Fix call_usermode_helper_exec() vs SIGKILL tip-bot2 for Peter Zijlstra
2023-02-03 12:00   ` Peter Zijlstra [this message]
2023-01-26 22:27 [syzbot] WARNING: locking bug in umh_complete syzbot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y9z3dvOH4SkQhU7w@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=hdanton@sina.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=mingo@kernel.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=rafael.j.wysocki@intel.com \
    --cc=syzbot+6cd18e123583550cf469@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®