Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp866966pxu; Mon, 23 Nov 2020 06:13:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxVdHuXW2izuvQ3nTyUEMMUp1qrLTwjB1R6IoaX2PQsvMGRiAiokFZkFVdpaSfL92aKyaPg X-Received: by 2002:aa7:c34c:: with SMTP id j12mr48417390edr.17.1606140802232; Mon, 23 Nov 2020 06:13:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606140802; cv=none; d=google.com; s=arc-20160816; b=X3PPFAMpvS1mHy8RLuwaS6buXrKDCEW0zWeX4rX3y4CzYYxGl81sfIgq8gzRdR39/j TM3V1XPrsIWdiLrSfLuWZzqXQmwusqAs9w2FRrMaoW9YN3Gzar9l79HKiRGt0ns42KN3 CNbmDp8Vk5LxBD1EwGR4wtgrkrffl+7HXaHyuQ13HXbzsv35Q+yBU/a2CMmSoNXkjTSm Ag1qZwDgSFGvTWdzhUwaUHig6GiRMKKScQqjDmpCaN3DxlzI4a7jHpGFkG5efshwJQut 30NultBQmZ4tWDB1M61bV3eCczk5juDmtg17USW9fzBZdyw2zJF7v5E80fKz7UMOQD0q b4VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=/6QyWi0R15jxddKhCJoNXPdmNJBgedf7QJ3rmuIGYo8=; b=iz2b/SVUoNb6oWYe22PXZLYRj+cNkP9Og+ukStK7NRVZtjImLWa4cEYYpT6dYS17Zm OUgMyyvkRvvU6S0Z4KwUlziJiZ5a+LMG67Ia8qX1Zpn70zoOZnLCvLgX5lqFiijG/ktG W3mhP2T431VDKmstb1kXQoc1VjUBt7DeSf9IdNoxHq9vVWu8LD/HQE5bWVJ3UkFty/Ew yQe22v0sXa6xnB4USjCtA4SgLdxuliMc0qO7IczgWqiukt6eDSf41JFm1+QJTmuBozRj /F0gC2pjCjX+vK+a3GHidsA90SfmRCQpLCjq3MEpf9G4AiaXcRkfl40NvyTq1BQGSWsh SZIQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q4si6323414edb.455.2020.11.23.06.12.57; Mon, 23 Nov 2020 06:13:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730401AbgKWOLa (ORCPT + 99 others); Mon, 23 Nov 2020 09:11:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:42734 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729794AbgKWOLa (ORCPT ); Mon, 23 Nov 2020 09:11:30 -0500 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (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 7378F20732; Mon, 23 Nov 2020 14:11:28 +0000 (UTC) Date: Mon, 23 Nov 2020 09:11:26 -0500 From: Steven Rostedt To: Petr Mladek Cc: Alan Stern , Sergey Senozhatsky , Kernel development list , Kees Cook , Daniel Borkmann , Linus Torvalds Subject: Re: Printk specifiers for __user pointers Message-ID: <20201123091126.5d6313d2@gandalf.local.home> In-Reply-To: References: <20201120164412.GD619708@rowland.harvard.edu> <20201120134242.6cae9e72@gandalf.local.home> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 23 Nov 2020 10:53:24 +0100 Petr Mladek wrote: > On Fri 2020-11-20 13:42:42, Steven Rostedt wrote: > > On Fri, 20 Nov 2020 11:44:12 -0500 > > Alan Stern wrote: > > > > > To the VSPRINTF maintainers: > > > > > > Documentation/core-api/printk-formats.rst lists a large number of format > > > specifiers for pointers of various sorts. Yet as far as I can see, > > > there is no specifier meant for use with __user pointers. > > > > > > The security implications of printing the true, unmangled value of a > > > __user pointer are minimal, since doing so does not leak any kernel > > > information. So %px would work, but tools like checkpatch.pl don't like > > > it. > > Just to be sure as I am not a security expert. Is there really that > big difference in the risk? The following scenarios come to my mind: One of the biggest differences, is that with exposing the kernel, every process has the same kernel address space. By leaking memory addresses of the kernel, and knowing of some overflow bug in a system call, you can exploit it right away. Also, a user space application could trigger some kind of print to show that kernel address space. With having the kernel show the address space of another process, it is not as easy to exploit. You would need to make that other process do something to have the kernel show its address space. > > 1. The address would show a well defined location in the userspace > application? Could it be used to attack the application? It's possible, but the ramifications usually wont be as bad as the kernel. Unless of course you do it for systemd or some other daemon. But then again, you still need to have that application cause the print, as any user space address being printed from the kernel would need to be caused by that application. > > 2. The address shows a location that is being accessed by kernel. > Could not it be used to pass a value that might be used to attack > kernel? I don't know what you mean here. > > > > > Should a new specifier be added? If not, should we simply use %px? > > > > There's currently no user of '%pu' (although there is a '%pus'. Perhaps we > > should have a '%pux'? > > > > I would even state that if it is used, that if makes sure that the value is > > indeed a user space pointer (goes through the same checks as accessing user > > space), before its printed, otherwise it shows "(fault)" or something. > > I have mixed feelings about this. > > One one hand, it might make sense to mark locations where userspace > address is printed. We could easily decide how to print them (hash or > value) and we could check that it is really from a userspace one. It would definitely need to be checked that it is from user space. > > But I have few concerns: > > 1. The existing "%pus" has a kind of opposite meaning. It says what > address space should be used when the kernel and userspace address > space is overlapping. > > 2. There is the history with "%pk". It did not work because people did > not use it. > > 3. I am not sure about the output when the address is not from > userspace. Printing ("fault") is not much helpful. Printing > hashed value might be confusing. Well, I am still not sure > that it is really safe to print real userspace addresses > by default. We could have it print: "(kernel:)" if it is a kernel address space, and the hash value wont be as confusing if it states "kernel", and by showing the hash value, it may be possible to know what was printed there instead (by possibly seeing another hash with the same value). -- Steve