Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1505075ybk; Thu, 21 May 2020 08:26:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEfWopeCgHzIVBBv7N2uQ8S7oFOfxyYu47sW337xrq7UWWOiRJdeGOfJi22YsTG2P6V2I/ X-Received: by 2002:a17:906:eda5:: with SMTP id sa5mr3944089ejb.289.1590074776237; Thu, 21 May 2020 08:26:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590074776; cv=none; d=google.com; s=arc-20160816; b=hxV/KB0RvAe+GorW3P4nKUXSa45M3z/oTQNKVQdv/4/K2hlB82fXCNGwC1KQL+i2wc 6Aa+RgW6MadOOYOU3mGt/0MgZoggpZyefMLkUVKnTg57KWUeRpuXujg6zuiTrkzO1V91 nOb5gBdAJItER24eSjhSFMXW8pluEUnpaTwQROOK1SFcDDFVU0eQVdp6wPFr3SuMx4gW 37MLKet1fS/ya0L+F9kfUimYvNWwWBeCDiDH5oTc7ECm6hL/dHOXUP4F2yqy7EimY8E+ wHYoh6nzwQyuWNKcyWEws2uPgejUAlH5cmIf9yn1FvntCj8T2oqRD/rgew1pJXo4HkDG Ct1Q== 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:date:subject:cc:to:from :dkim-signature; bh=fI4BRYe9whyI1lE6Uh0NEnF4iP7fYZaJTzPrp5Za6uo=; b=Qh3YH6dhKt4RgvF2XIMurawsH4T3U3ab1Jk6byK9euFhXyOpwOPKmV+LyEEdxEgmJT bBefgsqJvxgIY0/VAQ5W8EvSITvy0zL7d4kTcpogKNWrj3Zu4SeLnFotntTN4CMYESOP K2HCxiFcS4me4V4CcpHy+uPds3HSx1kdGFcntTAbdIWTS7q+lBeFeUjQ184QhamDXQfq BoWLpw6wZKxV0e96uTjkv0cFKr4sD4qMEWDf23qV3Xjlw0plRCoW+1uxY8KNo1AkuMum VNHKiJw9SxqEGleTP3hePo/QwbtJc+s/jxqMPRyig98y3CfjCULX1cHMCVTx1SBw8WJC iuTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="Rc9O/LwX"; 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 g9si3260390edu.25.2020.05.21.08.25.53; Thu, 21 May 2020 08:26:16 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="Rc9O/LwX"; 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 S1730185AbgEUPXp (ORCPT + 99 others); Thu, 21 May 2020 11:23:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730169AbgEUPXl (ORCPT ); Thu, 21 May 2020 11:23:41 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9938FC061A0E; Thu, 21 May 2020 08:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=fI4BRYe9whyI1lE6Uh0NEnF4iP7fYZaJTzPrp5Za6uo=; b=Rc9O/LwXdxzubF/e2bxMkK9d4f UhDXZm1zKBeKIKj9/Jz1Y/K5qnzv0S8NKWwxSg5bKdgdANSeHGV7KRYVGMH9+l0QVqmZvSCZmnGX9 qYxlc+F8UryHEcpA7FKBhBekDVxkG7T+4hX9klro7vBfN6bG/qV31zyNMAv1CeRwz+w7RTdwsr/Yu HmzRsi5rg7lZwATK3Hm8ID1GMejSC4+E/Ul4LxzW1cgDD7SvARSgrJrDJ+fA4s6kSVr/CwZnIhpCe j3S1EHwmmy/IwapVI6M3pg0CMB8ohnyHLd0jPrsbxI8JXy8OYSnnVv4r00AznrYv4pY0YRANLFzMi vZOZqSXA==; Received: from [2001:4bb8:18c:5da7:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jbn2p-0004TG-H2; Thu, 21 May 2020 15:23:40 +0000 From: Christoph Hellwig To: x86@kernel.org, Alexei Starovoitov , Daniel Borkmann , Masami Hiramatsu , Linus Torvalds , Andrew Morton Cc: 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: [PATCH 12/23] bpf: handle the compat string in bpf_trace_copy_string better Date: Thu, 21 May 2020 17:22:50 +0200 Message-Id: <20200521152301.2587579-13-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521152301.2587579-1-hch@lst.de> References: <20200521152301.2587579-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org User the proper helper for kernel or userspace addresses based on TASK_SIZE instead of the dangerous strncpy_from_unsafe function. Signed-off-by: Christoph Hellwig --- kernel/trace/bpf_trace.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 9d4080590f711..737d739230a6b 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -331,8 +331,11 @@ static void bpf_trace_copy_string(char *buf, void *unsafe_ptr, char fmt_ptype, switch (fmt_ptype) { case 's': #ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE - strncpy_from_unsafe(buf, unsafe_ptr, bufsz); - break; + if ((unsigned long)unsafe_ptr < TASK_SIZE) { + strncpy_from_user_nofault(buf, user_ptr, bufsz); + break; + } + fallthrough; #endif case 'k': strncpy_from_kernel_nofault(buf, unsafe_ptr, bufsz); -- 2.26.2