Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp128125pxf; Wed, 17 Mar 2021 17:32:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQZw8uiiWNNnDM1kRm5EDgc0hxiGS4OPnroHkswmlkIUTDJoTae7/IKIndGCTm5dkD8nmC X-Received: by 2002:a05:6402:160e:: with SMTP id f14mr412385edv.45.1616027568456; Wed, 17 Mar 2021 17:32:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616027568; cv=none; d=google.com; s=arc-20160816; b=DO58eJJ82gXySqK4DPAnafmJW39Pv8kl8/j+0iCWCP8QUGGG7eOQbPUOQyICtQLlQ4 uBjWm8dwM+5KBbBUNeqOrHPqseG8uF1VG7dalNRWTTrtg8lUwlPE9WsPkzomiI3jbYJ4 sztRn8MErQ0Z2KFQu560SrXcTz6GyF8RINtWmOfJhbx/klSnoJgVjETMFK3AWj/w8NFt OmXKOKN7DOH/r94g24/IflMn7JUl0vsOBI8886j8Nc9yXvs5BYAFYDhj4QUp3ge/TRHI jugYr0qca0HRiYxavqcXh3aN05VDoDX7PU/QpHPjo4vyJDpY9iucdrFlrEmDMkbRfVte fK1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=GkuRWpW9bExkYFxOTvvebzKRarhbJmzTDiFRajMJb68=; b=AxPz1qqmN4DyyzE87cjPskpyRMr/xnNmFN5qvQnFsRw7FAoApdMQ8UvihmRdEW6vdJ REqLsrBy2RTGi9jtLApQVyuDNWr0qEgPI8ibTlNV5suBSacNWI5oy/vMLisL7PYdGzXo 9MiKAckkWWX1v5i7EPSd27utF/D0Kj1N+U+ZyZBa4bsCMmObpRQ5lWlZudoPb0m8mFwx TRkLRVbxeGu6r3btN82ywQkt3G1Ca+MwFzLu2Q9WvITzQp53GgZ39g7TyED+/fsKhr9X NLMY9Oapg0myMJujlBgAKCh9BDZLBnlF2CuvY/x9sk09nuOyFMrmetoZc6qBPTDhjere v8MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Tw1JOhx9; 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 ge14si279100ejb.716.2021.03.17.17.32.24; Wed, 17 Mar 2021 17:32:48 -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=Tw1JOhx9; 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 S229766AbhCRAb2 (ORCPT + 99 others); Wed, 17 Mar 2021 20:31:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbhCRAa7 (ORCPT ); Wed, 17 Mar 2021 20:30:59 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A577C06174A for ; Wed, 17 Mar 2021 17:30:59 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id w8so1994976pjf.4 for ; Wed, 17 Mar 2021 17:30:59 -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=GkuRWpW9bExkYFxOTvvebzKRarhbJmzTDiFRajMJb68=; b=Tw1JOhx9WMaxj2zgL2+u0rROy7M24TONLFY0jAeGeUZ8wvui68EopwXxn0qUW0MLd0 7wDivc0uuetGtGIEBWlrqWFTBrilHFV2627ljgT263GE3RoDzgfyK5e5EBpYudqtz3dd /GlEBbuxEmry+CKUqSgiqaef06Dd3YyED+Uy8aI1BWqYM3LFXERUI3TDN2+wCbHzSCrC kocqgtsBmdIspMmdXpz5DCNo6LQRcOt+khcnBdBCVCCRtYuHidggrt5eRg0wTtuaDlgX W3kktFufFg0ZZSamAU5eWzJAmxbxOAlnl292ZmodwTRQBmd9GRSUIOVk5WemXVV5R2pn lMmQ== 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=GkuRWpW9bExkYFxOTvvebzKRarhbJmzTDiFRajMJb68=; b=KGgIqHzNkgyywXX+7H+mf3tM6JGwS0p3TDNNBmAW8sFxI1Bn+i5idJWbVLjuoyyD/m UmAjmiiKA4XLoSnK7gW0P+D23iBuMwHVWSBvUL4QuCAXpKHYVQFXF0Rq2qrlDW2SDnDB 70C2I8Lr2n3SqBs91CfKzo4WlZiQ6b0wegtbnD/X0lTf1vAUcRFgubbXbMz0QlEph8BD gfuRKdFmjCfMj4yU61nwNHDCNejWmKzNhCZodADRNzjHbHjXrEUTlf4HSUL0TJYY0vuP E6c9RS0eD8oWQYUrKKmtofig4PFzOlxLDKtJNKmo7sP+NDDHU/N61ZS4ZjqvQea0en7E kCcg== X-Gm-Message-State: AOAM530pQF2oTEOzFEG0HJzG5yhAj4xIK06zID/fScHzSHO37zGXPZ9y d0GS2xmHaMaWlCqthh11fOul+vbUKdoYTyItV9UcAg== X-Received: by 2002:a17:90a:a10c:: with SMTP id s12mr1413387pjp.166.1616027458725; Wed, 17 Mar 2021 17:30:58 -0700 (PDT) MIME-Version: 1.0 References: <20210316024410.19967-1-walter-zh.wu@mediatek.com> In-Reply-To: <20210316024410.19967-1-walter-zh.wu@mediatek.com> From: Andrey Konovalov Date: Thu, 18 Mar 2021 01:30:47 +0100 Message-ID: Subject: Re: [PATCH v2] task_work: kasan: record task_work_add() call stack To: Walter Wu Cc: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Matthias Brugger , Andrew Morton , Jens Axboe , Oleg Nesterov , kasan-dev , Linux Memory Management List , LKML , Linux ARM , wsd_upstream , "moderated list:ARM/Mediatek SoC..." Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 16, 2021 at 3:44 AM Walter Wu wrote: > > Why record task_work_add() call stack? > Syzbot reports many use-after-free issues for task_work, see [1]. > After see the free stack and the current auxiliary stack, we think > they are useless, we don't know where register the work, this work > may be the free call stack, so that we miss the root cause and > don't solve the use-after-free. > > Add task_work_add() call stack into KASAN auxiliary stack in > order to improve KASAN report. It is useful for programmers > to solve use-after-free issues. > > [1]: https://groups.google.com/g/syzkaller-bugs/search?q=kasan%20use-after-free%20task_work_run > > Signed-off-by: Walter Wu > Suggested-by: Dmitry Vyukov > Cc: Andrey Konovalov > Cc: Andrey Ryabinin > Cc: Dmitry Vyukov > Cc: Alexander Potapenko > Cc: Andrew Morton > Cc: Matthias Brugger > Cc: Jens Axboe > Cc: Oleg Nesterov > --- > > v2: Fix kasan_record_aux_stack() calling sequence issue. > Thanks for Dmitry's suggestion > > --- > kernel/task_work.c | 3 +++ > mm/kasan/kasan.h | 2 +- > 2 files changed, 4 insertions(+), 1 deletion(-) > > diff --git a/kernel/task_work.c b/kernel/task_work.c > index 9cde961875c0..3d4852891fa8 100644 > --- a/kernel/task_work.c > +++ b/kernel/task_work.c > @@ -34,6 +34,9 @@ int task_work_add(struct task_struct *task, struct callback_head *work, > { > struct callback_head *head; > > + /* record the work call stack in order to print it in KASAN reports */ > + kasan_record_aux_stack(work); > + > do { > head = READ_ONCE(task->task_works); > if (unlikely(head == &work_exited)) > diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h > index 3436c6bf7c0c..e4629a971a3c 100644 > --- a/mm/kasan/kasan.h > +++ b/mm/kasan/kasan.h > @@ -146,7 +146,7 @@ struct kasan_alloc_meta { > struct kasan_track alloc_track; > #ifdef CONFIG_KASAN_GENERIC > /* > - * call_rcu() call stack is stored into struct kasan_alloc_meta. > + * The auxiliary stack is stored into struct kasan_alloc_meta. > * The free stack is stored into struct kasan_free_meta. > */ > depot_stack_handle_t aux_stack[2]; > -- Acked-by: Andrey Konovalov