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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5789AC433FE for ; Mon, 4 Oct 2021 12:51:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0115F611CA for ; Mon, 4 Oct 2021 12:51:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0115F611CA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ubuntu.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 6B6EA94000F; Mon, 4 Oct 2021 08:51:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1DE1D94000B; Mon, 4 Oct 2021 08:51:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F249294000E; Mon, 4 Oct 2021 08:51:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0187.hostedemail.com [216.40.44.187]) by kanga.kvack.org (Postfix) with ESMTP id D0A7A94000F for ; Mon, 4 Oct 2021 08:51:44 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 83BAF253BD for ; Mon, 4 Oct 2021 12:51:44 +0000 (UTC) X-FDA: 78658741728.29.8A8324C Received: from smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) by imf01.hostedemail.com (Postfix) with ESMTP id 28E4A50703C9 for ; Mon, 4 Oct 2021 12:51:44 +0000 (UTC) Received: from wittgenstein.fritz.box (ip5f5bd0d9.dynamic.kabel-deutschland.de [95.91.208.217]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id D6AFE41A73; Mon, 4 Oct 2021 12:51:42 +0000 (UTC) From: Christian Brauner To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Vlastimil Babka , Suren Baghdasaryan , Matthew Bobrowski , Alexander Duyck , Jan Kara , Christian Brauner , Minchan Kim Subject: [PATCH 2/2] mm: use pidfd_get_task() Date: Mon, 4 Oct 2021 14:50:50 +0200 Message-Id: <20211004125050.1153693-3-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211004125050.1153693-1-christian.brauner@ubuntu.com> References: <20211004125050.1153693-1-christian.brauner@ubuntu.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 28E4A50703C9 X-Stat-Signature: bi5sfsbi3wbscidcntdkzok3qraryax7 Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=none; spf=none (imf01.hostedemail.com: domain of christian.brauner@ubuntu.com has no SPF policy when checking 185.125.188.121) smtp.mailfrom=christian.brauner@ubuntu.com X-HE-Tag: 1633351904-433545 Content-Transfer-Encoding: quoted-printable 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: Instead of duplicating the same code in two places use the newly added pidfd_get_task() helper. This fixes an (unimportant for now) bug where PIDTYPE_PID is used whereas PIDTYPE_TGID should have been used. Cc: Vlastimil Babka Cc: Suren Baghdasaryan Cc: Matthew Bobrowski Cc: Alexander Duyck Cc: Jan Kara Cc: Minchan Kim Signed-off-by: Christian Brauner --- mm/madvise.c | 15 +++------------ mm/oom_kill.c | 15 +++------------ 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 0734db8d53a7..8c927202bbe6 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1235,7 +1235,6 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const = struct iovec __user *, vec, struct iovec iovstack[UIO_FASTIOV], iovec; struct iovec *iov =3D iovstack; struct iov_iter iter; - struct pid *pid; struct task_struct *task; struct mm_struct *mm; size_t total_len; @@ -1250,18 +1249,12 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, cons= t struct iovec __user *, vec, if (ret < 0) goto out; =20 - pid =3D pidfd_get_pid(pidfd, &f_flags); - if (IS_ERR(pid)) { - ret =3D PTR_ERR(pid); + task =3D pidfd_get_task(pidfd, &f_flags); + if (IS_ERR(task)) { + ret =3D PTR_ERR(task); goto free_iov; } =20 - task =3D get_pid_task(pid, PIDTYPE_PID); - if (!task) { - ret =3D -ESRCH; - goto put_pid; - } - if (!process_madvise_behavior_valid(behavior)) { ret =3D -EINVAL; goto release_task; @@ -1301,8 +1294,6 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const = struct iovec __user *, vec, mmput(mm); release_task: put_task_struct(task); -put_pid: - put_pid(pid); free_iov: kfree(iov); out: diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 831340e7ad8b..70d399d5817e 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -1151,21 +1151,14 @@ SYSCALL_DEFINE2(process_mrelease, int, pidfd, uns= igned int, flags) struct task_struct *p; unsigned int f_flags; bool reap =3D true; - struct pid *pid; long ret =3D 0; =20 if (flags) return -EINVAL; =20 - pid =3D pidfd_get_pid(pidfd, &f_flags); - if (IS_ERR(pid)) - return PTR_ERR(pid); - - task =3D get_pid_task(pid, PIDTYPE_TGID); - if (!task) { - ret =3D -ESRCH; - goto put_pid; - } + task =3D pidfd_get_task(pidfd, &f_flags); + if (IS_ERR(task)) + return PTR_ERR(task); =20 /* * Make sure to choose a thread which still has a reference to mm @@ -1204,8 +1197,6 @@ SYSCALL_DEFINE2(process_mrelease, int, pidfd, unsig= ned int, flags) mmdrop(mm); put_task: put_task_struct(task); -put_pid: - put_pid(pid); return ret; #else return -ENOSYS; --=20 2.30.2