Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp4501976imb; Wed, 6 Mar 2019 15:15:29 -0800 (PST) X-Google-Smtp-Source: APXvYqzO4MbYy9Rxk54V5J0U2vhow2PH5vUWTVBWi+BmHlr5o7NwKIGDPLyZkHMP575my6tdjrbt X-Received: by 2002:a17:902:74cb:: with SMTP id f11mr9740056plt.180.1551914129400; Wed, 06 Mar 2019 15:15:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551914129; cv=none; d=google.com; s=arc-20160816; b=VLlOFSeCFgkXWS9TmazSh8BrpG+1z2nUuyo+cUGS+tk5YcA31rv1KZ0a2ppRUpQ17v jbLFBNac+lNqM+RBsLqxuBlW8UAQQ4IriQmXxJ601aza19qw/5Jntce5RFNnvdJO9/7J X2Pgx7T3BmW2VRekBxesGbqNEBBkr3LVLtjB3k6Awe8SOQ/SgMmxzy97uoU+eTxDd2nX AyPmhhb8RYzZfb70B0k9/I4FQ0EUIGFyIt2DqZvJapX73VU83/Nf/u5yJpf8A87jh2sc dlz1IlE/EnMO0Wl8UVujmpd4bsqFD1a5JwFU4QpNU7s/JmhKU9nozdVRymXXMmvFqRi6 CEaw== 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:subject:cc:to:from:date; bh=5xicT+JC9oblTCrAdpVGLVFcJO/wB0p+Szv3OSBbjp8=; b=qeKQnEjlwjVv2IqxQdVnAlOOGuPkb2EujWuCcb+6L6GYF/n5czR4cNH8wYs6IEHex6 uqBp9chfrPerUIdfc2AbRC9744c91tRzogreYp+/hHOKBHQwY8Rvrt9K7+S4mHDKg5ah hG9SlVgWSydYko/q8Og86noLDkU6FnDpK2g01KfHCN5mktiKL1K3McIh74HUIphaZrO1 H4N0f9a+1XMAizt6piQMMxQu9Hxtp7d7eSbB/yFGNIWwZx5BxFm+BKNi0+SxhF9y300S mmdew239KU4h1ANSYuMJpGP8zyHBaLQSclawx/cgU6Iq2lnX3QAYW7nhbQDffAg5Vsos wirg== 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 r76si2800619pfc.128.2019.03.06.15.15.13; Wed, 06 Mar 2019 15:15: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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726270AbfCFXNy (ORCPT + 99 others); Wed, 6 Mar 2019 18:13:54 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:33264 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725783AbfCFXNy (ORCPT ); Wed, 6 Mar 2019 18:13:54 -0500 Received: from akpm3.svl.corp.google.com (unknown [104.133.8.65]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 836AFB664; Wed, 6 Mar 2019 23:13:52 +0000 (UTC) Date: Wed, 6 Mar 2019 15:13:51 -0800 From: Andrew Morton To: Vlastimil Babka Cc: Linus Torvalds , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-api@vger.kernel.org, Peter Zijlstra , Greg KH , Jann Horn , Jiri Kosina , Dominique Martinet , Andy Lutomirski , Dave Chinner , Kevin Easton , Matthew Wilcox , Cyril Hrubis , Tejun Heo , "Kirill A . Shutemov" , Daniel Gruss , Jiri Kosina Subject: Re: [PATCH 1/3] mm/mincore: make mincore() more conservative Message-Id: <20190306151351.f8ae1acae51ccad1a3537284@linux-foundation.org> In-Reply-To: <20190130124420.1834-2-vbabka@suse.cz> References: <20190130124420.1834-1-vbabka@suse.cz> <20190130124420.1834-2-vbabka@suse.cz> X-Mailer: Sylpheed 3.6.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 30 Jan 2019 13:44:18 +0100 Vlastimil Babka wrote: > From: Jiri Kosina > > The semantics of what mincore() considers to be resident is not completely > clear, but Linux has always (since 2.3.52, which is when mincore() was > initially done) treated it as "page is available in page cache". > > That's potentially a problem, as that [in]directly exposes meta-information > about pagecache / memory mapping state even about memory not strictly belonging > to the process executing the syscall, opening possibilities for sidechannel > attacks. > > Change the semantics of mincore() so that it only reveals pagecache information > for non-anonymous mappings that belog to files that the calling process could > (if it tried to) successfully open for writing. "for writing" comes as a bit of a surprise. Why not for reading? Could we please explain the reasoning in the changelog and in the (presently absent) comments which describe can_do_mincore()? > @@ -189,8 +197,13 @@ static long do_mincore(unsigned long addr, unsigned long pages, unsigned char *v > vma = find_vma(current->mm, addr); > if (!vma || addr < vma->vm_start) > return -ENOMEM; > - mincore_walk.mm = vma->vm_mm; > end = min(vma->vm_end, addr + (pages << PAGE_SHIFT)); > + if (!can_do_mincore(vma)) { > + unsigned long pages = (end - addr) >> PAGE_SHIFT; I'm not sure this is correct in all cases. If addr = 4095 vma->vm_end = 4096 pages = 1000 then `end' is 4096 and `(end - addr) << PAGE_SHIFT' is zero, but it should have been 1. Please check? A mincore test suite in tools/testing/selftests would be useful, methinks. To exercise such corner cases, check for future breakage, etc. > + memset(vec, 1, pages); > + return pages; > + } > + mincore_walk.mm = vma->vm_mm; > err = walk_page_range(addr, end, &mincore_walk); > if (err < 0) > return err;