Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp787508ybl; Fri, 6 Dec 2019 06:16:31 -0800 (PST) X-Google-Smtp-Source: APXvYqynNuLNqoB9uPCxmqnMxmkEq5LH1GZ3eDcq1hRFKv8FfqPOl9YTEbe3l2Wu4geWLc4Ma6BK X-Received: by 2002:a54:4792:: with SMTP id o18mr6208178oic.74.1575641791653; Fri, 06 Dec 2019 06:16:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575641791; cv=none; d=google.com; s=arc-20160816; b=jDdtNuLLE8Ntjkqg1sJvAjLISi80WUrTjNfXfmLIUvM8QbapbzMDOgB7Jf3lpUZuGz D0VRzse46vxwLPrk66F7NIqyfX+Ku5QQ0AfhADpxxiv4NVyxFXKirjMickJXMOOVp4n2 +SIYvUmvnC/I5IHwz3cSnaBsjffNlwPCmMy4gYOUo196J5WX10HQnnf4p4btITbFD1Zh rxy8t6AG6pQhoOh4huHRMDnXKtZpyGZrrdF4rF1c1uzW+DcmNDeSClp/EBcS1iOPaLIB 5yWjtO7MejrczkWLrz+atOlSZ611IXrMtk6fqDG9YE91kJmiYKuPK/Ai4znLfKsw0iT7 5rYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=1olkk9TXEC/BOUOC/jKvrN6oXVEC2m91zebXuyBzBtQ=; b=bcDvdWRfXtV9kCFPyExGjXT/POEDiUHovyn7D3W6aEDzjU+dcVzGjsedEOA66PD78q zzIJIInOzD9Mpq9s79aKsQBSQu4UI01kEBTnrzL8fZP3PCIurbmCTT7URA8HlBdAYsqW NVCv/YnCgEna9/vN5/QuPgaX7LyRVdh1YR8YrDakeZh47W5O+J51htMIRBKYRfG5KjqH yGTF+5BcuKAKuGJ1zhUawG/eYUfY4EeawCstA4DrEWrWpggT3ItgyF1nIPItj2OVRCDr XfEzlHimUEDDGePSZcjtogIi+5eCG8sHtQYyo67v0Kj43W85L3YG/DZ1w5QB7JX92ng5 GynQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m82si6811573oig.129.2019.12.06.06.16.19; Fri, 06 Dec 2019 06:16:31 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726596AbfLFOPx (ORCPT + 99 others); Fri, 6 Dec 2019 09:15:53 -0500 Received: from mout-p-201.mailbox.org ([80.241.56.171]:59320 "EHLO mout-p-201.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726411AbfLFOPw (ORCPT ); Fri, 6 Dec 2019 09:15:52 -0500 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 47Tvkp3GkvzQl90; Fri, 6 Dec 2019 15:15:46 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) (amavisd-new, port 10030) with ESMTP id ZLxy6Jr4yVVS; Fri, 6 Dec 2019 15:15:41 +0100 (CET) From: Aleksa Sarai To: Al Viro , Jeff Layton , "J. Bruce Fields" , Arnd Bergmann , David Howells , Shuah Khan , Shuah Khan , Ingo Molnar , Peter Zijlstra , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , Jonathan Corbet Cc: Aleksa Sarai , Eric Biederman , Andy Lutomirski , Andrew Morton , Kees Cook , Jann Horn , Tycho Andersen , David Drysdale , Chanho Min , Oleg Nesterov , Rasmus Villemoes , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Christian Brauner , Aleksa Sarai , Linus Torvalds , dev@opencontainers.org, containers@lists.linux-foundation.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-alpha@vger.kernel.org, linux-api@vger.kernel.org, libc-alpha@sourceware.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linux-xtensa@linux-xtensa.org, sparclinux@vger.kernel.org Subject: [PATCH v18 03/13] namei: allow nd_jump_link() to produce errors Date: Sat, 7 Dec 2019 01:13:28 +1100 Message-Id: <20191206141338.23338-4-cyphar@cyphar.com> In-Reply-To: <20191206141338.23338-1-cyphar@cyphar.com> References: <20191206141338.23338-1-cyphar@cyphar.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for LOOKUP_NO_MAGICLINKS, it's necessary to add the ability for nd_jump_link() to return an error which the corresponding get_link() caller must propogate back up to the VFS. Suggested-by: Al Viro Signed-off-by: Aleksa Sarai --- fs/namei.c | 3 ++- fs/proc/base.c | 3 +-- fs/proc/namespaces.c | 14 +++++++++----- include/linux/namei.h | 2 +- security/apparmor/apparmorfs.c | 6 ++++-- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 5a47d9c09581..1024a641f075 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -859,7 +859,7 @@ static int nd_jump_root(struct nameidata *nd) * Helper to directly jump to a known parsed path from ->get_link, * caller must have taken a reference to path beforehand. */ -void nd_jump_link(struct path *path) +int nd_jump_link(struct path *path) { struct nameidata *nd = current->nameidata; path_put(&nd->path); @@ -867,6 +867,7 @@ void nd_jump_link(struct path *path) nd->path = *path; nd->inode = nd->path.dentry->d_inode; nd->flags |= LOOKUP_JUMPED; + return 0; } static inline void put_link(struct nameidata *nd) diff --git a/fs/proc/base.c b/fs/proc/base.c index ebea9501afb8..ee97dd322f3e 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1626,8 +1626,7 @@ static const char *proc_pid_get_link(struct dentry *dentry, if (error) goto out; - nd_jump_link(&path); - return NULL; + error = nd_jump_link(&path); out: return ERR_PTR(error); } diff --git a/fs/proc/namespaces.c b/fs/proc/namespaces.c index 08dd94df1a66..a8cca516f1a9 100644 --- a/fs/proc/namespaces.c +++ b/fs/proc/namespaces.c @@ -51,11 +51,15 @@ static const char *proc_ns_get_link(struct dentry *dentry, if (!task) return ERR_PTR(-EACCES); - if (ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) { - error = ns_get_path(&ns_path, task, ns_ops); - if (!error) - nd_jump_link(&ns_path); - } + if (!ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) + goto out; + + error = ns_get_path(&ns_path, task, ns_ops); + if (error) + goto out; + + error = nd_jump_link(&ns_path); +out: put_task_struct(task); return ERR_PTR(error); } diff --git a/include/linux/namei.h b/include/linux/namei.h index 397a08ade6a2..758e9b47db6f 100644 --- a/include/linux/namei.h +++ b/include/linux/namei.h @@ -68,7 +68,7 @@ extern int follow_up(struct path *); extern struct dentry *lock_rename(struct dentry *, struct dentry *); extern void unlock_rename(struct dentry *, struct dentry *); -extern void nd_jump_link(struct path *path); +extern int __must_check nd_jump_link(struct path *path); static inline void nd_terminate_link(void *name, size_t len, size_t maxlen) { diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c index 45d13b6462aa..0b7d6dce6291 100644 --- a/security/apparmor/apparmorfs.c +++ b/security/apparmor/apparmorfs.c @@ -2455,16 +2455,18 @@ static const char *policy_get_link(struct dentry *dentry, { struct aa_ns *ns; struct path path; + int error; if (!dentry) return ERR_PTR(-ECHILD); + ns = aa_get_current_ns(); path.mnt = mntget(aafs_mnt); path.dentry = dget(ns_dir(ns)); - nd_jump_link(&path); + error = nd_jump_link(&path); aa_put_ns(ns); - return NULL; + return ERR_PTR(error); } static int policy_readlink(struct dentry *dentry, char __user *buffer, -- 2.24.0