linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrey Konovalov <andreyknvl@google.com>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Alexander Potapenko <glider@google.com>,
	Marco Elver <elver@google.com>,
	Andrey Konovalov <andreyknvl@google.com>
Subject: [PATCH v4 2/7] kcov: fix potential use-after-free in kcov_remote_start
Date: Thu, 26 Mar 2020 15:44:01 +0100	[thread overview]
Message-ID: <9d9134359725a965627b7e8f2652069f86f1d1fa.1585233617.git.andreyknvl@google.com> (raw)
In-Reply-To: <cover.1585233617.git.andreyknvl@google.com>

If vmalloc() fails in kcov_remote_start() we'll access remote->kcov
without holding kcov_remote_lock, so remote might potentially be freed
at that point. Cache kcov pointer in a local variable.

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
 kernel/kcov.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/kernel/kcov.c b/kernel/kcov.c
index f6bd119c9419..cc5900ac2467 100644
--- a/kernel/kcov.c
+++ b/kernel/kcov.c
@@ -748,6 +748,7 @@ static const struct file_operations kcov_fops = {
 void kcov_remote_start(u64 handle)
 {
 	struct kcov_remote *remote;
+	struct kcov *kcov;
 	void *area;
 	struct task_struct *t;
 	unsigned int size;
@@ -774,16 +775,17 @@ void kcov_remote_start(u64 handle)
 		spin_unlock(&kcov_remote_lock);
 		return;
 	}
+	kcov = remote->kcov;
 	/* Put in kcov_remote_stop(). */
-	kcov_get(remote->kcov);
-	t->kcov = remote->kcov;
+	kcov_get(kcov);
+	t->kcov = kcov;
 	/*
 	 * Read kcov fields before unlock to prevent races with
 	 * KCOV_DISABLE / kcov_remote_reset().
 	 */
-	size = remote->kcov->remote_size;
-	mode = remote->kcov->mode;
-	sequence = remote->kcov->sequence;
+	size = kcov->remote_size;
+	mode = kcov->mode;
+	sequence = kcov->sequence;
 	area = kcov_remote_area_get(size);
 	spin_unlock(&kcov_remote_lock);
 
@@ -791,7 +793,7 @@ void kcov_remote_start(u64 handle)
 		area = vmalloc(size * sizeof(unsigned long));
 		if (!area) {
 			t->kcov = NULL;
-			kcov_put(remote->kcov);
+			kcov_put(kcov);
 			return;
 		}
 	}
-- 
2.26.0.rc2.310.g2932bb562d-goog


  parent reply	other threads:[~2020-03-26 14:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-26 14:43 [PATCH v4 0/7] kcov: collect coverage from usb soft interrupts Andrey Konovalov
2020-03-26 14:44 ` [PATCH v4 1/7] kcov: cleanup debug messages Andrey Konovalov
2020-06-04 12:05   ` Dmitry Vyukov
2020-03-26 14:44 ` Andrey Konovalov [this message]
2020-06-04 12:06   ` [PATCH v4 2/7] kcov: fix potential use-after-free in kcov_remote_start Dmitry Vyukov
2020-03-26 14:44 ` [PATCH v4 3/7] kcov: move t->kcov assignments into kcov_start/stop Andrey Konovalov
2020-06-04 12:09   ` Dmitry Vyukov
2020-03-26 14:44 ` [PATCH v4 4/7] kcov: move t->kcov_sequence assignment Andrey Konovalov
2020-06-04 13:07   ` Dmitry Vyukov
2020-03-26 14:44 ` [PATCH v4 5/7] kcov: use t->kcov_mode as enabled indicator Andrey Konovalov
2020-06-04 13:07   ` Dmitry Vyukov
2020-03-26 14:44 ` [PATCH v4 6/7] kcov: collect coverage from interrupts Andrey Konovalov
2020-06-04 13:11   ` Dmitry Vyukov
2020-03-26 14:44 ` [PATCH v4 7/7] usb: core: kcov: collect coverage from usb complete callback Andrey Konovalov
2020-06-04 13:12   ` Dmitry Vyukov
2020-06-04 13:46 ` [PATCH v4 0/7] kcov: collect coverage from usb soft interrupts Andrey Konovalov

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=9d9134359725a965627b7e8f2652069f86f1d1fa.1585233617.git.andreyknvl@google.com \
    --to=andreyknvl@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=glider@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /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;
as well as URLs for NNTP newsgroup(s).