Received: by 2002:ac0:950e:0:0:0:0:0 with SMTP id f14csp48342imc; Fri, 15 Mar 2019 14:40:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqyRRhabRBu+AFB5RRxTCBqiuHriNkmOnYMMP5vL+gWieYekJF0ivhve84GuJtSoUGoYT4ny X-Received: by 2002:a63:d509:: with SMTP id c9mr5616127pgg.2.1552686043549; Fri, 15 Mar 2019 14:40:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552686043; cv=none; d=google.com; s=arc-20160816; b=e9v8ujSE9VlDx410ReJsjO254Y7oY5cqVqbil6bpDOkpEFtv4pjL0JNQLqoaUTAbQy OrZ9K+g1TTt4yk8uj4FrPvwvkTytSMp2QixVKflaBk17kFOc4D43Z2GUl7q+iqEuFS/I d6JSjLcNb/jliFVZCawN9zb9apzy36LX5AxC/qzyVcxvrsPV/z8kkYpLmVW8FON5nhOP R5L7Qbtq2MsR7z+FzraMCL1estILw2lqsVpit4E0+/qSRv5+ONLcCpaktImg3xMSbcN/ iOwMkE+e/DJg0zlHqmLfG7GUcnAfDgQkNjylI1xSVWZSJIAg0bzGqaBuCuO3CpoTVqHC BX5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=swqwZha9BXWgetb1NNjrOQQKfGmgkrLsd+O2BNX0Vag=; b=EA7nTlgoEWZ2S9nxLf+63MfgVUkVc05cIC6eJy6kgreHMOMXJ0fs9hCqx2TvZkYAPm vwMYhptiL4D8RC1npvzErNMhdZP8817D1rjZqUkK92RU3xQ+n8MhU9UwpteOVz7Ppk0P bqCnPbdF3u6iA+Y4f6vmTfqaPXM3en/SKNwKaVCZM7AcnqVwChei1m3vPAehD3z8A3p3 2cy8sirtqxHXer7kXFR43X3U8eJLVmtMoiWwn26Pd31qrQMoy9PmXLHAuBSti81kWt7W UfmjxUtNEG8D/0p2tjbBMUV8gt7dBlMB+Pl0h/8iYDNOkhZM6El7YPs8yqvcvmVvUs5o r0LQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 34si2705745pgs.553.2019.03.15.14.40.27; Fri, 15 Mar 2019 14:40:43 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726315AbfCOVjs (ORCPT + 99 others); Fri, 15 Mar 2019 17:39:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34084 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725959AbfCOVjs (ORCPT ); Fri, 15 Mar 2019 17:39:48 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D20D93082B40; Fri, 15 Mar 2019 21:39:47 +0000 (UTC) Received: from sky.random (ovpn-121-1.rdu2.redhat.com [10.10.121.1]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A36055D6A6; Fri, 15 Mar 2019 21:39:45 +0000 (UTC) Date: Fri, 15 Mar 2019 17:39:44 -0400 From: Andrea Arcangeli To: zhong jiang Cc: Mike Rapoport , Peter Xu , Andrew Morton , Dmitry Vyukov , syzbot , Michal Hocko , cgroups@vger.kernel.org, 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 Message-ID: <20190315213944.GD9967@redhat.com> References: <00000000000006457e057c341ff8@google.com> <5C7BFE94.6070500@huawei.com> <5C7D2F82.40907@huawei.com> <5C7D4500.3070607@huawei.com> <5C7E1A38.2060906@huawei.com> <20190306020540.GA23850@redhat.com> <5C821550.50506@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5C821550.50506@huawei.com> User-Agent: Mutt/1.11.4 (2019-03-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 15 Mar 2019 21:39:48 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 rcu_read_lock() in get_mem_cgroup_from_mm() and the corresponding call_rcu to free the task struct in the fork failure path (again only if CONFIG_MEMCG=y is defined). Considering you can reproduce this tiny race on arm64 qemu (perhaps tcg JIT timing variantions helps?), you might also in theory be able to still reproduce the race condition if you remove the call_rcu from delayed_free_task and you replace it with free_task.