stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Qualys Security Advisory <qsa@qualys.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Andy Lutomirski <luto@amacapital.net>,
	Oleg Nesterov <oleg@redhat.com>, Willy Tarreau <w@1wt.eu>
Subject: [PATCH 4.14 45/45] proc: do not access cmdline nor environ from file-backed areas
Date: Fri, 18 May 2018 10:16:02 +0200	[thread overview]
Message-ID: <20180518081532.668152613@linuxfoundation.org> (raw)
In-Reply-To: <20180518081530.331586165@linuxfoundation.org>

4.14-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Willy Tarreau <w@1wt.eu>

commit 7f7ccc2ccc2e70c6054685f5e3522efa81556830 upstream.

proc_pid_cmdline_read() and environ_read() directly access the target
process' VM to retrieve the command line and environment. If this
process remaps these areas onto a file via mmap(), the requesting
process may experience various issues such as extra delays if the
underlying device is slow to respond.

Let's simply refuse to access file-backed areas in these functions.
For this we add a new FOLL_ANON gup flag that is passed to all calls
to access_remote_vm(). The code already takes care of such failures
(including unmapped areas). Accesses via /proc/pid/mem were not
changed though.

This was assigned CVE-2018-1120.

Note for stable backports: the patch may apply to kernels prior to 4.11
but silently miss one location; it must be checked that no call to
access_remote_vm() keeps zero as the last argument.

Reported-by: Qualys Security Advisory <qsa@qualys.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 fs/proc/base.c     |    8 ++++----
 include/linux/mm.h |    1 +
 mm/gup.c           |    3 +++
 3 files changed, 8 insertions(+), 4 deletions(-)

--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -263,7 +263,7 @@ static ssize_t proc_pid_cmdline_read(str
 	 * Inherently racy -- command line shares address space
 	 * with code and data.
 	 */
-	rv = access_remote_vm(mm, arg_end - 1, &c, 1, 0);
+	rv = access_remote_vm(mm, arg_end - 1, &c, 1, FOLL_ANON);
 	if (rv <= 0)
 		goto out_free_page;
 
@@ -281,7 +281,7 @@ static ssize_t proc_pid_cmdline_read(str
 			int nr_read;
 
 			_count = min3(count, len, PAGE_SIZE);
-			nr_read = access_remote_vm(mm, p, page, _count, 0);
+			nr_read = access_remote_vm(mm, p, page, _count, FOLL_ANON);
 			if (nr_read < 0)
 				rv = nr_read;
 			if (nr_read <= 0)
@@ -327,7 +327,7 @@ static ssize_t proc_pid_cmdline_read(str
 				bool final;
 
 				_count = min3(count, len, PAGE_SIZE);
-				nr_read = access_remote_vm(mm, p, page, _count, 0);
+				nr_read = access_remote_vm(mm, p, page, _count, FOLL_ANON);
 				if (nr_read < 0)
 					rv = nr_read;
 				if (nr_read <= 0)
@@ -946,7 +946,7 @@ static ssize_t environ_read(struct file
 		max_len = min_t(size_t, PAGE_SIZE, count);
 		this_len = min(max_len, this_len);
 
-		retval = access_remote_vm(mm, (env_start + src), page, this_len, 0);
+		retval = access_remote_vm(mm, (env_start + src), page, this_len, FOLL_ANON);
 
 		if (retval <= 0) {
 			ret = retval;
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2383,6 +2383,7 @@ static inline struct page *follow_page(s
 #define FOLL_MLOCK	0x1000	/* lock present pages */
 #define FOLL_REMOTE	0x2000	/* we are working on non-current tsk/mm */
 #define FOLL_COW	0x4000	/* internal GUP flag */
+#define FOLL_ANON	0x8000	/* don't do file mappings */
 
 static inline int vm_fault_to_errno(int vm_fault, int foll_flags)
 {
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -544,6 +544,9 @@ static int check_vma_flags(struct vm_are
 	if (vm_flags & (VM_IO | VM_PFNMAP))
 		return -EFAULT;
 
+	if (gup_flags & FOLL_ANON && !vma_is_anonymous(vma))
+		return -EFAULT;
+
 	if (write) {
 		if (!(vm_flags & VM_WRITE)) {
 			if (!(gup_flags & FOLL_FORCE))

  parent reply	other threads:[~2018-05-18  8:20 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-18  8:15 [PATCH 4.14 00/45] 4.14.42-stable review Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 01/45] 8139too: Use disable_irq_nosync() in rtl8139_poll_controller() Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 02/45] bridge: check iface upper dev when setting master via ioctl Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 03/45] dccp: fix tasklet usage Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 04/45] ipv4: fix fnhe usage by non-cached routes Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 05/45] ipv4: fix memory leaks in udp_sendmsg, ping_v4_sendmsg Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 06/45] llc: better deal with too small mtu Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 07/45] net: ethernet: sun: niu set correct packet size in skb Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 08/45] net: ethernet: ti: cpsw: fix packet leaking in dual_mac mode Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 09/45] net/mlx4_en: Fix an error handling path in mlx4_en_init_netdev() Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 10/45] net/mlx4_en: Verify coalescing parameters are in range Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 11/45] net/mlx5e: Err if asked to offload TC match on frag being first Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 12/45] net/mlx5: E-Switch, Include VF RDMA stats in vport statistics Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 13/45] net sched actions: fix refcnt leak in skbmod Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 14/45] net_sched: fq: take care of throttled flows before reuse Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 15/45] net: support compat 64-bit time in {s,g}etsockopt Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 16/45] net/tls: Dont recursively call push_record during tls_write_space callbacks Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 17/45] net/tls: Fix connection stall on partial tls record Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 18/45] openvswitch: Dont swap table in nlattr_set() after OVS_ATTR_NESTED is found Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 20/45] r8169: fix powering up RTL8168h Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 21/45] rds: do not leak kernel memory to user land Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 22/45] sctp: delay the authentication for the duplicated cookie-echo chunk Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 23/45] sctp: fix the issue that the cookie-ack with auth cant get processed Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 24/45] sctp: handle two v4 addrs comparison in sctp_inet6_cmp_addr Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 25/45] sctp: remove sctp_chunk_put from fail_mark err path in sctp_ulpevent_make_rcvmsg Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 26/45] sctp: use the old asoc when making the cookie-ack chunk in dupcook_d Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 27/45] tcp_bbr: fix to zero idle_restart only upon S/ACKed data Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 28/45] tcp: ignore Fast Open on repair mode Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 29/45] tg3: Fix vunmap() BUG_ON() triggered from tg3_free_consistent() Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 30/45] bonding: do not allow rlb updates to invalid mac Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 31/45] bonding: send learning packets for vlans on slave Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 32/45] net: sched: fix error path in tcf_proto_create() when modules are not configured Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 33/45] net/mlx5e: TX, Use correct counter in dma_map error flow Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 34/45] net/mlx5: Avoid cleaning flow steering table twice during " Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 35/45] hv_netvsc: set master device Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 36/45] ipv6: fix uninit-value in ip6_multipath_l3_keys() Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 37/45] net/mlx5e: Allow offloading ipv4 header re-write for icmp Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 38/45] nsh: fix infinite loop Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 39/45] udp: fix SO_BINDTODEVICE Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 40/45] scsi: aacraid: Correct hba_send to include iu_type Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 41/45] xfrm: Use __skb_queue_tail in xfrm_trans_queue Greg Kroah-Hartman
2018-05-18  8:15 ` [PATCH 4.14 42/45] btrfs: Take trans lock before access running trans in check_delayed_ref Greg Kroah-Hartman
2018-05-18  8:16 ` [PATCH 4.14 43/45] xfrm: fix xfrm_do_migrate() with AEAD e.g(AES-GCM) Greg Kroah-Hartman
2018-05-18  8:16 ` [PATCH 4.14 44/45] l2tp: revert "l2tp: fix missing print session offset info" Greg Kroah-Hartman
2018-05-18  8:16 ` Greg Kroah-Hartman [this message]
2018-05-18 13:22 ` [PATCH 4.14 00/45] 4.14.42-stable review Guenter Roeck
2018-05-18 19:10 ` Naresh Kamboju
2018-05-18 20:46 ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180518081532.668152613@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=oleg@redhat.com \
    --cc=qsa@qualys.com \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=w@1wt.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).