linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Jay Lang <jaytlang@mit.edu>
Cc: jaytlang@mit.edu, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Christian Brauner <christian@brauner.io>,
	Andy Lutomirski <luto@kernel.org>,
	Juergen Gross <jgross@suse.com>, Jan Beulich <jbeulich@suse.com>,
	Benjamin Thiel <b.thiel@posteo.de>,
	Matthew Garrett <mjg59@srcf.ucam.org>,
	"Peter Zijlstra \(Intel\)" <peterz@infradead.org>,
	Brian Gerst <brgerst@gmail.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	yu kuai <yukuai3@huawei.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86/ioperm: fix a memory leak bug
Date: Thu, 28 May 2020 21:30:32 +0200	[thread overview]
Message-ID: <87k10voo13.fsf@nanos.tec.linutronix.de> (raw)
In-Reply-To: <20200524162742.253727-1-jaytlang@mit.edu>

Jay,

Jay Lang <jaytlang@mit.edu> writes:

> In the copy_process() routine called by _do_fork(), failure to allocate
> a PID (or further along in the function) will trigger an invocation to
> exit_thread(). This is done to clean up from an earlier call to
> copy_thread_tls(). Naturally, the child task is passed into exit_thread(),
> however during the process, io_bitmap_exit() nullifies the parent's
> io_bitmap rather than the child's.
>
> As copy_thread_tls() has been called ahead of the failure, the reference
> count on the calling thread's io_bitmap is incremented as we would expect.
> However, io_bitmap_exit() doesn't accept any arguments, and thus assumes
> it should trash the current thread's io_bitmap reference rather than the
> child's. This is pretty sneaky in practice, because in all instances but
> this one, exit_thread() is called with respect to the current task and
> everything works out.
>
> A determined attacker can issue an appropriate ioctl (i.e. KDENABIO) to
> get a bitmap allocated, and force a clone3() syscall to fail by passing
> in a zeroed clone_args structure. The kernel handles the erroneous struct
> and the buggy code path is followed, and even though the parent's reference
> to the io_bitmap is trashed, the child still holds a reference and thus
> the structure will never be freed.

Nice catch! I'm sure I thought about that at some point and then forgot
again.

> Fix this by tweaking io_bitmap_exit() and its subroutines to accept a
> task_struct argument which to operate on.

> This may not be the most elegant solution, but it mitigates the
> trigger described above on an x86_64 kernel.

It's well done and straight forward and comes with a well done change
log. Appreciated!

Thanks,

        tglx

  reply	other threads:[~2020-05-28 19:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-24 16:27 Jay Lang
2020-05-28 19:30 ` Thomas Gleixner [this message]
2020-05-28 19:38 ` [tip: x86/urgent] x86/ioperm: Prevent a memory leak when fork fails tip-bot2 for Jay Lang

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=87k10voo13.fsf@nanos.tec.linutronix.de \
    --to=tglx@linutronix.de \
    --cc=b.thiel@posteo.de \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=christian@brauner.io \
    --cc=hpa@zytor.com \
    --cc=jaytlang@mit.edu \
    --cc=jbeulich@suse.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=mjg59@srcf.ucam.org \
    --cc=mtosatti@redhat.com \
    --cc=peterz@infradead.org \
    --cc=x86@kernel.org \
    --cc=yukuai3@huawei.com \
    --subject='Re: [PATCH] x86/ioperm: fix a memory leak bug' \
    /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

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox