Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3376944imb; Tue, 5 Mar 2019 07:55:33 -0800 (PST) X-Google-Smtp-Source: APXvYqwnA50CeefbbOR7p1sdbRnZmljhrpmFnqOTbROwifOCbO9jLVYAkEmJcT4XJX+5Nc3NqpM/ X-Received: by 2002:a17:902:d88c:: with SMTP id b12mr1860814plz.339.1551801333758; Tue, 05 Mar 2019 07:55:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551801333; cv=none; d=google.com; s=arc-20160816; b=ixcfVen6HEueglEG1M1gmrW2ll1SlrLLG1MfHNyGXSTalx61Y4gQ84D0CoHBKvnvPl DjDd2ut5Iu/74NXj+jPDhvARZgoR49SMsRU0lY/6KiBAYadNLrUN0X9GZ1bBkIIJ3GYg 2elUrUtgrEgyv8uVLbBFQbRXVyByOVnRqo0jJ3+r+Fw6Ki613nhEK+FPthajaEAWKQkQ uS7H9Mcq1PHU3Y43S0nvUcH0glN95ihHZ0+8XA3thsZYbqLxcNsWDS5tBP8PWO84rMv6 VMnIe9IVw7sgTwKyokv9KSoLZkTBDXxhJS0KasoMZhVStDLQozixms54hGJ+fSjQhC6S G0Qg== 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=kpBXHhoDhAfXirGPHkm7qbEAm0aG0rBMBCcVkDKvtSY=; b=d7XqjtwO+052vJIBSHdexoCkUrkSiuSgcIIcTNeteU5GMTha5qSMohpamTGZ0yP1w4 3EuP+GUM5+exkGuX0z+iF252BnJh5P0GF2qnAiN9bjAekiiIdQbeaJfdYhcn29MvbbI5 tZ0l+HCM9Uioelgt98HpCSdYCXiE/Xk4Tc2Eo4eFssCkQeiTo6DVHoWBgMpSHQ8gv6OL l0qPch4rVzJzwMPTW6TAyRTNvV5HWoW0qWGtcsiICFwv+UYoWIW1MKPstU7t7rmy81ls 2p3KOQxcLKiTRk2zZl+w/f+qxtlfsgZaV+b3jbS+6OCC3XSvYsvItjk9QSQCX2d5qdlh fOnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cl3g1kYH; 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 b64si8145737pgc.218.2019.03.05.07.55.17; Tue, 05 Mar 2019 07:55:33 -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=cl3g1kYH; 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 S1728685AbfCEPSR (ORCPT + 99 others); Tue, 5 Mar 2019 10:18:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:40974 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727114AbfCEPSR (ORCPT ); Tue, 5 Mar 2019 10:18:17 -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 22F2920848; Tue, 5 Mar 2019 15:18:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551799095; bh=wOUquXm9gpv0TOxJKPQvY2wkA5/USc7lFJmXyQtma0A=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=cl3g1kYHSzeKeX5Jg/5jvFh5H9MS6wZWE4NjQyxObCyJuUoZOP7Co2BBe3dQyHCRo Bdwf9QCzll9D/OqbOzZ5NF8E945Nnx87YgkwS7piFLTGQt5WLLkT4zzA4X3TiFF5oP FowaI9V8yP3KlYzwG4snBNTVYC+PzwVHlOJuIflo= Date: Wed, 6 Mar 2019 00:18:11 +0900 From: Masami Hiramatsu To: Peter Zijlstra Cc: g@hirez.programming.kicks-ass.net, 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: <20190306001811.c7cf77cb26b9d816a7561e7b@kernel.org> In-Reply-To: <20190305145306.GL32477@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> <20190305225801.a63ac8712105ab2e673be1bc@kernel.org> <20190305145306.GL32477@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 15:53:06 +0100 Peter Zijlstra wrote: > On Tue, Mar 05, 2019 at 10:58:01PM +0900, Masami Hiramatsu wrote: > > > Could you tell me why WARN_ON_ONCE(!in_task()) is needed in access_ok()? > > That came from here: > > lkml.kernel.org/r/20190225145240.GB32534@hirez.programming.kicks-ass.net > > Because in-irq usage is dodgy, since we don't actually know what mm or > ds it loaded. Yes, I would like to allow it only if setting pagefault-disable correctly. (and setting ds too, it is good to me) > > > > 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. > > Because it's been a source of bugs. Any sanity checking we can put in > seems like a good thing at this point. Hmm, I see yours is strict, fit with current code, but complicated rule. - strncpy_from_user() can access user memory with set_fs(USER_DS) in task context - strncpy_from_user() can access kernel memory with set_fs(KERNEL_DS) in task context - strncpy_from_user() can access user memory in IRQ context if pagefault is disabled and with set_fs(USER_DS). (but pagefault-disabled is not verified) - strncpy_from_user() never allowed to access kernel memory in IRQ context, even if pagefault is disabled and with set_fs(KERNEL_DS). And mine is simple. - strncpy_from_user() can access user memory with set_fs(USER_DS) in task context - strncpy_from_user() can access kernel memory with set_fs(KERNEL_DS) in task context - strncpy_from_user() can access user/kernel memory (depends on DS) in IRQ context if pagefault is disabled. (both verified) Thank you, -- Masami Hiramatsu