Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4067001imc; Sun, 24 Feb 2019 20:51:01 -0800 (PST) X-Google-Smtp-Source: AHgI3IagTMdVCmnZ8z5UcxxG3/AhLn+B7HE3QjqtlThmhG954UlrPNoVRw1fZqsok3NdHBnOvMXx X-Received: by 2002:a17:902:ea06:: with SMTP id cu6mr18217176plb.187.1551070261512; Sun, 24 Feb 2019 20:51:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551070261; cv=none; d=google.com; s=arc-20160816; b=B/uBQ91RxH2wgiTC0KN7Q+Y7NyAWFCIuyzJ2E/A6jsKSycdWbAmS4d+eB9wJg1BdeX 2+g06HZMELRQ3Sqb8Y7XphqGZ6/NRVhgwJKHX/tFfKbvo1za1cwtsqoS2I/68X0E4rRl UtFYUVeV7me3+J0ctJf32GF5q+pusFzBTc5DPa8Yt0519FSXrkodBkYGE3Mqkggj8xOc ZAmmgNC2HgOgsNE+3KEBjjQ2RbjLMIlExPYBNXSgeSHn/9ZDg3EwNoVdrTDzwBVNfGiu 576sLrakDJiV5ZwyrXiJG7MYdRy6/Csk0+6MYXs/32337VQZmqsvsjfL4vdMPFpP9fKN Vpqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=QV8Zh3QVVm8++OkMCHYSpFwEC2Bh631c803bchDwylE=; b=l9S0+vsdryPzzGY9WC+4jrera7CQx4iYlFAusPpyIcr8wvSk0nH9otrp8w+uAcr4AM O1bvlXnxrK6kqva62TRkz/ZGQmOreunNUaIj/Ez2n4UR33kwp336XStI1ftbL1N4Mw/p vJeVkWUO2PsQv+enbHzOHRpOrVhfWuGMIaxamw9dXxc12tzURL/ArMIDBl7VOQ5pQG3R lpveDn99CArashdMMiGDM8xZVvci6Ty3tWTjiyqcID5cglmn/7eLk47HqOppX/gN2oOj jnCdlfXToV+CFVx+4Es7T/WLwXnu+FaR3fb+N/67u09w0Z34hCydwkLjkTgOeF3zPHKj rFaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1t209tiy; 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 z11si8575957pgj.140.2019.02.24.20.50.34; Sun, 24 Feb 2019 20:51:01 -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=1t209tiy; 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 S1728473AbfBYEuC (ORCPT + 99 others); Sun, 24 Feb 2019 23:50:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:34724 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726399AbfBYEuC (ORCPT ); Sun, 24 Feb 2019 23:50:02 -0500 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 355E2213A2 for ; Mon, 25 Feb 2019 04:50:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551070200; bh=BuwIf7LAh6cpO/lEaK4StUUzng6d8i+jekXB8LibuiU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=1t209tiyuPKheSVREOdf9r+Ht59p1NdyXQDfojwCctFIGXDvWYXkz6ygkIgt72s0a LXr1AlkhLhM26eYA3cVwKtKq6NUIWqYN7yIK2AVFna1uzMC0RSUr+ukOyAUYt6xcCf lOH/n05HoSR18zVJu1QP5VmMWTDU2GI9Bqw9y29g= Received: by mail-wr1-f47.google.com with SMTP id o17so8353710wrw.3 for ; Sun, 24 Feb 2019 20:50:00 -0800 (PST) X-Gm-Message-State: AHQUAuaTgwc/+lzD+VcvnlbpiNMnqoar6an0VWgHTRzMJ8/akz4cy2BF 4slK6L5wEC2WOfXgT1dX55VglAh0EYIrb/PRjc8bzg== X-Received: by 2002:adf:e747:: with SMTP id c7mr10639434wrn.176.1551070198663; Sun, 24 Feb 2019 20:49:58 -0800 (PST) MIME-Version: 1.0 References: <20190215174712.372898450@goodmis.org> <20190215191949.04604191@gandalf.local.home> <20190219111802.1d6dbaa3@gandalf.local.home> <20190219140330.5dd9e876@gandalf.local.home> <20190220171019.5e81a4946b56982f324f7c45@kernel.org> <20190220094926.0ab575b3@gandalf.local.home> <20190222172745.2c7205d62003c0a858e33278@kernel.org> <20190222173509.88489b7c5d1bf0e2ec2382ee@kernel.org> <20190223124746.d021973004c7c892c3b3fde1@kernel.org> <20190223194421.725a03fd@oasis.local.home> <20190225001757.519f40cd088c05fdd00a9397@kernel.org> <20190225114025.902c9031075e2f1fc55369a3@kernel.org> In-Reply-To: <20190225114025.902c9031075e2f1fc55369a3@kernel.org> From: Andy Lutomirski Date: Sun, 24 Feb 2019 20:49:45 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/2 v2] kprobe: Do not use uaccess functions to access kernel memory that can fault To: Masami Hiramatsu Cc: Linus Torvalds , Andy Lutomirski , Steven Rostedt , Linux List Kernel Mailing , Ingo Molnar , Andrew Morton , stable , Changbin Du , Jann Horn , Kees Cook , Peter Zijlstra Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Feb 24, 2019 at 6:40 PM Masami Hiramatsu wrote: > > On Sun, 24 Feb 2019 09:26:45 -0800 > Linus Torvalds wrote: > > > On Sun, Feb 24, 2019 at 7:18 AM Masami Hiramatsu wrote: > > > > > > On Sat, 23 Feb 2019 20:38:03 -0800 > > > Andy Lutomirski wrote: > > > > > > > > Can we just get rid of this might_sleep()? access_ok() doesn't sleep > > > > as far as I know. > > > > > > Hmm, which might_sleep() would you pointed? What I talked was a > > > WARN_ON_ONCE(!in_task()) in access_ok() on x86 (only!), and in_task() just > > > checks preempt_count. > > > > So the in_task() check does kind of make sense. Using "access_ok()" > > outside of task context is certainly an odd thing, for several > > reasons. The main one being simply that outside of task context, the > > whole "which task" question is open, and you don't know if the task is > > the active one, and so it's not clear if whatever task you interrupt > > might have done "set_fs()" or not. > > Ah I got it. Usual case access_ok() in IRQ handler is strange. > > > > > So PeterZ isn't wrong: > > > > > I guess PeterZ assumed that access_ok() is used only with user space access > > > APIs (e.g. copy_from_user) which can cause page-fault and locks mm (and might > > > sleep :)), but now we are trying to use access_ok() with new functions which > > > disables page-fault and just return -EFAULT. > > > > .. but in this case, if we do it all *within* code that saves and > > restores the user access flag with get_fs/set_fs, access_ok() would be > > ok and it doesn't have the above issue. > > > > So access_ok() in _general_ is absolutely not safe to do from > > interrupts, but within the context of probing user memory from a > > tracing event it just happens to be ok. > > Hmm, but user can specify user-memory access from the tracing event > which is located in interrupt handler. So I understand that it is safe > only if we correctly setup access flag with get_fs/set_fs, is that > correct? > > > It would be lovely to have a special macro for this, and keep the > > warning for the general case, but because this is a "every > > architecture needs to build their own" it's probably too painful. > > Agreed. This should probably go with whatever effort makes nmi_uaccess_ok() available on all architectures. That being said, how about just making copy_from_user_nmi() work on all architectures, even if it just fails unconditionally on some of them?