From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Morton Subject: + kcov-fix-potential-use-after-free-in-kcov_remote_start.patch added to -mm tree Date: Fri, 20 Mar 2020 17:27:03 -0700 Message-ID: <20200321002703.qaQ8h-8j_%akpm@linux-foundation.org> References: <20200305222751.6d781a3f2802d79510941e4e@linux-foundation.org> Reply-To: linux-kernel@vger.kernel.org Return-path: Received: from mail.kernel.org ([198.145.29.99]:55826 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726867AbgCUA1E (ORCPT ); Fri, 20 Mar 2020 20:27:04 -0400 In-Reply-To: <20200305222751.6d781a3f2802d79510941e4e@linux-foundation.org> Sender: mm-commits-owner@vger.kernel.org List-Id: mm-commits@vger.kernel.org To: andreyknvl@gmail.com, andreyknvl@google.com, elver@google.com, glider@google.com, gregkh@linuxfoundation.org, mm-commits@vger.kernel.org, stern@rowland.harvard.edu The patch titled Subject: kcov: fix potential use-after-free in kcov_remote_start has been added to the -mm tree. Its filename is kcov-fix-potential-use-after-free-in-kcov_remote_start.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/kcov-fix-potential-use-after-free-in-kcov_remote_start.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/kcov-fix-potential-use-after-free-in-kcov_remote_start.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Andrey Konovalov Subject: kcov: fix potential use-after-free in kcov_remote_start 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. Link: http://lkml.kernel.org/r/de0d3d30ff90776a2a509cc34c7c1c7521bda125.1584655448.git.andreyknvl@google.com Signed-off-by: Andrey Konovalov Cc: Alan Stern Cc: Alexander Potapenko Cc: Greg Kroah-Hartman Cc: Marco Elver Signed-off-by: Andrew Morton --- kernel/kcov.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) --- a/kernel/kcov.c~kcov-fix-potential-use-after-free-in-kcov_remote_start +++ a/kernel/kcov.c @@ -748,6 +748,7 @@ static const struct file_operations kcov 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; } } _ Patches currently in -mm which might be from andreyknvl@gmail.com are kcov-fix-potential-use-after-free-in-kcov_remote_start.patch kcov-move-t-kcov-assignments-into-kcov_start-stop.patch kcov-move-t-kcov_sequence-assignment.patch kcov-use-t-kcov_mode-as-enabled-indicator.patch