Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp128193ybm; Wed, 27 May 2020 21:43:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnTNb9+pw3otI79syZRH8BcLJf7GPyBDLjjBSxOz0x7RaB7n5PexApgfHlh47jE0i/FWeq X-Received: by 2002:a17:906:7c5a:: with SMTP id g26mr753471ejp.200.1590641036567; Wed, 27 May 2020 21:43:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590641036; cv=none; d=google.com; s=arc-20160816; b=0XkH1/P3Xz2SJBzs969zH2Epj3x6lKXR5hoF7QNkx8xRLSiv/C6C6pMA2oOPI80KI5 aAAYLe08tbjZ+gX04Ey0q1kPwMdtgoz9h8BvJh5pSwdzTd72jgSfSp16EFrSC+mSSBqB nV3wNBlJVHkDekzzhzuUUdFtiIIfYsL2R5LaBKruaODda8hIxRteERf0Qbvphnn4t4HK U99q3IRhgD3BQ3c86E27eNeSOx7rsTIRSgUbbLqObHwQWfotvhFk25lPf2aJ8p4YqDWH 2X/UD+Xt2wDvsvhWf3nhE5/irSY6AiVDXzf8jh4bkDkYy0bEoM7H5QJ1gQxh9c3grL0h m2fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=ELEuyK36YtWd5JYtN8v0sIrMvlMQTs51qLZrcVjlWLs=; b=rqT325YdyukFCCml5V3JFXR+gMeaQJrgLnqgsQIvm064QKKFCxW2efbdul75GxhLv1 PDDYv0dpyMfu09RtusGehaY/JTa+k2VNxXBCC4DHG5FLbvSkaxL0lw/KgSz6sPh4lQS3 Pke1f51u++eOal7aTR/mez1AbRb0OYqWTBQ3JMMOczTvh3uJ/ICcRn+7HF1OBAWdoQUm +D0buE7N6C9JJE+mgHk4mkFQ6eJ5u2MG9khfJCWLgw72LlTfoySpY6wmR/ir275VHgvt teySVzD2HmiAjLWesHy+a4Hm1OdrARQCIE0r5ppLBDf6zrdOKzZVJY6taWVZJuRDEZfd w88w== 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 bt24si2790473edb.477.2020.05.27.21.42.56; Wed, 27 May 2020 21:43:56 -0700 (PDT) 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 S1726865AbgE1EkB (ORCPT + 99 others); Thu, 28 May 2020 00:40:01 -0400 Received: from verein.lst.de ([213.95.11.211]:54138 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725298AbgE1EkB (ORCPT ); Thu, 28 May 2020 00:40:01 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id C991B68B05; Thu, 28 May 2020 06:39:57 +0200 (CEST) Date: Thu, 28 May 2020 06:39:57 +0200 From: Christoph Hellwig To: Yonghong Song Cc: Andrew Morton , Christoph Hellwig , x86@kernel.org, Alexei Starovoitov , Daniel Borkmann , Masami Hiramatsu , Linus Torvalds , linux-parisc@vger.kernel.org, linux-um@lists.infradead.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 12/23] bpf: handle the compat string in bpf_trace_copy_string better Message-ID: <20200528043957.GA28494@lst.de> References: <20200521152301.2587579-1-hch@lst.de> <20200521152301.2587579-13-hch@lst.de> <20200527190432.e4af1fba00c13cb1421f5a37@linux-foundation.org> <2b64fae6-394c-c1e5-8963-c256f4284065@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2b64fae6-394c-c1e5-8963-c256f4284065@fb.com> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 27, 2020 at 07:26:30PM -0700, Yonghong Song wrote: >> --- a/kernel/trace/bpf_trace.c~xxx >> +++ a/kernel/trace/bpf_trace.c >> @@ -588,15 +588,22 @@ BPF_CALL_5(bpf_seq_printf, struct seq_fi >> } >> if (fmt[i] == 's') { >> + void *unsafe_ptr; >> + >> /* try our best to copy */ >> if (memcpy_cnt >= MAX_SEQ_PRINTF_MAX_MEMCPY) { >> err = -E2BIG; >> goto out; >> } >> - err = strncpy_from_unsafe(bufs->buf[memcpy_cnt], >> - (void *) (long) args[fmt_cnt], >> - MAX_SEQ_PRINTF_STR_LEN); >> + unsafe_ptr = (void *)(long)args[fmt_cnt]; >> + if ((unsigned long)unsafe_ptr < TASK_SIZE) { >> + err = strncpy_from_user_nofault( >> + bufs->buf[memcpy_cnt], unsafe_ptr, >> + MAX_SEQ_PRINTF_STR_LEN); >> + } else { >> + err = -EFAULT; >> + } > > This probably not right. > The pointer stored at args[fmt_cnt] is a kernel pointer, > but it could be an invalid address and we do not want to fault. > Not sure whether it exists or not, we should use > strncpy_from_kernel_nofault()? If you know it is a kernel pointer with this series it should be strncpy_from_kernel_nofault. But even before the series it should have been strncpy_from_unsafe_strict.