Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4242107imu; Mon, 7 Jan 2019 18:58:31 -0800 (PST) X-Google-Smtp-Source: ALg8bN5WcJ7aVilnPWVaZwotONWieEF8SAJAmrR+dVRjGYyuGTnXhFzLcmgxQvRXM9V9k1cbJIrx X-Received: by 2002:a63:5518:: with SMTP id j24mr29791pgb.208.1546916311658; Mon, 07 Jan 2019 18:58:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546916311; cv=none; d=google.com; s=arc-20160816; b=QUYgVUdKJXV5nocbGmFSWAmN5vuNeAV6stxfVuY0QSM6kCTpq3DnWqTPtkb2kRk84Y 92HBqPCbffDvWy+BTrKk18DHwUNV9hAekFoxnqTsZhBWBcsSIuyPxJ2NRSj7LuQzr6a2 xQprBz9+0Eu+qnzSA8uVtLd9gvf6hNLm7ClRR+KnoD4S2czImDgV4IQuqkd5WPLee7yy RnmlZdVrqmcMOxUwTjKFR+1eVn9hILVNaknxTEo5Vl1gDa7uCeD/XGOYtF6GbI1jXoA1 UHPQ+sWqJSQ4PsMYAQl7tnLO7nAlu1WJuC5ikMI7Mn+OZ8RiZVy7iz6gZqOqzcJ4jro1 TPrg== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=y9ObTv9VZKWeig/ErXe4abXp+OIC5NZ4BD4vITYH84o=; b=TWqtC6fG2/uccadjkSSROyJ2J8kXFJ1mX9TU18HlLP63TutkceGGtbao/My/c6UvFz 1IWBkLVemRT34/lqoUOpnF5bs4Trk8nTlBfAdzwwg5doKSoWad4AMbkTOvzwVXN7Vwbt fk25ojMR9HJaVVpK42Hi3huxwp3In0nLt5KNly3q1NWkFQpwujDg8evks8qfoS8m4OUT TCDty9Ai8U9wJdGZl7DMLOuklK8KVVNh7cgJzPgFo1mItx8wvmLeHrUEQRzPSFOFjwTg 5LBesNqCYkLomFvPggF7+RVjR/nzdO1C3gqRjfWNDWA45cl7kMBlHtg2pv0pSxO7RRq3 tRVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="u8P0PAW/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f34si58888677pgm.318.2019.01.07.18.58.15; Mon, 07 Jan 2019 18:58:31 -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="u8P0PAW/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727367AbfAHC4w (ORCPT + 99 others); Mon, 7 Jan 2019 21:56:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:56826 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727030AbfAHC4w (ORCPT ); Mon, 7 Jan 2019 21:56:52 -0500 Received: from devbox (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (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 439082085A; Tue, 8 Jan 2019 02:56:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546916211; bh=RIjbtEa8XyNcF5cd/yVs6e2GBQFmZDCFZEqeQLa4pig=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=u8P0PAW/RRqUmbTXk58EquKmWXA3NNhna4JvA4PxLKQPKnAi/K/5QHnXQS1v6LMMw qCZHRBeIPpWfuyvmg6Y63VCJaJ8Akwv/bhwbP6n5BeVYZubyci3h8WVimw64wBzOip K+aTuWsp+52eaID1nKg2++3ivp/UdQlzeFa/e9bU= Date: Tue, 8 Jan 2019 11:56:48 +0900 From: Masami Hiramatsu To: Andrea Righi Cc: Steven Rostedt , Masami Hiramatsu , Ingo Molnar , peterz@infradead.org, Mathieu Desnoyers , linux-kernel Subject: Re: [PATCH 0/2] kprobes: Fix kretprobe incorrect stacking order problem Message-Id: <20190108115648.5ecf625bf5477ad3f3148b80@kernel.org> In-Reply-To: <20190107213439.GD5966@xps-13> References: <154686789378.15479.2886543882215785247.stgit@devbox> <20190107183444.GA5966@xps-13> <20190107142749.34231bb6@gandalf.local.home> <20190107195209.GB5966@xps-13> <20190107145918.407b851b@gandalf.local.home> <20190107211904.GC5966@xps-13> <20190107162833.1e034fc7@gandalf.local.home> <20190107213439.GD5966@xps-13> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andrea and Steve, On Mon, 7 Jan 2019 22:34:39 +0100 Andrea Righi wrote: > On Mon, Jan 07, 2019 at 04:28:33PM -0500, Steven Rostedt wrote: > > On Mon, 7 Jan 2019 22:19:04 +0100 > > Andrea Righi wrote: > > > > > > > If we put a kretprobe to raw_spin_lock_irqsave() it looks like > > > > > kretprobe is going to call kretprobe... > > > > > > > > Right, but we should be able to add some recursion protection to stop > > > > that. I have similar protection in the ftrace code. > > > > > > If we assume that __raw_spin_lock/unlock*() are always inlined a > > > > I wouldn't assume that. > > > > > possible way to prevent this recursion could be to use directly those > > > functions to do locking from the kretprobe trampoline. > > > > > > But I'm not sure if that's a safe assumption... if not I'll see if I can > > > find a better solution. > > > > All you need to do is have a per_cpu variable, where you just do: > > > > preempt_disable_notrace(); > > if (this_cpu_read(kprobe_recursion)) > > goto out; > > this_cpu_inc(kprobe_recursion); > > [...] > > this_cpu_dec(kprobe_recursion); > > out: > > preempt_enable_notrace(); > > > > And then just ignore any kprobes that trigger while you are processing > > the current kprobe. > > > > Something like that. If you want (or if it already happens) replace > > preempt_disable() with local_irq_save(). > > Oh.. definitely much better. I'll work on that and send a new patch. > Thanks for the suggestion! Thank you for pointing it out, Since we already have current_kprobe per_cpu, it can be done by setting up a dummy kprobe on it. I'll add that in v2 series. Actually, this bug has been introduced a long time ago by me... when I introduced asm-coded kretprobe-trampoline. Before that, kretprobe trampoline handler uses a kprobe to hook it, so the 2nd kretprobe must be skipped automatically. Thank you, -- Masami Hiramatsu