Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1762064ybi; Sat, 27 Jul 2019 18:05:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqyosqYF1UEGjvWk6HKAJqvoILDyrZYI6dlQUIAeFzWrf9Yz8cjTi9KzuNoCVqxCOclOwjUG X-Received: by 2002:a63:61c6:: with SMTP id v189mr90696100pgb.36.1564275954311; Sat, 27 Jul 2019 18:05:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564275954; cv=none; d=google.com; s=arc-20160816; b=kFWCwHT2t/DsXCxag3ZhqIHDrrmFA+8q63DblcInON60fjza/VBqZMafZItEV3yx3G w4lGm/HEg1Cy07weKssWNmxnlGXaTkqScJv8pcb3F3A3/KniRTgJDSuvFOCjAYitLXtf nY7+u5b6XIgeR6iAqTFr6eqsc/RGNAWw8NrHmVxPJJZg7mOt8ctGL/le47E1BhP/6PL4 saYBHfBA1MwQurHHhIj25J0oXfvBZVveIHcfMfUZnfMZcGIspFk64eRj1uxOS+hBAHHv n++l+SJiCKvsjyXXH9i3EuV2Ivwg2GdulIQjPwbaEPEjUcKxYZwwF3/bZyhS7LBpQ1g5 eDUg== 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=pq7ZhUOcyuU2RZaX0a3T4gWgLLjY5vPbPe4qUhnnPnw=; b=AU7mRDfKa0+pyvGSRmCg2CV7M48Wx5qWSeLDHl793BkoGKrhKGOcvr4NW+vaTJk9gD GfxkASsjkuR2g6qZgK81jlJML6opVE6En0JawJTb/5OtD6ozBqUyEscYJ1cx6Y9UQn1E R5tITIORnorO5Qpp8Gv6MS69Qk37V9bX86HgY8RNuLHURrmJ1K3Wm6LHYECqZlV+fdP9 HxmblEUX0bLmMougpyB77hDxqDSQqEKRXsECy9g5ISPCtAXb0eNg7b+X4eBgzOKCMlVj PH5MVr6eydl09IuLtr9ZujeN96jKeQ+IHdo2EFQPmQPC86s2+uw6GNntEe5YrVlOZxAv V87A== 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 u24si23465465pgf.76.2019.07.27.18.05.39; Sat, 27 Jul 2019 18:05:54 -0700 (PDT) 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 S2388203AbfG1BEw (ORCPT + 99 others); Sat, 27 Jul 2019 21:04:52 -0400 Received: from mx2.mailbox.org ([80.241.60.215]:49478 "EHLO mx2.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726240AbfG1BEv (ORCPT ); Sat, 27 Jul 2019 21:04:51 -0400 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 mx2.mailbox.org (Postfix) with ESMTPS id 6F4EBA10DC; Sun, 28 Jul 2019 03:04:46 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id pibGlf-jZKFj; Sun, 28 Jul 2019 03:04:40 +0200 (CEST) From: Aleksa Sarai To: Al Viro , Jeff Layton , "J. Bruce Fields" , Arnd Bergmann , David Howells , Shuah Khan , Shuah Khan Cc: Aleksa Sarai , Eric Biederman , Andy Lutomirski , Andrew Morton , Alexei Starovoitov , Kees Cook , Jann Horn , Christian Brauner , Tycho Andersen , David Drysdale , Chanho Min , Oleg Nesterov , Aleksa Sarai , Linus Torvalds , containers@lists.linux-foundation.org, linux-alpha@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.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 v11 2/8] procfs: switch magic-link modes to be more sane Date: Sun, 28 Jul 2019 11:02:01 +1000 Message-Id: <20190728010207.9781-3-cyphar@cyphar.com> In-Reply-To: <20190728010207.9781-1-cyphar@cyphar.com> References: <20190728010207.9781-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 Now that magic-link modes are obeyed for file re-opening purposes, some of the pre-existing magic-link modes need to be adjusted to be more semantically correct. The most blatant example of this is /proc/self/exe, which had a mode of a+rwx even though tautologically the file could never be opened for writing (because it is the current->mm of a live process). With the new O_PATH restrictions, changing the default mode of these magic-links allows us to avoid delayed-access attacks such as we saw in CVE-2019-5736. Signed-off-by: Aleksa Sarai --- fs/proc/base.c | 20 ++++++++++---------- fs/proc/namespaces.c | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index ebea9501afb8..297242174402 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -133,9 +133,9 @@ struct pid_entry { #define DIR(NAME, MODE, iops, fops) \ NOD(NAME, (S_IFDIR|(MODE)), &iops, &fops, {} ) -#define LNK(NAME, get_link) \ - NOD(NAME, (S_IFLNK|S_IRWXUGO), \ - &proc_pid_link_inode_operations, NULL, \ +#define LNK(NAME, MODE, get_link) \ + NOD(NAME, (S_IFLNK|(MODE)), \ + &proc_pid_link_inode_operations, NULL, \ { .proc_get_link = get_link } ) #define REG(NAME, MODE, fops) \ NOD(NAME, (S_IFREG|(MODE)), NULL, &fops, {}) @@ -3028,9 +3028,9 @@ static const struct pid_entry tgid_base_stuff[] = { REG("numa_maps", S_IRUGO, proc_pid_numa_maps_operations), #endif REG("mem", S_IRUSR|S_IWUSR, proc_mem_operations), - LNK("cwd", proc_cwd_link), - LNK("root", proc_root_link), - LNK("exe", proc_exe_link), + LNK("cwd", S_IRWXUGO, proc_cwd_link), + LNK("root", S_IRWXUGO, proc_root_link), + LNK("exe", S_IRUGO|S_IXUGO, proc_exe_link), REG("mounts", S_IRUGO, proc_mounts_operations), REG("mountinfo", S_IRUGO, proc_mountinfo_operations), REG("mountstats", S_IRUSR, proc_mountstats_operations), @@ -3429,11 +3429,11 @@ static const struct pid_entry tid_base_stuff[] = { REG("numa_maps", S_IRUGO, proc_pid_numa_maps_operations), #endif REG("mem", S_IRUSR|S_IWUSR, proc_mem_operations), - LNK("cwd", proc_cwd_link), - LNK("root", proc_root_link), - LNK("exe", proc_exe_link), + LNK("cwd", S_IRWXUGO, proc_cwd_link), + LNK("root", S_IRWXUGO, proc_root_link), + LNK("exe", S_IRUGO|S_IXUGO, proc_exe_link), REG("mounts", S_IRUGO, proc_mounts_operations), - REG("mountinfo", S_IRUGO, proc_mountinfo_operations), + REG("mountinfo", S_IRUGO, proc_mountinfo_operations), #ifdef CONFIG_PROC_PAGE_MONITOR REG("clear_refs", S_IWUSR, proc_clear_refs_operations), REG("smaps", S_IRUGO, proc_pid_smaps_operations), diff --git a/fs/proc/namespaces.c b/fs/proc/namespaces.c index dd2b35f78b09..cd1e130913f7 100644 --- a/fs/proc/namespaces.c +++ b/fs/proc/namespaces.c @@ -94,7 +94,7 @@ static struct dentry *proc_ns_instantiate(struct dentry *dentry, struct inode *inode; struct proc_inode *ei; - inode = proc_pid_make_inode(dentry->d_sb, task, S_IFLNK | S_IRWXUGO); + inode = proc_pid_make_inode(dentry->d_sb, task, S_IFLNK | S_IRUGO); if (!inode) return ERR_PTR(-ENOENT); -- 2.22.0