From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE97BC433E0 for ; Wed, 13 May 2020 23:24:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E2D3220659 for ; Wed, 13 May 2020 23:24:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732600AbgEMXYX (ORCPT ); Wed, 13 May 2020 19:24:23 -0400 Received: from www62.your-server.de ([213.133.104.62]:39596 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732374AbgEMXYW (ORCPT ); Wed, 13 May 2020 19:24:22 -0400 Received: from sslproxy06.your-server.de ([78.46.172.3]) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1jZ0jb-0000nW-H0; Thu, 14 May 2020 01:24:19 +0200 Received: from [178.196.57.75] (helo=pc-9.home) by sslproxy06.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jZ0jb-0007qv-2t; Thu, 14 May 2020 01:24:19 +0200 Subject: Re: [PATCH 11/18] maccess: remove strncpy_from_unsafe To: Linus Torvalds Cc: Christoph Hellwig , the arch/x86 maintainers , Alexei Starovoitov , Masami Hiramatsu , Andrew Morton , linux-parisc@vger.kernel.org, linux-um , Netdev , bpf@vger.kernel.org, Linux-MM , Linux Kernel Mailing List , bgregg@netflix.com References: <20200513160038.2482415-1-hch@lst.de> <20200513160038.2482415-12-hch@lst.de> <20200513192804.GA30751@lst.de> <0c1a7066-b269-9695-b94a-bb5f4f20ebd8@iogearbox.net> From: Daniel Borkmann Message-ID: <2a03633b-419d-643f-b787-ca1520e2229b@iogearbox.net> Date: Thu, 14 May 2020 01:24:18 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.102.2/25811/Wed May 13 14:11:53 2020) Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On 5/14/20 1:03 AM, Linus Torvalds wrote: > On Wed, May 13, 2020 at 3:36 PM Daniel Borkmann wrote: >> >> It's used for both. > > Daniel, BPF real;ly needs to make up its mind about that. > > You *cannot* use ti for both. > > Yes, it happens to work on x86 and some other architectures. > > But on other architectures, the exact same pointer value can be a > kernel pointer or a user pointer. Right, it has the same issue as with the old probe helper. I was merely stating that there are existing users (on x86) out there that use it this way, even though broken generally. >> Given this is enabled on pretty much all program types, my >> assumption would be that usage is still more often on kernel memory than user one. > > You need to pick one. > > If you know it is a user pointer, use strncpy_from_user() (possibly > with disable_pagefault() aka strncpy_from_user_nofault()). > > And if you know it is a kernel pointer, use strncpy_from_unsafe() (aka > strncpy_from_kernel_nofault()). > > You really can't pick the "randomly one or the other guess what I mean " option. My preference would be to have %s, %sK, %sU for bpf_trace_printk() where the latter two result in an explicit strncpy_from_kernel_nofault() or strncpy_from_user_nofault() choice while the %s is converted as per your suggestion and it would still allow for a grace period to convert existing users to the new variants, similar with what we did on the bpf_probe_read_kernel() and bpf_probe_read_user() helpers to get this sorted out. Thanks, Daniel