All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Vladis Dronov <vdronov@redhat.com>
Cc: Jiri Kosina <jikos@kernel.org>,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] HID: debug: fix the ring buffer implementation
Date: Fri, 25 Jan 2019 14:01:14 +0100	[thread overview]
Message-ID: <20190125130113.GA18589@redhat.com> (raw)
In-Reply-To: <20190125095744.3813-1-vdronov@redhat.com>

On 01/25, Vladis Dronov wrote:
>
> Ring buffer implementation in hid_debug_event() and hid_debug_events_read()
> is strange allowing lost or corrupted data. After commit 717adfdaf147
> ("HID: debug: check length before copy_to_user()") it is possible to enter
> an infinite loop in hid_debug_events_read() by providing 0 as count, this
> locks up a system. Fix this by rewriting the ring buffer implementation
> with kfifo and simplify the code.
>
> This fixes CVE-2019-3819.

To me this looks like a good cleanup even if we forget about bugfix. Cosmetic
nits, feel free to ignore...

> +	if (kfifo_is_empty(&list->hid_debug_fifo)) {
> +		add_wait_queue(&list->hdev->debug_wait, &wait);
> +		set_current_state(TASK_INTERRUPTIBLE);
> +
> +		while (kfifo_is_empty(&list->hid_debug_fifo)) {
> +			if (file->f_flags & O_NONBLOCK) {
> +				ret = -EAGAIN;
> +				break;
> +			}
> +
> +			if (signal_pending(current)) {
> +				ret = -ERESTARTSYS;
> +				break;
> +			}
> +
> +			if (!list->hdev || !list->hdev->debug) {
> +				ret = -EIO;
> +				set_current_state(TASK_RUNNING);
> +				goto out;

Can't resist... Yes, this is what the current code does. But you know that it looks
suspicious ;) if you add a comment the patch will be even better.

> +			}
> +
> +			/* allow O_NONBLOCK from other threads */
> +			mutex_unlock(&list->read_mutex);
> +			schedule();
> +			mutex_lock(&list->read_mutex);
> +			set_current_state(TASK_INTERRUPTIBLE);
> +		}
> +
> +		set_current_state(TASK_RUNNING);

you can use __set_current_state() here, mb() is not needed.

> +		remove_wait_queue(&list->hdev->debug_wait, &wait);
> +	}
> +
> +	if (ret)
> +		goto out;
> +

perhaps it make sense to move this check into the "if (kfifo_is_empty())" block.

> +	if (kfifo_is_empty(&list->hid_debug_fifo))
> +		goto out;

is kfifo_is_empty() == T really possible here?

Oleg.

  reply	other threads:[~2019-01-25 13:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-25  9:57 [PATCH] HID: debug: fix the ring buffer implementation Vladis Dronov
2019-01-25 13:01 ` Oleg Nesterov [this message]
2019-01-26 15:44   ` Vladis Dronov

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=20190125130113.GA18589@redhat.com \
    --to=oleg@redhat.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=vdronov@redhat.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.