From mboxrd@z Thu Jan 1 00:00:00 1970 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=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 BB7C3C33CB1 for ; Thu, 16 Jan 2020 14:44:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 84D5A207E0 for ; Thu, 16 Jan 2020 14:44:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579185865; bh=1ex58SMPt/dCwANUPh78pSMpR2tbb9x2YKco51bZMQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=qAGhGDqIKBiL50fv0oBPGCCneXmf265xOUK4xDalrIhnd232bqyyatQLYobs0xvgF r45gSZ5bVxoSuN2BdT+fnPZZi8hQhlZAK6OAkB30W8kL65RQ5Hk9lkWc/NHZBmvLcj uzXNq0Hm7VQglkSnCF9TIrj2+w/FKk5LbKtQ4XmE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726714AbgAPOoZ (ORCPT ); Thu, 16 Jan 2020 09:44:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:34978 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726189AbgAPOoZ (ORCPT ); Thu, 16 Jan 2020 09:44:25 -0500 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 400312075B; Thu, 16 Jan 2020 14:44:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579185864; bh=1ex58SMPt/dCwANUPh78pSMpR2tbb9x2YKco51bZMQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rTnoQY8wjtY/aiYo/rYUjUWBxfme7CgkCU17FOgpMhJav+b0HeZ7u+phpzVhSrTZv vNo2rY7rkvw3Nt/hpXGCRBjNEZl1r5jwh9D8FBr9Po9KnfuGhNSrNF4QcPjAfg2JAK w9hFpYwfibecuXhmuD+Vz8qne+SVmVCRW2i4irJQ= From: Masami Hiramatsu To: Brendan Gregg , Steven Rostedt , Alexei Starovoitov Cc: mhiramat@kernel.org, Ingo Molnar , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Daniel Borkmann , Arnaldo Carvalho de Melo , "David S . Miller" , paulmck@kernel.org, joel@joelfernandes.org, "Naveen N . Rao" , Anil S Keshavamurthy Subject: [RFT PATCH 01/13] kprobes: Fix to protect kick_kprobe_optimizer() by kprobe_mutex Date: Thu, 16 Jan 2020 23:44:20 +0900 Message-Id: <157918585992.29301.13166378246753856348.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <157918584866.29301.6941815715391411338.stgit@devnote2> References: <157918584866.29301.6941815715391411338.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org 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. Signed-off-by: Masami Hiramatsu --- kernel/kprobes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 5a664f995377..52b05ab9c323 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -592,11 +592,12 @@ static void kprobe_optimizer(struct work_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 */