Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp153664img; Sun, 17 Mar 2019 23:25:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqbO9yv4YBWa5R6z2s52Xkgjv+oL2mo2/1D363ykHVhPlFhq1xX7TafNXesg4IXfTuY72+ X-Received: by 2002:a17:902:d715:: with SMTP id w21mr17658054ply.14.1552890335282; Sun, 17 Mar 2019 23:25:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552890335; cv=none; d=google.com; s=arc-20160816; b=Qf0T6VVq6GnjTm8kRquq0hwXPMkbIvQrO3lba5wmqkHkZKXJZ1ZVV8ildnuHZuWQeH nOYcgdt5fGMOvqW7x2KVm/TNRLZmCum8tiyo7vVnBWu4cbW895QkHgW80viKW5gzWepj ceebzJq/torOrA26qEJSobKXOK7q3Exh1q6sPWihHWGD6oKQVFYrIakIzqg+qC9q+yo2 th775ZVp95+bq0LnBjnLBULFjF7zp60LKNej0P5K90dRoU5KYDI438vf1nM9k0jx9tXH fSRc5owwmn34Jw4fYhe4QvYOevNzB1uvInZpQ2qBR9K/6+76tO78Ovn1FuQ/p++Tl16K 7ueg== 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:in-reply-to :references:subject:cc:to:mime-version:user-agent:from:date :message-id; bh=ZB9nJsDpKa1+tc/kynrz0Fmj61kcN4tZlEWpMXssfxY=; b=JDU65vK3b7AkENSj1l2+awIk1NJKTHwlDmZKEY8SXJz85f9k6DORrgBdTrFR4QYY69 G/oU7h5+AlOB+1K17SySDVSHT5qIPMRH00Wk5fczxqL5ku45Zy2ATwxujoVJ/PKp5Efu +IkhoxCJf+6nPeGy4NyuCCj132X8XliMjfdYsLLEcWJFNZz46QbFamYFhsovFP+m67iA fDRWEW0eWTMpOFQ4dw94s48xZpyTTHwVv6UNlxsUt1f8LiYtyF25hisYtFTaGAbP1Iee meb5WZHFqoWXLgLYJJ210dEaHxPOchCwS+APuabXoSqNAHBo//yyXvKyNpcPCAhaJIq1 BQNQ== ARC-Authentication-Results: i=1; mx.google.com; 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 g22si4748907pgg.525.2019.03.17.23.25.19; Sun, 17 Mar 2019 23:25:35 -0700 (PDT) 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; 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 S1727818AbfCRGXj (ORCPT + 99 others); Mon, 18 Mar 2019 02:23:39 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:42702 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726646AbfCRGXj (ORCPT ); Mon, 18 Mar 2019 02:23:39 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id CD773565038434D6CCAB; Mon, 18 Mar 2019 14:23:36 +0800 (CST) Received: from [127.0.0.1] (10.177.29.68) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.408.0; Mon, 18 Mar 2019 14:23:34 +0800 Message-ID: <5C8F3965.2050202@huawei.com> Date: Mon, 18 Mar 2019 14:23:33 +0800 From: zhong jiang User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: Andrea Arcangeli CC: Mike Rapoport , Peter Xu , Andrew Morton , Dmitry Vyukov , syzbot , Michal Hocko , , Johannes Weiner , LKML , Linux-MM , syzkaller-bugs , Vladimir Davydov , David Rientjes , Hugh Dickins , Matthew Wilcox , Mel Gorman , Vlastimil Babka Subject: Re: KASAN: use-after-free Read in get_mem_cgroup_from_mm References: <5C7D2F82.40907@huawei.com> <5C7D4500.3070607@huawei.com> <5C7E1A38.2060906@huawei.com> <20190306020540.GA23850@redhat.com> <5C821550.50506@huawei.com> <20190315213944.GD9967@redhat.com> <5C8CC42E.1090208@huawei.com> <20190316194222.GA29767@redhat.com> In-Reply-To: <20190316194222.GA29767@redhat.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.29.68] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/3/17 3:42, Andrea Arcangeli wrote: > On Sat, Mar 16, 2019 at 05:38:54PM +0800, zhong jiang wrote: >> On 2019/3/16 5:39, Andrea Arcangeli wrote: >>> On Fri, Mar 08, 2019 at 03:10:08PM +0800, zhong jiang wrote: >>>> I can reproduce the issue in arm64 qemu machine. The issue will leave after applying the >>>> patch. >>>> >>>> Tested-by: zhong jiang >>> Thanks a lot for the quick testing! >>> >>>> Meanwhile, I just has a little doubt whether it is necessary to use RCU to free the task struct or not. >>>> I think that mm->owner alway be NULL after failing to create to process. Because we call mm_clear_owner. >>> I wish it was enough, but the problem is that the other CPU may be in >>> the middle of get_mem_cgroup_from_mm() while this runs, and it would >>> dereference mm->owner while it is been freed without the call_rcu >>> affter we clear mm->owner. What prevents this race is the >> As you had said, It would dereference mm->owner after we clear mm->owner. >> >> But after we clear mm->owner, mm->owner should be NULL. Is it right? >> >> And mem_cgroup_from_task will check the parameter. >> you mean that it is possible after checking the parameter to clear the owner . >> and the NULL pointer will trigger. :-( > Dereference mm->owner didn't mean reading the value of the mm->owner > pointer, it really means to dereference the value of the pointer. It's > like below: > > get_mem_cgroup_from_mm() failing fork() > ---- --- > task = mm->owner > mm->owner = NULL; > free(mm->owner) > *task /* use after free */ > > We didn't set mm->owner to NULL before, so the window for the race was > larger, but setting mm->owner to NULL only hides the problem and it > can still happen (albeit with a smaller window). > > If get_mem_cgroup_from_mm() can see at any time mm->owner not NULL, > then the free of the task struct must be delayed until after > rcu_read_unlock has returned in get_mem_cgroup_from_mm(). This is > the standard RCU model, the freeing must be delayed until after the > next quiescent point. Thank you for your explaination patiently. The patch should go to upstream too. I think you should send a formal patch to the mainline. Maybe other people suffer from the issue. :-) Thanks, zhong jiang > BTW, both mm_update_next_owner() and mm_clear_owner() should have used > WRITE_ONCE when they write to mm->owner, I can update that too but > it's just to not to make assumptions that gcc does the right thing > (and we still rely on gcc to do the right thing in other places) so > that is just an orthogonal cleanup. > > Thanks, > Andrea > > . >