From patchwork Tue May 17 07:36:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugene Syromiatnikov X-Patchwork-Id: 12852051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 845F5C433FE for ; Tue, 17 May 2022 07:37:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241606AbiEQHg7 (ORCPT ); Tue, 17 May 2022 03:36:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241557AbiEQHgu (ORCPT ); Tue, 17 May 2022 03:36:50 -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 089354839F for ; Tue, 17 May 2022 00:36:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652773007; 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=H7jSsizinrG8nZErCw/ytFK20Fk3uOSAT2IHyDT5nRYZp/cDlb+P32jQqxa9JFRXytViAh 1Hap16PZJPyckgYQGkbAILxVl34BM1rAPYTKYhThRRwEJh1H1NBEsL4QVRcRnOqZh32VSz MGM0WqFckrFENZCR4mqZ2R8G2JqJj44= 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-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 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@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; }