Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3313543imb; Tue, 5 Mar 2019 06:25:38 -0800 (PST) X-Google-Smtp-Source: APXvYqypA0DQR2996xrSFHYRpckvi1VrbZauT9qzVlSNjGqBn5pJKkHt84uPwQlMBD017ZrfGJnB X-Received: by 2002:a62:404:: with SMTP id 4mr2062381pfe.131.1551795938274; Tue, 05 Mar 2019 06:25:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551795938; cv=none; d=google.com; s=arc-20160816; b=HAgNW6CC/ewut2w4ZIASBIqNNXfbyLlFeK19Wech2TQXUtmhHvJHl/F+0CDmHEJSSa xyHZB5z5LmQHSA+LF0wwKUA7Vhw6Lb9rw1EXhe8JydmPfx8jhM9t7fqtCJQxV2kKl4RC LK8qBHrR/yChKi5EnqRhR6rx0lAn1eFBf9mIgnjNuXSvvsACWPBwWya+5QGFX8BYkHkC 3KopvkPBJlueIgp734R38QM6Y/BJi6lh0SQnOKvRCtZuA2L8M/6CIkcO9O/0mXFLz1qT Nzw7HeOv+TyzKewiWy4idFjAEYBCTzh8RPu+yHRDT3VYVu0nhyrClaAR99IMp/iRdId1 dUJg== 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=sCmPbSP475vx+SKC92YCptdbsI8B4htLyGg+o1lItng=; b=Nc12OlwgXQ5g0PN8ATvbkCBv4TJnIBKF4e4VuO3pPTFjgFrpLbMRzqymdnUCGtiJZK 078Q04xTN7jzqjX9ARBaEc+ruP752m/bew5j20EZPjLW3VMb4jy2LaEL9vHRcIrW/Lw0 FV6iwDcn1DIARnryWX99SdNIJmY5C8hGBkwn2Got6Hwi0qwvdiwt8I9nMMp2gPNbbIYP FvGY27b99iVT+dttoea7IGDQkVmGF7sqZgQxfxM51OQegahJMtI1AcGj4kjmyHS9DeyG CbPenP9mmGKIBymHdhvKtYO0JT5EQE/Tpa0nxt6UeDZz4T5MHWbwhYL/6xbaSFKKRET+ YI1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OAJyOcYg; 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 i67si5649949pfb.117.2019.03.05.06.25.22; Tue, 05 Mar 2019 06:25:38 -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=OAJyOcYg; 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 S1728000AbfCEN6J (ORCPT + 99 others); Tue, 5 Mar 2019 08:58:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:39114 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727751AbfCEN6G (ORCPT ); Tue, 5 Mar 2019 08:58:06 -0500 Received: from devnote (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (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 5DEF420842; Tue, 5 Mar 2019 13:58:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551794286; bh=axca7RM4SN0gehRdBNyzipIsMfpZazaIVF9gG36Q4ys=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=OAJyOcYgJ44XdEGMl7EtEAsowKWCC/6gLwXmlCmsMDD7I4+ptG4Bvu5PmHWpRpGJ1 rmvDxarPyhVnwKLuPddRke5xkmPuZyE5QWA43zUBqEUG+Q+8IMiEuFgX2wzOknpvLb R93lZ9OB48C4ifYlTKjMzEXVWrkJVhWzzDikwRQM= Date: Tue, 5 Mar 2019 22:58:01 +0900 From: Masami Hiramatsu To: Peter Zijlstra 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: <20190305225801.a63ac8712105ab2e673be1bc@kernel.org> In-Reply-To: <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> <20190305090729.GF32477@hirez.programming.kicks-ass.net> 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 10:07:29 +0100 Peter Zijlstra wrote: > 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. Hmm, I thought CONFIG_DEBUG_ATOMIC_SLEEP=y tries to detect that some operations which can sleep in atomic, like IRQ context, doesn't it? (note that above should be !pagefault_disabled() anyway) So I guessed WARN_ON_IN_IRQ() intended to detect the access_ok() was used in atomic, because it might follow some copy_from_user() like operation which can sleep when it hits a pagefault. Is my guess wrong? If correct, I think if pagefault is disabled, the caller never sleep, so we don't need to take care of that. Could you tell me why WARN_ON_ONCE(!in_task()) is needed in access_ok()? > > 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. But what would this mean? I can't understand why we limit using access_ok() so strictly and narrow the cases. Thank you, -- Masami Hiramatsu