Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3254030iob; Mon, 16 May 2022 17:14:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuxl0XTDCi2Ys2kKDoR6oA3Vr7y9oGQ9sEZfs9oCDq0kGaPEeLDCxzgtLZk0/oJC0+Si21 X-Received: by 2002:a17:907:3d91:b0:6f5:2b6a:ef55 with SMTP id he17-20020a1709073d9100b006f52b6aef55mr17861156ejc.352.1652746483976; Mon, 16 May 2022 17:14:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652746483; cv=none; d=google.com; s=arc-20160816; b=yBb6KOfncwqwnJ27T9BOz/KWcrc8ulUs4AeksDYMDuGJyma7wEPpxGy1TIFfAZLYnJ yQuS2tAb+qFdfGdpandr2GrMZVvgGN/yRQWKdosaTVcByKe6MuDXr6XTU7QePMSUCooe INaX+qpkdp+BWMGGv2ThnvUvkH0GkqRnuPpF7xVORmwDK+Wr6+lTgRT5HnAcFkZ1MpPs 39Uo6tIyQAYByDDpzANYobdjwdhJkvxgTXIU4kVyt4Ku38FjuuMngPLU9qS74JOmYt+f vHeXfMf99P1kp3lV1XYdyG3Xf9P851n6f/ScIXE6ZYNUfVXZQAakRxHY2MrZpmx4+Z+L ID7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=/PrpIF0lAA7w2fu9g8XdUbK+AXcZafepF1JXwFuF0QE=; b=za5saALqryAHQUbu3zEpCFPaJm6dvPnBv0twyLZJ2apJwapOXEtYzSoZQCqX87nTe3 owm8cNlnEySZ7uaEcw2tQ+/vYQ7NRa38CzvntZTnusZS+8pfEep5caY0EpqdLTWyvTme 2gBalsF7KWCfiFl1zelXY5EPzfVyNDKAQnG0zlxeI98qMBcDKSMZrdDWXtNuaVRo2bbw ZgdQZ7B1CCDCkUD6eHR0wK8XsbQxqksHgT0KnXGZItLyn1901q5Vcy47Vksx0FxoRs3L ZNjSLnD3sKMm5IhuQwIKjW7x2aPMwN787o40MCjAXmbD6V82eSQ+cVnvGR33ApOAtNZX EeOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VXsBsED4; 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 s20-20020a056402521400b0041d85852a22si13320330edd.190.2022.05.16.17.14.18; Mon, 16 May 2022 17:14:43 -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=VXsBsED4; 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 S235823AbiEPXFn (ORCPT + 99 others); Mon, 16 May 2022 19:05:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350200AbiEPXFf (ORCPT ); Mon, 16 May 2022 19:05:35 -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 26A0946B19 for ; Mon, 16 May 2022 16:05:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652742331; 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; bh=/PrpIF0lAA7w2fu9g8XdUbK+AXcZafepF1JXwFuF0QE=; b=VXsBsED4kne1ikSBSQH9TFOK83oA0c5aYmO1wIiHhYam9bvkSYbQw0MzFjHsALUlReJuLC 6jvv7c7cztP3kzqiiCdBsNwJgTHQDV/UHpopVXOSzwI9N+kRNWFm48ZccUVWsqIj+nPwHU O7v2Somo9Tjr9csl7TdiHq0uNdB7cDQ= 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-442-ZlOt9hVaPm6IfjLVuzpThA-1; Mon, 16 May 2022 19:05:25 -0400 X-MC-Unique: ZlOt9hVaPm6IfjLVuzpThA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C9BCC801210; Mon, 16 May 2022 23:05:24 +0000 (UTC) Received: from asgard.redhat.com (unknown [10.36.110.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D83CF400E122; Mon, 16 May 2022 23:05:20 +0000 (UTC) Date: Tue, 17 May 2022 01:05:17 +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 v2 3/4] bpf_trace: handle compat in kprobe_multi_resolve_syms Message-ID: <20220516230517.GA25568@asgard.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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 pointer size is different. Since the copied array is iterated anyway, the simplest fix seems to be copy the user-supplied array as-is and the iterate as an array of native or compat pointers, depending on the in_compat_syscall() value. Fixes: 0dcac272540613d4 ("bpf: Add multi kprobe link") Signed-off-by: Eugene Syromiatnikov --- kernel/trace/bpf_trace.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index bf5bcfb..268c92b 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2353,16 +2353,19 @@ kprobe_multi_resolve_syms(const void __user *usyms, u32 cnt, unsigned long *addrs) { unsigned long addr, sym_size; - u32 size; + u32 size, elem_size; const char __user **syms; + compat_uptr_t __user *compat_syms; int err = -ENOMEM; unsigned int i; char *func; - if (check_mul_overflow(cnt, (u32)sizeof(*syms), &size)) + elem_size = in_compat_syscall() ? sizeof(*compat_syms) : sizeof(*syms); + if (check_mul_overflow(cnt, elem_size, &size)) return -EOVERFLOW; - size = cnt * sizeof(*syms); + size = cnt * elem_size; syms = kvzalloc(size, GFP_KERNEL); + compat_syms = (void *)syms; if (!syms) return -ENOMEM; @@ -2376,7 +2379,10 @@ kprobe_multi_resolve_syms(const void __user *usyms, u32 cnt, } for (i = 0; i < cnt; i++) { - err = strncpy_from_user(func, syms[i], KSYM_NAME_LEN); + const char __user *ufunc = in_compat_syscall() + ? (char __user *)(uintptr_t)compat_syms[i] + : syms[i]; + err = strncpy_from_user(func, ufunc, KSYM_NAME_LEN); if (err == KSYM_NAME_LEN) err = -E2BIG; if (err < 0) -- 2.1.4