From patchwork Tue Jun 23 19:58:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 223267 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3417EC433E1 for ; Tue, 23 Jun 2020 21:09:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 05F0B2077D for ; Tue, 23 Jun 2020 21:09:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592946577; bh=viS8a8dmbb9A2GmY90fZ+bNnnJuUqFinGUtzLAZl9+c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=k6wjGwxMln/eURZ94b6JajcGVIW/IFGdHVnH3DkWkZozlxtHK4bd56XlRRy8iQecZ O7qOY8XkLO7VqZ4CaBMwqlcQtl6TcXJTqO2EnVXuLnKwFmNFwcTVQEYIo6+durhJTs YH6NdvMXaNsBzWX2PndvU6au6xK45lcnnoDX0bhY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387729AbgFWVJc (ORCPT ); Tue, 23 Jun 2020 17:09:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:55778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391484AbgFWUeE (ORCPT ); Tue, 23 Jun 2020 16:34:04 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 25C0E20836; Tue, 23 Jun 2020 20:34:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592944444; bh=viS8a8dmbb9A2GmY90fZ+bNnnJuUqFinGUtzLAZl9+c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HEfpTUeLtrbItWWVCNLR+EnnWq7KwdqJ47mgkV50AW1ZmBFNA4x3N6YWxUAIOLXWB ImUSmgHGo8uC50J5PGEyfOOfautQxE0jyhI9oMqIg/vBLIoY6ZzqKs2F1k8eEPOUiK zzHMTSoPFutOLjI6yZVvvqcOf0Z+LpHNQGMTe8ww= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ingo Molnar , "Gustavo A . R . Silva" , Anders Roxell , "Naveen N . Rao" , Anil S Keshavamurthy , David Miller , Ingo Molnar , Peter Zijlstra , Ziqian SUN , Masami Hiramatsu , "Steven Rostedt (VMware)" Subject: [PATCH 5.4 308/314] kprobes: Fix to protect kick_kprobe_optimizer() by kprobe_mutex Date: Tue, 23 Jun 2020 21:58:23 +0200 Message-Id: <20200623195353.691272527@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623195338.770401005@linuxfoundation.org> References: <20200623195338.770401005@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Masami Hiramatsu commit 1a0aa991a6274161c95a844c58cfb801d681eb59 upstream. In kprobe_optimizer() kick_kprobe_optimizer() is called without kprobe_mutex, but this can race with other caller which is protected by kprobe_mutex. To fix that, expand kprobe_mutex protected area to protect kick_kprobe_optimizer() call. Link: http://lkml.kernel.org/r/158927057586.27680.5036330063955940456.stgit@devnote2 Fixes: cd7ebe2298ff ("kprobes: Use text_poke_smp_batch for optimizing") Cc: Ingo Molnar Cc: "Gustavo A . R . Silva" Cc: Anders Roxell Cc: "Naveen N . Rao" Cc: Anil S Keshavamurthy Cc: David Miller Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Ziqian SUN Cc: stable@vger.kernel.org Signed-off-by: Masami Hiramatsu Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- kernel/kprobes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -586,11 +586,12 @@ static void kprobe_optimizer(struct work mutex_unlock(&module_mutex); mutex_unlock(&text_mutex); cpus_read_unlock(); - mutex_unlock(&kprobe_mutex); /* Step 5: Kick optimizer again if needed */ if (!list_empty(&optimizing_list) || !list_empty(&unoptimizing_list)) kick_kprobe_optimizer(); + + mutex_unlock(&kprobe_mutex); } /* Wait for completing optimization and unoptimization */