From patchwork Wed Nov 25 22:45:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 57309 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp173601lbb; Wed, 25 Nov 2015 15:05:26 -0800 (PST) X-Received: by 10.98.79.202 with SMTP id f71mr35390691pfj.21.1448492726662; Wed, 25 Nov 2015 15:05:26 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h81si37193374pfd.177.2015.11.25.15.05.26; Wed, 25 Nov 2015 15:05:26 -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; dkim=neutral (body hash did not verify) header.i=@linaro-org.20150623.gappssmtp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752781AbbKYXFT (ORCPT + 28 others); Wed, 25 Nov 2015 18:05:19 -0500 Received: from mail-pa0-f41.google.com ([209.85.220.41]:33454 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752446AbbKYXFO (ORCPT ); Wed, 25 Nov 2015 18:05:14 -0500 Received: by pabfh17 with SMTP id fh17so72473716pab.0 for ; Wed, 25 Nov 2015 15:05:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2/Yd8x5EktyoDGO7pb9nFdILlFHHVKuVgAdIBEbIzNA=; b=pP/zt/SqK9/tenpQbu78hBFmG/K4D/0dG7oZMPkkg1IsBxxhg5gkREEewpIGoxdI8D yLG6IIffdqCCjL796VTSpllisi4W6csaJy3N1Tu2RsWHU0wLaU9uvJgKcnE+CueX6nJF h3JdsCIU4Sn709r86YsG3K5QcNSczqQgxVurtpbQgsJWL/c5b9VZnjNmS3fV1OH39yc0 zloY6AdQv5QJ1yqy/PvSkqOMJ/NWdT41wDo2kUKW8w+aVZTmHpE/6l+TfdqIn7hYXsuM 4vvJ4H8nHq5K0/ptafCcfCejXw0/F/sLbP8duPC39pC+na9VC1ma60dKJ4zvRjqTBRg/ CJVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2/Yd8x5EktyoDGO7pb9nFdILlFHHVKuVgAdIBEbIzNA=; b=XUGUJneQc7Bgi+Q3xSUjZ+N2rEnWpQd3byq45YNxQRitjClITX+gMUjxuI9Bh1zTNq sZfJy94IhV06W5OwIzPZWJurPT8Dn18G5tj3YQnHo2osb1k3pIUW/k0rEBkOJ93f4wR2 FQLs3TVJlxgI5X4/tnKuWBf/xRz5+akOaJ110P+7IVGWOusHKULmsAkZh/fSAPP6rWXO xQxh24W00fb/UAoeWMvzbusP1ZD8HsCwvBU2sjBDUMWqiC/d7oDqnZYb77pzAbMd9pVX FeWUhs2XF4ryItEXBTFOKuQeCnrbodR94aX2EsVhAr3AweE6U/Meu+0b+pqELqL87UEE t2JA== X-Gm-Message-State: ALoCoQm5rGuM4A92ybcbnCVzzRVqm6YNRWtq3Y+2d2K5YjGkOyiv6XjkkGxtlLtwyqtyMZ3zAmEP X-Received: by 10.98.10.2 with SMTP id s2mr34900548pfi.45.1448492714079; Wed, 25 Nov 2015 15:05:14 -0800 (PST) Received: from yshi-Precision-T5600.corp.ad.wrs.com (unknown-216-82.windriver.com. [147.11.216.82]) by smtp.gmail.com with ESMTPSA id st5sm23519443pab.42.2015.11.25.15.05.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Nov 2015 15:05:13 -0800 (PST) From: Yang Shi To: davem@davemloft.net Cc: linux-kernel@vger.kernel.org, sparclinux@vger.kernel.org, linaro-kernel@lists.linaro.org, yang.shi@linaro.org Subject: [V2 PATCH] sparc64/gup: check address scope legitimacy Date: Wed, 25 Nov 2015 14:45:43 -0800 Message-Id: <1448491543-17946-1-git-send-email-yang.shi@linaro.org> X-Mailer: git-send-email 2.0.2 In-Reply-To: <1448490684-17171-1-git-send-email-yang.shi@linaro.org> References: <1448490684-17171-1-git-send-email-yang.shi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Check if user address is accessible in atomic version __get_user_pages_fast() before walking the page table. And, check if end > start in get_user_pages_fast(), otherwise fallback to slow path. Signed-off-by: Yang Shi --- Just found slow_irqon label is not defined, added it to avoid compile error. arch/sparc/mm/gup.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) -- 2.0.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/arch/sparc/mm/gup.c b/arch/sparc/mm/gup.c index 2e5c4fc..cf4fb47 100644 --- a/arch/sparc/mm/gup.c +++ b/arch/sparc/mm/gup.c @@ -173,6 +173,9 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write, addr = start; len = (unsigned long) nr_pages << PAGE_SHIFT; end = start + len; + if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ, + (void __user *)start, len))) + return 0; local_irq_save(flags); pgdp = pgd_offset(mm, addr); @@ -203,6 +206,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write, addr = start; len = (unsigned long) nr_pages << PAGE_SHIFT; end = start + len; + if (end < start) + goto slow_irqon; /* * XXX: batch / limit 'nr', to avoid large irq off latency @@ -244,7 +249,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write, slow: local_irq_enable(); - +slow_irqon: /* Try to get the remaining pages with get_user_pages */ start += nr << PAGE_SHIFT; pages += nr;