Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2843999ybk; Tue, 12 May 2020 09:26:17 -0700 (PDT) X-Google-Smtp-Source: APiQypIbTOueZNJ+U0fj11ytr4TBEzHJLMB9Z+wpZvPlFkcwnCFmoEuRYdwJpJI9NzTFHs865uH0 X-Received: by 2002:a17:906:8152:: with SMTP id z18mr17747973ejw.4.1589300777694; Tue, 12 May 2020 09:26:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589300777; cv=none; d=google.com; s=arc-20160816; b=Xafn2BHWfqY5d7fnJRRvOQdBXeawZvxokxwBiB3rBL9XZ+oGlfseryssjDNRStQVKe h5qt2S9ohRvd3LAbnU8bbaFkr2JO/YNurQKKYbeo/nWewxR2Xog+EaoOdycurq5BxzU7 T8xog537Mr/2BhOctR+bAoN6ag+aDtC9Su1gsX9dxlyVA2U2F3/39B635MByE4n8l9eW ywbxndsztyHiX5NvUQhcLBqMjsXZc153Y+LMMemTN7rquVWRmuJdvuSVrvA3EDDTm6LS Up/znOmdRB4aRAKYe6hZprY76gS9ENOOnO2J1Sc7XQOv8f9iuVtGctcABeklmUDiLkrK tpQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=UEnxThmKo9eCKn9Sp5S//SCIqt2NuliFRLICXjN1F8w=; b=HtOlcAt/k+twpoOFlyk8Xx3Y8OTbzyJWw7t5BdNKcsAPzirwxyx4W8l68UMUn7IXkq QUdmQz3I3SfkuUkSpnXFbp0HjL/WoOpFX/iOYctXg/VrIIbIrbz6OzV6DDDzKyieZ/iU XAb81cUZhZpRP46N3UJA7lV4yTOEse4+35Soc8Rcr2vVBvhpwCY7+JFxzZrCD6lBNgO0 q/M0uBr1e9CI5x3Z1h6BTUd33EOfsdt6CIbcEHzV9qiWI8EdylqHJQrY01sozubCud0w 4xX8vKOsVz6N9bpDNHgkVM4wAHjv2/F2aPLbbZpmyFsI83sB2zZ89dXo0wuJXQaew8zY hi3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="qpJ2/f9j"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l2si4051866edi.237.2020.05.12.09.25.52; Tue, 12 May 2020 09:26:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="qpJ2/f9j"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726891AbgELQWS (ORCPT + 99 others); Tue, 12 May 2020 12:22:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725851AbgELQWR (ORCPT ); Tue, 12 May 2020 12:22:17 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 729C2C061A0C for ; Tue, 12 May 2020 09:22:17 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id g185so14185954qke.7 for ; Tue, 12 May 2020 09:22:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=UEnxThmKo9eCKn9Sp5S//SCIqt2NuliFRLICXjN1F8w=; b=qpJ2/f9jFEw2XCnsQfklOx5O1EFTzceVHfXu1J5e7cHafuTXCDfUb5YnDchiAFVf3s jX+crR2gfyQv5H41/px3hC3d8mYCDhouCowZVS8ZR2Dj7msbcJs+/OAa7zYP3Z3P2tZO au5612/l0fzYXDXwkAO7TOJKK0LaFe81pNNxI1qiP5qaeHGELr1uXlTgF66qkpZQDsHP iFNxirnEGsp23l/WTFAlAkszfOh7yopgd1UpMaNaY9Owii6rSyCyYgYt1WgCqEkwmVxK 6478KCl4hBT/j869nxatLWU+X7EJihyrXYrU+t9IAOe+24XJuiL7iK5VxObMn0tyheZZ k8Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UEnxThmKo9eCKn9Sp5S//SCIqt2NuliFRLICXjN1F8w=; b=MUWLvbYokE+iWoIv+RwkJYwDT6SeV1dbtRF0IXbMxZKa1jw6hSqcE2I8MaDSj/ef8J hCm/yK7Xwbi5wO1lxdKtmgul5sKS//t2iTCahQIMf82UbJxvLZXbrGgNubIwcuZxQYLc BmlwPAJZYlKghgSl+Q2/lyfPpV6F59UG7u5eJ3N+GbATIqNAEpVRjH8GcgNQAGd9Os2m SyGYC612Qh9cemlzTq8lBnOdD1ICJs5Yf1q7IJeZat7s2mZZV/jXD0jyvx0rLydDHV/D wI/UZkZWtMoQu8EeEzDwQrU+2mcOrtQk9A7zJMQfy9RGo8Wb5A6qqjfcpcw5AdjWHVfa Flgg== X-Gm-Message-State: AGi0PuYnmnZef7w/QuqneCFdOBfn6PL1utxB3tAayGZOc2AJ7+TlXfFa WWy3Mt+vKBBTZSiOS6B5dAyRI8qEHbVmA1ix25jzfA== X-Received: by 2002:a37:9d55:: with SMTP id g82mr18935803qke.407.1589300535553; Tue, 12 May 2020 09:22:15 -0700 (PDT) MIME-Version: 1.0 References: <20200511023111.15310-1-walter-zh.wu@mediatek.com> <20200511180527.GZ2869@paulmck-ThinkPad-P72> <1589250993.19238.22.camel@mtksdccf07> <20200512142541.GD2869@paulmck-ThinkPad-P72> <20200512161422.GG2869@paulmck-ThinkPad-P72> In-Reply-To: <20200512161422.GG2869@paulmck-ThinkPad-P72> From: Dmitry Vyukov Date: Tue, 12 May 2020 18:22:04 +0200 Message-ID: Subject: Re: [PATCH v2 1/3] rcu/kasan: record and print call_rcu() call stack To: "Paul E. McKenney" Cc: Walter Wu , Andrey Ryabinin , Alexander Potapenko , Matthias Brugger , Josh Triplett , Mathieu Desnoyers , Lai Jiangshan , Joel Fernandes , Andrew Morton , kasan-dev , Linux-MM , LKML , Linux ARM , wsd_upstream , linux-mediatek@lists.infradead.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 12, 2020 at 6:14 PM Paul E. McKenney wrote: > > > > > > > This feature will record first and last call_rcu() call stack and > > > > > > > print two call_rcu() call stack in KASAN report. > > > > > > > > > > > > Suppose that a given rcu_head structure is passed to call_rcu(), then > > > > > > the grace period elapses, the callback is invoked, and the enclosing > > > > > > data structure is freed. But then that same region of memory is > > > > > > immediately reallocated as the same type of structure and again > > > > > > passed to call_rcu(), and that this cycle repeats several times. > > > > > > > > > > > > Would the first call stack forever be associated with the first > > > > > > call_rcu() in this series? If so, wouldn't the last two usually > > > > > > be the most useful? Or am I unclear on the use case? > > > > > > > > 2 points here: > > > > > > > > 1. With KASAN the object won't be immediately reallocated. KASAN has > > > > 'quarantine' to delay reuse of heap objects. It is assumed that the > > > > object is still in quarantine when we detect a use-after-free. In such > > > > a case we will have proper call_rcu stacks as well. > > > > It is possible that the object is not in quarantine already and was > > > > reused several times (quarantine is not infinite), but then KASAN will > > > > report non-sense stacks for allocation/free as well. So wrong call_rcu > > > > stacks are less of a problem in such cases. > > > > > > > > 2. We would like to memorize 2 last call_rcu stacks regardless, but we > > > > just don't have a good place for the index (bit which of the 2 is the > > > > one to overwrite). Probably could shove it into some existing field, > > > > but then will require atomic operations, etc. > > > > > > > > Nobody knows how well/bad it will work. I think we need to get the > > > > first version in, deploy on syzbot, accumulate some base of example > > > > reports and iterate from there. > > > > > > If I understood the stack-index point below, why not just move the > > > previous stackm index to clobber the previous-to-previous stack index, > > > then put the current stack index into the spot thus opened up? > > > > We don't have any index in this change (don't have memory for such index). > > The pseudo code is" > > > > u32 aux_stacks[2]; // = {0,0} > > > > if (aux_stacks[0] != 0) > > aux_stacks[0] = stack; > > else > > aux_stacks[1] = stack; > > I was thinking in terms of something like this: > > u32 aux_stacks[2]; // = {0,0} > > if (aux_stacks[0] != 0) { > aux_stacks[0] = stack; > } else { > if (aux_stacks[1]) > aux_stacks[0] = aux_stacks[1]; > aux_stacks[1] = stack; > } > > Whether this actually makes sense in real life, I have no idea. > The theory is that you want the last two stacks. However, if these > elements get cleared at kfree() time, then I could easily believe that > the approach you already have (first and last) is the way to go. > > Just asking the question, not arguing for a change! Oh, this is so obvious... in hindsight! :) Walter, what do you think? I would do this. I think latter stacks are generally more interesting wrt shedding light on a bug. The first stack may even be "statically known" (e.g. if object is always queued into a workqueue for some lazy initialization during construction).