Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3687661ybv; Mon, 10 Feb 2020 04:43:33 -0800 (PST) X-Google-Smtp-Source: APXvYqySjrkt+acXhy8zMLXP4XOQEaWOAckrQLCNMMHO33rPG0zLTxVH6q9BDeX6UF7r1H8EuRhn X-Received: by 2002:a9d:7386:: with SMTP id j6mr895005otk.336.1581338613306; Mon, 10 Feb 2020 04:43:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581338613; cv=none; d=google.com; s=arc-20160816; b=SsbdvdTqwIfoObmPz/YtI2KqC94tr68xyKpaQKHyYpduF3dCw0VNdEg+RqcKFRxzed lBlCdiYsK5DBYvhkxii5pOHY5l7oUUntvqXzdEwBAo/WJLbmbaw57d5c7KCD9AI9FdX5 9aMrl+hnkvtd4l0YTgA4NinQYeEUeGengW/Yd/j0F6WQwAa1nqIwUgJr0CwU24UKYrAg uRjpohv49Q58jTn81BQ/QoOybOhXQe2DzsIJNrS+P03SIVa57Y2h3sCvDa4voNIfzhEu bg7TKX84dCSi9cODZWbkVdR/Y+drOvPGm1Qxj7q1AmpYu6uDWtTO2ra5uYkC53galOXY 2LvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SRAG49sOpIIq3P3EHgoopiDDQ3/ZMbcu9uaxw6AnApI=; b=eAZv4t5TuotVIiMuNvLkapODOYuXm1eqMuzNSfa9hw+J6+9BsQWEf+e0WxEQHdR7vr 4zBBf2izEhY0Yrxq8Xr0LAS3psgbBG/wlwGSTojqo+Xc6PceSVi8K9nH7xT3iTZKHTuW mI8069fZg0SLJWafjIhreBWdhATRhYO2UMq5ZMJWea4PhxszyZjvpigbslXyxiGdPBGa XVX+In1Lj2xjUZfUh60Gn65X2LdVBPeqjtqBacGhVxlq5mPAOADL8lxTj1WLwof+trsR Cp4mM8POJ1FH/nSK/akiiaEQLkDtde7bvCQJ/O5j+fNhWb1v/6Zkr+NJG3eRb9uSae3i 4NuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HEwSFPLR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d20si118949oti.311.2020.02.10.04.43.21; Mon, 10 Feb 2020 04:43:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HEwSFPLR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730398AbgBJMnL (ORCPT + 99 others); Mon, 10 Feb 2020 07:43:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:38474 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729523AbgBJMjs (ORCPT ); Mon, 10 Feb 2020 07:39:48 -0500 Received: from localhost (unknown [209.37.97.194]) (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 114A02051A; Mon, 10 Feb 2020 12:39:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338388; bh=V4Vj4iXVZCOwvr/0Kky48M0kWDdquu7/d64KrYgidMQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HEwSFPLRijUIIhdmLOVI6nromJx0JCn3VPSY+uBq+ezaAgPF+8uxOSq+ATQ/t1+If Uh9xbIMMDxborcDhU4dSS/jDTLikrtUtTMjxVLEgzUYSjENZ/wQjy5VMRC/2JgLQVB gcxfegPUdTsXCcwU+y+ijCaxpBBARpNjacwNfBQQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Steven Rostedt (VMware)" , "Joel Fernandes (Google)" , Peter Zijlstra , Thomas Gleixner , "Paul E. McKenney" , syzbot+774fddf07b7ab29a1e55@syzkaller.appspotmail.com, Mathieu Desnoyers Subject: [PATCH 5.5 033/367] tracing: Fix sched switch start/stop refcount racy updates Date: Mon, 10 Feb 2020 04:29:06 -0800 Message-Id: <20200210122427.002470141@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mathieu Desnoyers commit 64ae572bc7d0060429e40e1c8d803ce5eb31a0d6 upstream. Reading the sched_cmdline_ref and sched_tgid_ref initial state within tracing_start_sched_switch without holding the sched_register_mutex is racy against concurrent updates, which can lead to tracepoint probes being registered more than once (and thus trigger warnings within tracepoint.c). [ May be the fix for this bug ] Link: https://lore.kernel.org/r/000000000000ab6f84056c786b93@google.com Link: http://lkml.kernel.org/r/20190817141208.15226-1-mathieu.desnoyers@efficios.com Cc: stable@vger.kernel.org CC: Steven Rostedt (VMware) CC: Joel Fernandes (Google) CC: Peter Zijlstra CC: Thomas Gleixner CC: Paul E. McKenney Reported-by: syzbot+774fddf07b7ab29a1e55@syzkaller.appspotmail.com Fixes: d914ba37d7145 ("tracing: Add support for recording tgid of tasks") Signed-off-by: Mathieu Desnoyers Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace_sched_switch.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/kernel/trace/trace_sched_switch.c +++ b/kernel/trace/trace_sched_switch.c @@ -89,8 +89,10 @@ static void tracing_sched_unregister(voi static void tracing_start_sched_switch(int ops) { - bool sched_register = (!sched_cmdline_ref && !sched_tgid_ref); + bool sched_register; + mutex_lock(&sched_register_mutex); + sched_register = (!sched_cmdline_ref && !sched_tgid_ref); switch (ops) { case RECORD_CMDLINE: