Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1901899imu; Sat, 5 Jan 2019 09:28:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/VpWovsrmVwh3yAs43WqSaYjhnpV3AlgI6mTLcBLL6zK76e8XkT5jOweVpCMc0XNdp8DNXv X-Received: by 2002:a62:ea09:: with SMTP id t9mr59458733pfh.228.1546709309116; Sat, 05 Jan 2019 09:28:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546709309; cv=none; d=google.com; s=arc-20160816; b=Ipv706JSDXWaF++D4XW7nkIubbBb+URGpoh0NTq9a4PS2BL1occD7wS5Xo3CoFe8wz 1MZrNF3W82NbkEF+CIa+TMllTvI7HGrSUP9oGleA4o1icaCv6gf5e1tsx+qi45dUYsiL rUK5ivQ9ik1kNady9ImGQC44x6qTM2s+tzWDlTFdJPbwY8M3R1OQwTLG3snIn315C2OQ xqa4whjYrxXrN0UK6t5xRdnM/UGMQD3Vhg81n67NqQxr/b6mqJ2DU9rOKAfvLc7Ireo9 2BfJuXcuHLJgRZG3iBfiJ7rRTXr58y3m6Qzy3LOgn7e8dm3W0xL+qtObLjbf8GcaUce9 gE+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :subject:cc:to:from:date; bh=rbh7SbMsDzLW85qhFs/JA9KR+911TMgBdFkozzVBbtQ=; b=nc5gXZSysnXx9UMv7u5vilfSneWbrOzuejNP5FaNx21LdbuTHJGKCgm5VlI6z/UQT/ 7gzDdpWoIrBB7aCAcywCJO5ttxRSVZQQKcDpincVzI3beBJw4234H5CqmZAnicgRSZMj Bm2JtXi15wcVtF4HCFBKjRlBWxtN2DnQIUURk7U5ZHFRZv608bE3qqqbsMDy7N3KmTmU 0Ae/aQ6sUkcR+uYsuLhSZjLQ8wg/NSenk6O9pc0lisDndWQT6uPvb0I/0AqmrGsSqx1r 24wanPIIBCrxX77agzaq48OKhOd+l8zKLur5aVgdGasH1cOEISD7wTpSHgtVmsTIlOAZ GQNw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r1si39366098plb.330.2019.01.05.09.28.14; Sat, 05 Jan 2019 09:28:29 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726349AbfAER1I (ORCPT + 99 others); Sat, 5 Jan 2019 12:27:08 -0500 Received: from mx2.suse.de ([195.135.220.15]:52216 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726252AbfAER1I (ORCPT ); Sat, 5 Jan 2019 12:27:08 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 24DAFAF09; Sat, 5 Jan 2019 17:27:07 +0000 (UTC) Date: Sat, 5 Jan 2019 18:27:05 +0100 (CET) From: Jiri Kosina To: Linus Torvalds , Andrew Morton , Greg KH , Peter Zijlstra , Michal Hocko cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH] mm/mincore: allow for making sys_mincore() privileged Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiri Kosina There are possibilities [1] how mincore() could be used as a converyor of a sidechannel information about pagecache metadata. Provide vm.mincore_privileged sysctl, which makes it possible to mincore() start returning -EPERM in case it's invoked by a process lacking CAP_SYS_ADMIN. The default behavior stays "mincore() can be used by anybody" in order to be conservative with respect to userspace behavior. [1] https://www.theregister.co.uk/2019/01/05/boffins_beat_page_cache/ Signed-off-by: Jiri Kosina --- Documentation/sysctl/vm.txt | 9 +++++++++ kernel/sysctl.c | 8 ++++++++ mm/mincore.c | 5 +++++ 3 files changed, 22 insertions(+) diff --git a/Documentation/sysctl/vm.txt b/Documentation/sysctl/vm.txt index 187ce4f599a2..afb8635e925e 100644 --- a/Documentation/sysctl/vm.txt +++ b/Documentation/sysctl/vm.txt @@ -41,6 +41,7 @@ Currently, these files are in /proc/sys/vm: - min_free_kbytes - min_slab_ratio - min_unmapped_ratio +- mincore_privileged - mmap_min_addr - mmap_rnd_bits - mmap_rnd_compat_bits @@ -485,6 +486,14 @@ files and similar are considered. The default is 1 percent. ============================================================== +mincore_privileged: + +mincore() could be potentially used to mount a side-channel attack against +pagecache metadata. This sysctl provides system administrators means to +make it available only to processess that own CAP_SYS_ADMIN capability. + +The default is 0, which means mincore() can be used without restrictions. +============================================================== mmap_min_addr diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 1825f712e73b..f03cb07c8dd4 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -114,6 +114,7 @@ extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max; #ifndef CONFIG_MMU extern int sysctl_nr_trim_pages; #endif +extern int sysctl_mincore_privileged; /* Constants used for minimum and maximum */ #ifdef CONFIG_LOCKUP_DETECTOR @@ -1684,6 +1685,13 @@ static struct ctl_table vm_table[] = { .extra2 = (void *)&mmap_rnd_compat_bits_max, }, #endif + { + .procname = "mincore_privileged", + .data = &sysctl_mincore_privileged, + .maxlen = sizeof(sysctl_mincore_privileged), + .mode = 0644, + .proc_handler = proc_dointvec, + }, { } }; diff --git a/mm/mincore.c b/mm/mincore.c index 218099b5ed31..77d4928cdfaa 100644 --- a/mm/mincore.c +++ b/mm/mincore.c @@ -21,6 +21,8 @@ #include #include +int sysctl_mincore_privileged; + static int mincore_hugetlb(pte_t *pte, unsigned long hmask, unsigned long addr, unsigned long end, struct mm_walk *walk) { @@ -228,6 +230,9 @@ SYSCALL_DEFINE3(mincore, unsigned long, start, size_t, len, unsigned long pages; unsigned char *tmp; + if (sysctl_mincore_privileged && !capable(CAP_SYS_ADMIN)) + return -EPERM; + /* Check the start address: needs to be page-aligned.. */ if (start & ~PAGE_MASK) return -EINVAL; -- Jiri Kosina SUSE Labs