From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58BB2C433E1 for ; Wed, 19 Aug 2020 18:04:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1B7BD20658 for ; Wed, 19 Aug 2020 18:04:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Dm12xVmM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1B7BD20658 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CB82E8D0049; Wed, 19 Aug 2020 14:04:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C68038D0002; Wed, 19 Aug 2020 14:04:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7D7A8D0049; Wed, 19 Aug 2020 14:04:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0069.hostedemail.com [216.40.44.69]) by kanga.kvack.org (Postfix) with ESMTP id A23958D0002 for ; Wed, 19 Aug 2020 14:04:43 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 602D42488 for ; Wed, 19 Aug 2020 18:04:43 +0000 (UTC) X-FDA: 77168093646.25.cats11_4a122882702a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 9415B1804E516 for ; Wed, 19 Aug 2020 18:04:28 +0000 (UTC) X-HE-Tag: cats11_4a122882702a X-Filterd-Recvd-Size: 3973 Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Wed, 19 Aug 2020 18:04:28 +0000 (UTC) Received: by mail-pj1-f65.google.com with SMTP id q93so110313pjq.0 for ; Wed, 19 Aug 2020 11:04:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=o5QWU1nEiy+Wm6gh5sFTQwgB0RXtZgwdt6tODGtZKRg=; b=Dm12xVmMzZ7+gsbRjbkm68z3UhSAAY6ovLHRwBvSlZRYXMn/jyVefCRwwEuid/htYs br88nAj9HKrAuowA12vkOzJAwRYaRkbgsNo09lWJDv7VL18k1yKtxP+qrqbV68ClR1J9 aINuOTkBRJSvuCX+knwKWIe7bXQAL6ulo1Sg4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=o5QWU1nEiy+Wm6gh5sFTQwgB0RXtZgwdt6tODGtZKRg=; b=HkglgvmoRwk3jPNicVvBTJmxh9BqUMV7QcDDb40/NWGTFo4zj3fF2pcsLBZdSwDDd9 ve8edHqiBlD5ZyWUzwXXu9XeMKWGLde0XG8hMMe0UHPCY4B7oabt/HAsYoLWP/GUaSJH UnfqdhUeo36XVfUUHc+FWuqKGdKb7W0yBWodd6RXNeXYmm774EzJUkY4tUbPQl8qtMzZ NgO7epecj2uVcVkGvrcujITCk9k2oY2Zsh88vIFYGA4VRj5Uvpg2Oyp3eJAtWR3brIWs zKutIgxODoT0ZEJ/IrbCM0cic2BtqZvrqdxVSjRlz2R2B5ZQnqaR7qk3wDdOSEyiE2o0 pJDw== X-Gm-Message-State: AOAM530Vv58obb7YmsfcuNAVvO1ytqrR3FAX5KggvMBo0QWUFXKe8ga3 U1z8/LBsoILMJyyqwlAGi0ig+g== X-Google-Smtp-Source: ABdhPJzcCUFsTUuuU/7fR9DIMfV1GDtBk230JWzP+wvh2sEXRmU+hodx93sL2eXCM5k81uPM4O9/vg== X-Received: by 2002:a17:90b:46d3:: with SMTP id jx19mr5046020pjb.158.1597860267077; Wed, 19 Aug 2020 11:04:27 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id d4sm3563704pju.56.2020.08.19.11.04.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 11:04:26 -0700 (PDT) Date: Wed, 19 Aug 2020 11:04:24 -0700 From: Kees Cook To: Miaohe Lin Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Subject: Re: [PATCH] mm/migrate: Avoid possible unnecessary ptrace_may_access() call in kernel_move_pages() Message-ID: <202008191103.D88345E410@keescook> References: <20200817115933.44565-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200817115933.44565-1-linmiaohe@huawei.com> X-Rspamd-Queue-Id: 9415B1804E516 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000136, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Aug 17, 2020 at 07:59:33AM -0400, Miaohe Lin wrote: > There is no need to check if this process has the right to modify the > specified process when they are same. > > Signed-off-by: Hongxiang Lou > Signed-off-by: Miaohe Lin > --- > mm/migrate.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/migrate.c b/mm/migrate.c > index 34a842a8eb6a..342c1ce0b433 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -1903,7 +1903,7 @@ static int kernel_move_pages(pid_t pid, unsigned long nr_pages, > * Check if this process has the right to modify the specified > * process. Use the regular "ptrace_may_access()" checks. > */ > - if (!ptrace_may_access(task, PTRACE_MODE_READ_REALCREDS)) { > + if (pid && !ptrace_may_access(task, PTRACE_MODE_READ_REALCREDS)) { > rcu_read_unlock(); > err = -EPERM; > goto out; NAK, please don't do this -- the ptrace and security hooks already do these kinds of self-introspection checks, and I'd like to keep a central place to perform these kinds of checks. Is there a specific problem you've encountered that this fixes? -- Kees Cook