Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3119248imb; Tue, 5 Mar 2019 01:08:55 -0800 (PST) X-Google-Smtp-Source: APXvYqxjvz4OC2ILZ2bOCPKfBtebFQD+fM/Bw+X/C7QLYqz7zU87IztrKdgReOUrOGWC07L+S1jA X-Received: by 2002:a17:902:d207:: with SMTP id t7mr154796ply.216.1551776935725; Tue, 05 Mar 2019 01:08:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551776935; cv=none; d=google.com; s=arc-20160816; b=HyVX4YbIk1h+gq+6EpO0byyXmNokN32y/V8INC3IZVP8bCBQuc5ZzQOGxJiJwc6i+8 5zHxl4b3Y6VS8yc9lUWCKkw6EL609FSsK4ygUjkQpJAN7XF3bZc+F8G9BdQ3tMRPVelh /r3vGFIzCvFCC0p9sLAsl2WCWrOmMMnGDS+Kp0/33tKdzkK9jPbqLk2DXtuZLyrIFfcr N/5mERR4oPuaP9zSMGNCmptz+d1gkU9y37kn2q1yyF9zFzZF2kiLcCHYJk9XUfgtpF4/ fECP9i3cASbWpR+UdvOrH6ny+F0JxrNUFgjuSpmPqQn8OubsW7iQMFiLgDIQMxRymslw sMMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=C69eDiEB7D7z/Vfa3n3d0LLxb19gtv1PyelxonksJgM=; b=s78g9wYqcSBFegn9SlLipAqcPH5g11Lbu9mC+LieAkWj8mdM9fvMfhWRMGpapQHlK0 M9KtFGyMbByXpy0GiuWfWSJfzCuBLeMERmXmMwrcg4e0eR1YnmBdQIIwda3eclTpCKv3 rRCdoilN30pnJBq9vwXdBcJ012MWWYlgvSLTlA7VfdWPQT6qL++TUboyzP+Sf0N9uOaE a5iDJRFS/qvbPXts6JgO02oAWLL+/LNF5hLV86owJUbem1b1H6NWe2bkDkptTk0scOm3 GytukgEIWQZ1vQ0XjzWXD4o1Ap6nZg5JrgMivzKzlLk0yLXk7W9zyyb243OzFWAOOkvN /8KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=CbUxnz9M; 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 f3si7447594pfn.122.2019.03.05.01.08.39; Tue, 05 Mar 2019 01:08:55 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=CbUxnz9M; 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 S1727006AbfCEJH5 (ORCPT + 99 others); Tue, 5 Mar 2019 04:07:57 -0500 Received: from merlin.infradead.org ([205.233.59.134]:57682 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726085AbfCEJH5 (ORCPT ); Tue, 5 Mar 2019 04:07:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=C69eDiEB7D7z/Vfa3n3d0LLxb19gtv1PyelxonksJgM=; b=CbUxnz9MRTtTfVa9HAJx7lw16 aJFVa5nyrfIag8anKepyvAPcFlobSUXERVYdH0ereoEUZUqdM218m/WdkO7Za0mD4kjg+aP9fwKGZ 0nULNYPzQl1Z5IPUaRuwwLcMdPLwNxeTCjOcvzggxkdsNg0205IZnST2eAmrjq1vpoGZeRhFp5jEt X6zKQrwX2t9ghpR0euHVp8sVtykC9RzxygsdXdKdNSqEAN06k9jq/ERwbZ+KJITISc6KBxdh2jNYR wdbNYjMcO7cwXQpYvW8gW6j/CtHPZdkrtFjLisxi4HkxBuc8tRCCECGFAKsvShX9XmHBoETyvgRST paWoOkayg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1h162u-0004KK-61; Tue, 05 Mar 2019 09:07:32 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id A376D29B17DEE; Tue, 5 Mar 2019 10:07:29 +0100 (CET) Date: Tue, 5 Mar 2019 10:07:29 +0100 From: Peter Zijlstra To: Masami Hiramatsu Cc: Linus Torvalds , 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: <20190305090729.GF32477@hirez.programming.kicks-ass.net> References: <155136980507.2968.15165201054223875356.stgit@devbox> <20190303173954.kliegojbuigqi5tn@inn2.lkp.intel.com> <20190304101434.8429ffffb17813c0e7930130@kernel.org> <20190304180610.2d4f6f08d9ad89d6abae3597@kernel.org> <20190305113635.18f80ea3b1f4fca54b9d21e4@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190305113635.18f80ea3b1f4fca54b9d21e4@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 05, 2019 at 11:36:35AM +0900, Masami Hiramatsu wrote: > I think the better way to do this is allowing strncpy_from_user() O > 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() ? > > diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h > index 780f2b42c8ef..ec0f0b74c9ab 100644 > --- a/arch/x86/include/asm/uaccess.h > +++ b/arch/x86/include/asm/uaccess.h > @@ -70,7 +70,7 @@ 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()) > +# define WARN_ON_IN_IRQ() WARN_ON_ONCE(pagefault_disabled() && !in_task()) That doesn't make any kind of sense to me; see faulthandler_disabled(). IOW. interrupt (and any atomic context really) won't take faults anyway. I dislike that whole KERNEL_DS thing, but obviously that's not something that's going away. Would something like: WARN_ON_ONCE(!(in_task || segment_eq(get_fs(), USER_DS))) Work? Then we allow KERNEL_DS in task context, but for interrupt and others require USER_DS.