Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3116075imb; Tue, 5 Mar 2019 01:03:44 -0800 (PST) X-Google-Smtp-Source: APXvYqyWFeayS29tQ2p6E1+BeLsz1DmS79E7sKHzMzEUK2rEEj04J3Mdmm0HFtl8/n8I26V7Mtyj X-Received: by 2002:a17:902:9307:: with SMTP id bc7mr128413plb.234.1551776624803; Tue, 05 Mar 2019 01:03:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551776624; cv=none; d=google.com; s=arc-20160816; b=yY2XuVUR3SX6D7BPebqa2twC8YBZzRcgz2Tp7Z0l3UVopSZNZeDbJxFdQueYIepjyO oLP3lf5a6g5cS0pvOcRFWS85U+znGXKKUua8QMKA0oDhIqTXE8NQSEvRA+blccskI8Fm T3gT/tmwb8Aupa8u+MZP6zv+E4afjJOtpnqkcSdY+jaZ+DcPKpYyNIQlsYamAFUkEc+E wY2w0gyBzLnI9/uy2XYMcTg1bxL10vVLygWKxfT/avDxnc3/jPRKU3zqbTuzLG1ojamF q30xcU6GyUMXaDAJAXBXZmK6cEYfyMoVPTCOPsYHA3i798gOwfNacetfk/V9fHYsgSi4 Fr7A== 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 :dkim-signature; bh=URR3vg9EwgVzaZ+snBNRzhtMexrFmIC4pbMVhQ3juPo=; b=Sgw0cipbOs4XUaOjLWRBSW26ojrP68ara4v2r+Fd5DEAey6ZHqty1PPNHQmG2voxgy 8MTKp4X3X9ejZc5OoS0AVHZ+7XH77ThbTE4RSY5DUQaoMLbauuX42hGYsz4wUHaW/2fU YZqF6XkL7CtzxdjM07mIOcpQVkRZ81jWfpWobHpbjnp6r5h+enChizjatl/JPy4t5EYg 71Huu1OFOU5192mEK3LVqUh6qZAHifaxYFbmyLckq+z7Rm1tmJAaROcdrfpEj7/K0b9g hqsMMpwqMv8xxLVkTrAn4Qsx/knnoFOuySDwnYkZG+N0xP2CYj67XIFnadydHi5Jg76O XCWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WPNG67sC; 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=pass (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 c132si7506064pfg.5.2019.03.05.01.03.28; Tue, 05 Mar 2019 01:03:44 -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; dkim=pass header.i=@kernel.org header.s=default header.b=WPNG67sC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726956AbfCEJBe (ORCPT + 99 others); Tue, 5 Mar 2019 04:01:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:34224 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726098AbfCEJBe (ORCPT ); Tue, 5 Mar 2019 04:01:34 -0500 Received: from devnote (p218086-mobac01.tokyo.ocn.ne.jp [153.233.209.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 495F3206DD; Tue, 5 Mar 2019 09:01:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551776492; bh=Jqu7d71snGoa2BV0+qw3peB2EK3U1LcVkWK7xz6qFrg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=WPNG67sC1u4H34rE5jxXCpEKoTzMDZF3DZrN7hbCf9xOrGmqSJ4I5xLIk070M465w JdraszkD6bV75K7znH/TlVNKm3WNwEs2cCX8IUSeBtnK8KnwNqKPMpK8FWPU2hXohu jIEjozNCeantgPrY8TYJQfdvFqsavWN82m7SDo70= Date: Tue, 5 Mar 2019 18:01:26 +0900 From: Masami Hiramatsu To: Masami Hiramatsu Cc: Linus Torvalds , Peter Zijlstra , kernel test robot , Steven Rostedt , Shuah Khan , Linux List Kernel Mailing , Andy Lutomirski , Ingo Molnar , Andrew Morton , Changbin Du , Jann Horn , Kees Cook , Andy Lutomirski , Alexei Starovoitov , Nadav Amit , Joel Fernandes , yhs@fb.com, lkp@01.org Subject: Re: [uaccess] 780464aed0: WARNING:at_arch/x86/include/asm/uaccess.h:#strnlen_user/0x Message-Id: <20190305180126.0f7201d8ec733fdc887135f1@kernel.org> In-Reply-To: <20190305172241.2eef39c6ca74d09120bbbcad@kernel.org> References: <155136980507.2968.15165201054223875356.stgit@devbox> <20190303173954.kliegojbuigqi5tn@inn2.lkp.intel.com> <20190304101434.8429ffffb17813c0e7930130@kernel.org> <20190304180610.2d4f6f08d9ad89d6abae3597@kernel.org> <20190305113635.18f80ea3b1f4fca54b9d21e4@kernel.org> <20190305172241.2eef39c6ca74d09120bbbcad@kernel.org> X-Mailer: Sylpheed 3.5.0 (GTK+ 2.24.30; 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 Tue, 5 Mar 2019 17:22:41 +0900 Masami Hiramatsu wrote: > On Tue, 5 Mar 2019 11:36:35 +0900 > Masami Hiramatsu wrote: > > > On Mon, 4 Mar 2019 10:59:22 -0800 > > Linus Torvalds wrote: > > > > I think the better way to do this is allowing strncpy_from_user() > > if some conditions are match, like > > > > - strncpy_from_user() will be able to copy user memory with set_fs(USER_DS) > > - strncpy_from_user() can copy kernel memory with set_fs(KERNEL_DS) > > - strncpy_from_user() can access unsafe memory in IRQ context if > > pagefault is disabled. > > > > This is almost done, except for CONFIG_DEBUG_ATOMIC_SLEEP=y on x86. > > > > So, what about adding a condition to WARN_ON_IN_IRQ() like below > > instead of introducing user_access_ok() ? OK, here is the patch. Does it work for us? ==== x86/uaccess: Verify access_ok() context strictly From: Masami Hiramatsu WARN_ON_IN_IRQ() assumes that the access_ok() and following user memory access can sleep. But this assumption is not always correct; when the pagefault is disabled, following memory access will just returns -EFAULT and never sleep. Add pagefault_disabled() check in WARN_ON_ONCE() so that it can ignore the case we call it with disabling pagefault. For this purpose, this modified pagefault_disabled() as an inline function. Signed-off-by: Masami Hiramatsu --- arch/x86/include/asm/uaccess.h | 4 +++- include/linux/uaccess.h | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index 780f2b4..b98a552 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -70,7 +70,9 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un }) #ifdef CONFIG_DEBUG_ATOMIC_SLEEP -# define WARN_ON_IN_IRQ() WARN_ON_ONCE(!in_task()) +static inline bool pagefault_disabled(void); +# define WARN_ON_IN_IRQ() \ + WARN_ON_ONCE(!in_task() && !pagefault_disabled()) #else # define WARN_ON_IN_IRQ() #endif diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index 37b226e..ef3032d 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h @@ -203,7 +203,10 @@ static inline void pagefault_enable(void) /* * Is the pagefault handler disabled? If so, user access methods will not sleep. */ -#define pagefault_disabled() (current->pagefault_disabled != 0) +static inline bool pagefault_disabled(void) +{ + return current->pagefault_disabled != 0; +} /* * The pagefault handler is in general disabled by pagefault_disable() or