Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3726558iob; Tue, 17 May 2022 06:11:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8cDJio9LsBed/9VQn7OK1xFNc7UMcBXKLM8vVRWLSL1zjZfdUSdT4ovpvk4XHzrMPvVmU X-Received: by 2002:a05:6a00:9a2:b0:505:974f:9fd6 with SMTP id u34-20020a056a0009a200b00505974f9fd6mr22481690pfg.12.1652793117789; Tue, 17 May 2022 06:11:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652793117; cv=none; d=google.com; s=arc-20160816; b=xFxe1jiNUawwK96WYUq6vI3doTV/WdVaN5FoJgsAIgrYJZAAPRv6gd5tkrgd5SYxLG BrsA6w1sLjPozOH7WZu8oZzgPrMpw/xSsnFFe6jgFN7wNlMbn7YSc80rajnCd8DcdSQ1 wfyYJeIe467NrjB1yFZ90gVOxyHTlMYjeT89dGgi0w6SkgDLV6KRC05Bf5mUt2y0Fw4v pt9EvoG7XykHHyJpBnhQ4hOhb1B5Bq7QfYZK4Ap5AYNxctSTrYv0UlMd0PC7H5nLEKNS QiI1Uwf0nHNLbwjNcN83RTPIOAb5WykRT+GWnrabkb0wMrZ1KCaHu4bSv8Xzj1UNGIx+ eemQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=pQ8Tbw3YXlfFnImshaS6CSiXIKXl6akxMQXuGl5HlAA=; b=aRvaBVbENyprbG77GcrDyjTGMVL1CEOuKpChFDHBLjEqci48DWJxtHCYmazP48sz5E v+iXXY5Uxw9hXSXQ22moramDIju+X5RRAzqFMVpvVusxyRz7rhGx2b6J1ydMs8kdqLvT DHpmlpvI4ligAqjIjEj4muEM19JldZlkPwe+Dil3WMXyBC+bkarKSJnUc+LP7HLwj/rP xqs8987HUiKSCx7rn7flJTMTvUi/3HD8fnzTDTHYJEl3zIAlxYZE82kTAAs0KpLDaeRt rbmgiX1Fc/nW300FaQlbjqvJuvbUSQDsFLFKP15HiO0KbgFbsLkDkOvmnZROywsqZ44W Pg0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bUYDPIEY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h1-20020a656381000000b00398ebebcaa8si594667pgv.261.2022.05.17.06.11.44; Tue, 17 May 2022 06:11:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bUYDPIEY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241696AbiEQHiD (ORCPT + 99 others); Tue, 17 May 2022 03:38:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241421AbiEQHgw (ORCPT ); Tue, 17 May 2022 03:36:52 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 579C7483AD for ; Tue, 17 May 2022 00:36:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652773008; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=pQ8Tbw3YXlfFnImshaS6CSiXIKXl6akxMQXuGl5HlAA=; b=bUYDPIEYgGGiZJUKm/Elz3BUY44sLTC3SlA5P/xU41dt6r+TQECuNJRGSvcm3bg+kJqAso WGe7aOrm4FIFn3LqyM9ieBGQANPcrwE5PtBBOgOB5SDiQMfjYj34vSfdemttfRqooowDas lS4QIOmqQKuMkIWdYNyimrRYBs8RSRQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-556-Mlcp5x2wPqa4VISOC-SGlw-1; Tue, 17 May 2022 03:36:44 -0400 X-MC-Unique: Mlcp5x2wPqa4VISOC-SGlw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 404C9101AA47; Tue, 17 May 2022 07:36:43 +0000 (UTC) Received: from asgard.redhat.com (unknown [10.36.110.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 771137774; Tue, 17 May 2022 07:36:39 +0000 (UTC) Date: Tue, 17 May 2022 09:36:36 +0200 From: Eugene Syromiatnikov To: Jiri Olsa , Masami Hiramatsu , Steven Rostedt , Ingo Molnar , Alexei Starovoitov , Daniel Borkmann Cc: Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Shuah Khan , linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v3 3/4] bpf_trace: handle compat in copy_user_syms Message-ID: <2a56d66cf4b9430982e81233f49d6c54988df056.1652772731.git.esyr@redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For compat processes, userspace size for syms pointers is different. Provide compat handling for copying array elements from the user space. Fixes: 0dcac272540613d4 ("bpf: Add multi kprobe link") Signed-off-by: Eugene Syromiatnikov --- kernel/trace/bpf_trace.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index a93a54f..9d3028a 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2253,6 +2253,24 @@ struct user_syms { char *buf; }; +static inline int get_arr_ptr(unsigned long *p, + unsigned long __user *uaddr, u32 idx) +{ + if (unlikely(in_compat_syscall())) { + compat_uptr_t __user *compat_uaddr = (compat_uptr_t __user *)uaddr; + compat_uptr_t val; + int err; + + err = __get_user(val, compat_uaddr + idx); + if (!err) + *p = val; + + return err; + } else { + return __get_user(*p, uaddr + idx); + } +} + static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32 cnt) { unsigned long __user usymbol; @@ -2270,7 +2288,7 @@ static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32 goto error; for (p = buf, i = 0; i < cnt; i++) { - if (__get_user(usymbol, usyms + i)) { + if (get_arr_ptr(&usymbol, usyms, i)) { err = -EFAULT; goto error; } -- 2.1.4