Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1734551pxu; Fri, 16 Oct 2020 22:34:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvC7G81U4bVrEPJnOuDwct81CNRhqdMr4TP58mjtDUMnLEa1UGIJE35+DVGyzOpXQBwREZ X-Received: by 2002:a50:85c6:: with SMTP id q6mr8018270edh.126.1602912878000; Fri, 16 Oct 2020 22:34:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602912877; cv=none; d=google.com; s=arc-20160816; b=PEOWHHtltyUSWp5Nm2P05Xa1BbACkXhWkiZm6utD6qtMdOH57uBs1DA2M/UC6FVISb 9vtYNVTTC5QEiELrOtGlIwERY7o71iL21VtAyQI78IJSYFuvFX0t//TXhMDmnlb27dgs ZyG2RQD6h3RMIs59K7C3tn4FMmTkKImOr5CaX6cn8NxrFH3CAE08ZhINopisKVQKK7VG weFVzAb3ug1Pb4/JiUfs/6nj8HKwWcDIgu4JhnxhWX6ghg+AnxSSqg2pN20SdA/nxfuJ Go/rZb5ZFJuMD+Tr/dQXULBAgYew9nkkjrCyLDUQ7FJEMEE47FhQiXc8YeEGLIunqXir HcLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZqE9YT9elxKHcuMev0eqxdSAa29MOpdvFBgbgr/Dw4c=; b=OAKxgBDWI8JP1r9NC73K0CV5gFg9hmwmynBxnvi4Vvs06+OWsTH5QG/mpyYXIhjZ+b dOGRCkcz3TAsKuUN9zz5taCUMdjquiQ+Nvp9zn3BfcbMHg+aAQeQiTWd7M20gSfPWPdk OEzPGF8lvAW5DR9goAWhzX5cJf/WgpJNKklRsjSCR1xQ/LvthgMOrYShXc2KpkQjSvd6 50sNcEyoQ4XteGCdHXW47LIFK1YASQKpS3b3f11RHHi0NsEqWQN3Em7p+8sd/dOttOpT o9QuVaE/ep8mN0UhN13mR/t41TnqsQpYMYY2N7UtkxUzWEFAtjxtEWSmRjUTyGypqCzz gYBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LhDuPgRe; 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 s26si3179793eds.49.2020.10.16.22.34.15; Fri, 16 Oct 2020 22:34:37 -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=LhDuPgRe; 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 S2409171AbgJPXJ4 (ORCPT + 99 others); Fri, 16 Oct 2020 19:09:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408340AbgJPXJs (ORCPT ); Fri, 16 Oct 2020 19:09:48 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 192F3C0613D3 for ; Fri, 16 Oct 2020 16:09:46 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id n6so4822058wrm.13 for ; Fri, 16 Oct 2020 16:09:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZqE9YT9elxKHcuMev0eqxdSAa29MOpdvFBgbgr/Dw4c=; b=LhDuPgReRaskA4lZJUuE4meGMw+AgSOBWcN0nqcL7KFy86acDGi8um3oRgd5CDOyyW bJFG22PeRLjTWFTU0ukD0tLvCbDgdbDFYPyGitxBgX1xKbXiv598o0EuHa9yELSghqKw VA4T4kdrHVqd88Cs852iMYBnFRMpkx301IXdoi39KfAj+zcBhsCDBtvTEc8dT3mQEW7T 7cylEg7GMWupAk7aZgn16x9jAZeU8zBSiMABrBnBpXTYtig7uF8ZJ7QptnUymL6udJDm sSK7gfMVEBYedaoF17S5Y2Kt1jq2Ee3Ymywe0au8W2vWFh7Kb2xhY8Sfp9vAdq5IO04Z rTDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZqE9YT9elxKHcuMev0eqxdSAa29MOpdvFBgbgr/Dw4c=; b=rDAFlsBL9gnhueEfUlhHVK0gLMWaqL5W2jE+A+dp5Bt2JoYAcwpf8jg9SisjfkWfWS 5B756Qma4hF669FApJmMYP0X8W+Ux2vKdWBMMw5/0SbloTBJh+OMVnvBpoJ5HyZbOmLv XWrNz7E6EHc2V6pFyWS3G0LApubsil2mqop3CbcCcAcbxeEvN+BG84bNzScgKsit1rei rhM8fSMGAW6t2xjtGQuLU7g9Tu2EHW3v6/SYyloYEN15qCB4jaghvoDatXibH1wkKsK4 ayecmW+QM7e0YkvrJE24w1J0czbVNgPtUuVcE5AcMTSpBDJiER7umedyG0Ivw41lj4uI APqw== X-Gm-Message-State: AOAM531hmw7StzltALHAvs/1FegldrgJnhNMaxTelPYd0QJDJQqAZL3a +flsGEN5bUBDi3RR4fNIYKGReA== X-Received: by 2002:a5d:4b49:: with SMTP id w9mr7015093wrs.41.1602889784661; Fri, 16 Oct 2020 16:09:44 -0700 (PDT) Received: from localhost ([2a02:168:96c5:1:55ed:514f:6ad7:5bcc]) by smtp.gmail.com with ESMTPSA id v17sm6144214wrc.23.2020.10.16.16.09.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Oct 2020 16:09:44 -0700 (PDT) From: Jann Horn To: Andrew Morton , linux-mm@kvack.org, Eric Biederman , Oleg Nesterov Cc: linux-kernel@vger.kernel.org, Will Deacon , Kees Cook , Ingo Molnar Subject: [RFC PATCH resend 5/6] ptrace: Use mm_ref() for ->exit_mm Date: Sat, 17 Oct 2020 01:09:14 +0200 Message-Id: <20201016230915.1972840-6-jannh@google.com> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog In-Reply-To: <20201016230915.1972840-1-jannh@google.com> References: <20201016230915.1972840-1-jannh@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We only use ->exit_mm to look up dumpability and the ->user_mm; we don't need to keep the PGD alive for this. mmgrab() is also inconvenient here, because it means that we need to use mmdrop_async() when dropping the reference to the mm from an RCU callback. Use mm_ref() instead of mmgrab() to make things neater. Signed-off-by: Jann Horn --- kernel/exit.c | 2 +- kernel/fork.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index 97253ef33486..03ba6d13ef1e 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -476,7 +476,7 @@ static void exit_mm(void) /* more a memory barrier than a real lock */ task_lock(current); current->mm =3D NULL; - mmgrab(mm); /* for current->exit_mm */ + mm_ref(mm); /* for current->exit_mm */ current->exit_mm =3D mm; mmap_read_unlock(mm); enter_lazy_tlb(mm, current); diff --git a/kernel/fork.c b/kernel/fork.c index 59c119b03351..4383bf055b40 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -720,7 +720,7 @@ void free_task(struct task_struct *tsk) if (tsk->flags & PF_KTHREAD) free_kthread_struct(tsk); if (tsk->exit_mm) - mmdrop_async(tsk->exit_mm); + mm_unref(tsk->exit_mm); free_task_struct(tsk); } EXPORT_SYMBOL(free_task); --=20 2.29.0.rc1.297.gfa9743e501-goog