From patchwork Wed Feb 12 23:39:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 11379361 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CB3C139A for ; Wed, 12 Feb 2020 23:40:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E42032168B for ; Wed, 12 Feb 2020 23:40:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qEAmDJpj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E42032168B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B8F9E6B04CF; Wed, 12 Feb 2020 18:39:59 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B18326B04D1; Wed, 12 Feb 2020 18:39:59 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A05DC6B04D2; Wed, 12 Feb 2020 18:39:59 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0166.hostedemail.com [216.40.44.166]) by kanga.kvack.org (Postfix) with ESMTP id 82FED6B04CF for ; Wed, 12 Feb 2020 18:39:59 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 3AA4E180AD80F for ; Wed, 12 Feb 2020 23:39:59 +0000 (UTC) X-FDA: 76483095318.24.leg68_743daa725482f X-Spam-Summary: 2,0,0,d9fa351297a1c719,d41d8cd98f00b204,minchan.kim@gmail.com,:akpm@linux-foundation.org:linux-kernel@vger.kernel.org::linux-api@vger.kernel.org:oleksandr@redhat.com:surenb@google.com:timmurray@google.com:dancol@google.com:sspatil@google.com:sonnyrao@google.com:bgeffon@google.com:mhocko@suse.com:hannes@cmpxchg.org:shakeelb@google.com:joaodias@google.com:joel@joelfernandes.org:alexander.h.duyck@linux.intel.com:minchan@kernel.org:oleg@redhat.com,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1534:1540:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3868:3872:4321:5007:6261:6653:6742:7901:7903:10004:11658:11914:12296:12297:12517:12519:12555:12895:13069:13311:13357:13894:14096:14181:14384:14394:14721:21080:21444:21451:21627:21990:30054:30069,0,RBL:209.85.215.196:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL: 0,DNSBL: X-HE-Tag: leg68_743daa725482f X-Filterd-Recvd-Size: 4384 Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Wed, 12 Feb 2020 23:39:58 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id l24so2042835pgk.2 for ; Wed, 12 Feb 2020 15:39:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5FaTihNB0iO6aVJlFQnliVUDjcHxSy/v5NwxGrH8kEI=; b=qEAmDJpjHq1/SDf6Xx5QnzwOEfkQzfaAAuSuJ0sR01YF0yYlVoCLxLOOwV+QGxC1A6 At4V57OeHDRLTUEM5vf09xAy2F5SvJ+57jVcDXKUcwcDgz1ol2m6zScXLJG7OoSu3BWF AsNMxbhzRVlrb5IdNChiSE0Z5R7G10ipo2dnSqTIuSy26l/Yc2Wca1lHimE+eQw7dL3a EFrmpjflcH51ALHlyIJ+xp3f9nuMS3HRz/Nsr/RFsucD8oolwMZuMwHYxV+TxNob5BwB ZmiX8UPIf3vovj+TMAhkkQCfjW1LXhJX+AyqoPTtIQCxX3ctHrDxmuSA3VhkddJQeDAj Gz1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=5FaTihNB0iO6aVJlFQnliVUDjcHxSy/v5NwxGrH8kEI=; b=DBbSt5OVUd66t0rQd7rD4xzoM4Vj/3Zn5RGktxvmrH0qMmOBLS70YMRXl2b23hPIuy pUR2AL0rS6RdQIfK/KfBVTJKCQqQKCH9pOYkIPSvrwebYrOeQWm7xTIYSdHg1iU0LJ0a GG/h8QXXTmhdRHX0oBm7Z940NbA8xYmPXyAFVV3nrwnk4r0WVTOyQjpRLN/Zemrcrs1u 9JTRDmsEYmc0gOKBmPWZFX3EPWsrwLs/gcDjyTOKTOG0HBqBCJknzi+lJK/Vj5gOUaMy fN/BsUoXoVt0ULJ6lTM73tNm/oxsIVP5YN1slgmhqh+XTRs/Jms4gze8hNzUZ0uMbIsN p7iQ== X-Gm-Message-State: APjAAAWVgf1aPt4SUrLVzMMwRq7lQhfgU6O9dNABl7CCtOPmoZSF845W QDqVTRRcIg5KvZxI92xu31Y= X-Google-Smtp-Source: APXvYqwUgswxPMoz82nKSTevATYCfitBRedBrE6cghsT9OKRaDZWTkOVO5apq4PKzc/j/CtkDUG47w== X-Received: by 2002:a63:3c08:: with SMTP id j8mr15003128pga.223.1581550797747; Wed, 12 Feb 2020 15:39:57 -0800 (PST) Received: from bbox-1.mtv.corp.google.com ([2620:15c:211:1:3e01:2939:5992:52da]) by smtp.gmail.com with ESMTPSA id k5sm296664pju.29.2020.02.12.15.39.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2020 15:39:56 -0800 (PST) From: Minchan Kim To: Andrew Morton Cc: LKML , linux-mm , linux-api@vger.kernel.org, oleksandr@redhat.com, Suren Baghdasaryan , Tim Murray , Daniel Colascione , Sandeep Patil , Sonny Rao , Brian Geffon , Michal Hocko , Johannes Weiner , Shakeel Butt , John Dias , Joel Fernandes , Alexander Duyck , Minchan Kim , Oleg Nesterov Subject: [PATCH v4 3/8] mm: validate mm in do_madvise Date: Wed, 12 Feb 2020 15:39:41 -0800 Message-Id: <20200212233946.246210-4-minchan@kernel.org> X-Mailer: git-send-email 2.25.0.225.g125e21ebc7-goog In-Reply-To: <20200212233946.246210-1-minchan@kernel.org> References: <20200212233946.246210-1-minchan@kernel.org> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Oleg pointed out mm could be nulllified right after mm_access succeeds. This patch validates it before the using. Cc: Oleg Nesterov Signed-off-by: Minchan Kim --- mm/madvise.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/madvise.c b/mm/madvise.c index 8611f1d39289..bb04c7897eb9 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1073,7 +1073,11 @@ int do_madvise(struct task_struct *task, unsigned long start, int write; size_t len; struct blk_plug plug; - struct mm_struct *mm = task->mm; + struct mm_struct *mm = READ_ONCE(task->mm); + + /* task can exit and nullify its ->mm right after mm_access() */ + if (!mm) + return -ESRCH; start = untagged_addr(start);