From: Greg KH <gregkh@linuxfoundation.org>
To: "Dae R. Jeong" <threeearcat@gmail.com>
Cc: bryantan@vmware.com, vdasa@vmware.com, pv-drivers@vmware.com,
arnd@arndb.de, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] vmci_host: fix a race condition in vmci_host_poll() causing GPF
Date: Wed, 29 Mar 2023 12:15:21 +0200 [thread overview]
Message-ID: <ZCQPuaps5rCtGAb2@kroah.com> (raw)
In-Reply-To: <ZCGFsdBAU4cYww5l@dragonet>
On Mon, Mar 27, 2023 at 09:01:53PM +0900, Dae R. Jeong wrote:
> During fuzzing, a general protection fault is observed in
> vmci_host_poll().
>
> general protection fault, probably for non-canonical address 0xdffffc0000000019: 0000 [#1] PREEMPT SMP KASAN
> KASAN: null-ptr-deref in range [0x00000000000000c8-0x00000000000000cf]
> RIP: 0010:__lock_acquire+0xf3/0x5e00 kernel/locking/lockdep.c:4926
> <- omitting registers ->
> Call Trace:
> <TASK>
> lock_acquire+0x1a4/0x4a0 kernel/locking/lockdep.c:5672
> __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline]
> _raw_spin_lock_irqsave+0xb3/0x100 kernel/locking/spinlock.c:162
> add_wait_queue+0x3d/0x260 kernel/sched/wait.c:22
> poll_wait include/linux/poll.h:49 [inline]
> vmci_host_poll+0xf8/0x2b0 drivers/misc/vmw_vmci/vmci_host.c:174
> vfs_poll include/linux/poll.h:88 [inline]
> do_pollfd fs/select.c:873 [inline]
> do_poll fs/select.c:921 [inline]
> do_sys_poll+0xc7c/0x1aa0 fs/select.c:1015
> __do_sys_ppoll fs/select.c:1121 [inline]
> __se_sys_ppoll+0x2cc/0x330 fs/select.c:1101
> do_syscall_x64 arch/x86/entry/common.c:51 [inline]
> do_syscall_64+0x4e/0xa0 arch/x86/entry/common.c:82
> entry_SYSCALL_64_after_hwframe+0x46/0xb0
>
> Example thread interleaving that causes the general protection fault
> is as follows:
>
> CPU1 (vmci_host_poll) CPU2 (vmci_host_do_init_context)
> ----- -----
> // Read uninitialized context
> context = vmci_host_dev->context;
> // Initialize context
> vmci_host_dev->context = vmci_ctx_create();
> vmci_host_dev->ct_type = VMCIOBJ_CONTEXT;
>
> if (vmci_host_dev->ct_type == VMCIOBJ_CONTEXT) {
> // Dereferencing the wrong pointer
> poll_wait(..., &context->host_context);
> }
>
> In this scenario, vmci_host_poll() reads vmci_host_dev->context first,
> and then reads vmci_host_dev->ct_type to check that
> vmci_host_dev->context is initialized. However, since these two reads
> are not atomically executed, there is a chance of a race condition as
> described above.
>
> To fix this race condition, read vmci_host_dev->context after checking
> the value of vmci_host_dev->ct_type so that vmci_host_poll() always
> reads an initialized context.
>
> Reported-by: Dae R. Jeong <threeearcat@gmail.com>
> Fixes: 8bf503991f87 ("VMCI: host side driver implementation.")
> Signed-off-by: Dae R. Jeong <threeearcat@gmail.com>
If you author and sign-off on the patch, no need for a Reported-by: as
that is obvious :)
And how did you test this change?
thanks,
greg k-h
next prev parent reply other threads:[~2023-03-29 10:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-27 12:01 [PATCH] vmci_host: fix a race condition in vmci_host_poll() causing GPF Dae R. Jeong
2023-03-29 10:15 ` Greg KH [this message]
2023-03-30 11:18 ` Dae R. Jeong
2023-04-11 20:33 ` Vishnu Dasa
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=ZCQPuaps5rCtGAb2@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=arnd@arndb.de \
--cc=bryantan@vmware.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pv-drivers@vmware.com \
--cc=threeearcat@gmail.com \
--cc=vdasa@vmware.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.