Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp135819iob; Tue, 17 May 2022 21:27:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2xvaAxMGxAwTQZbg4Y7ddbPc8DQfaQG00Zp0ms4knFHIpRrOiY+MUT1GK6CDT777kHC70 X-Received: by 2002:a17:902:e2d2:b0:161:a6d8:3a0e with SMTP id l18-20020a170902e2d200b00161a6d83a0emr6522013plc.79.1652848066419; Tue, 17 May 2022 21:27:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652848066; cv=none; d=google.com; s=arc-20160816; b=rtlRZVRkysoIilMcpTTnLOq2KVS/1XeA5GlDlEkKRjfaMuPkRtGEmhgQ+5Lo3r5q6X UPovV9ZaQ+YkpprVKPZHb17yNtrg0N+H1jTZFTRennrvFlyHaqQu1G0d/5jeZdGni64x iqGLpwcAq1oB6t+NvWHPNWtusQYCMVy/puZHzN3rfjc2ptTLscVZQm6eCSO/Ih0MgZxA or+np7NU6PvLIdW7w9pUYZnIkQobSTdnTzuNMgoi/GeO66YSi0O3DfJ+T/hfESekWB5A /C/W3xxnmj0ScbfDF3L/pi5ePJnsK8iGarQ/JSsxaoGxx7PjeFagKZnzlvyBQuj7lAXO 4bxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:date:from:dkim-signature; bh=krprm27rZ7iPBdo6XYTUP4wdNhee1KynZMic612/ZrY=; b=NzK0intxUez6hEJmtDW+FOa1cNT2ThyTgAXbYPSvG9c2Kqa7i+VHov6xCKx7fXkuqo ImEQAWbTj2NEnp6gFZh92DUui+nwT25jNhGLs9UxIf0ls++lycAtzmgPR7lDi+5qFkjH oafkP2cOac49kZUsFolLBG9ZTrPymEH54Qbehd0wYGamk8WQbJW9EnbRgQ5DyyNQp3UL GRJRFUI4OMWZdzmuInqV3fm+i96Z6tTtGmGVQ8M0FmwbZ7U+Tx1mdS9SeQVT744fbUcb Mv7+5tEuRgbkng219dZEMl/sxBAW08OZPlxpmjJd+bt79qBl3uOFPl+gPDFAd415TN7i beTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=MWAeWZpS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id h6-20020a170902f7c600b0015f13887fe4si1300602plw.200.2022.05.17.21.27.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 21:27:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=MWAeWZpS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 64BB18CB38; Tue, 17 May 2022 20:50:33 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243768AbiEQJNS (ORCPT + 99 others); Tue, 17 May 2022 05:13:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243998AbiEQJMy (ORCPT ); Tue, 17 May 2022 05:12:54 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D528639E; Tue, 17 May 2022 02:12:52 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id s3so6369794edr.9; Tue, 17 May 2022 02:12:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=krprm27rZ7iPBdo6XYTUP4wdNhee1KynZMic612/ZrY=; b=MWAeWZpS8cfoTVdcyZxBXKRbq7drUp8r9kHb7b8Im/3e4UoBgtoo9MLHBTJyUT/H/9 pJVQL2yCClxYbt2qEEzyUXy1MZWg9mGuYzuaSSekxV8fQ5DcSXqt083A19IjKwOjPUFn FhgVsAlsr6PqRsL8VjYnpET7JZZLQZCpTUjralaXzutM2Ohy5XkHp+/nqC4n9YBZnuiL aKBtoA4BaRqGch9/Cu+DTAfs3ExXjMSuYxfNusMwx2u+KZVHP7DVP2+flqzJTXw+LUzt NE7bIlcZAZ79obRDAtqBW+3s7GVzDWzztrghd6tLsFSP4foAu6Xoa4miXuPqcLnBJkTE jPHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=krprm27rZ7iPBdo6XYTUP4wdNhee1KynZMic612/ZrY=; b=vkfe/fyJVmiDWAjhkvi1SOz01L3e0O9Pie7GmzLHolKvNI0/jd30PlP4Ryf/le43f+ xfQDoBkiygrSJpJxUmjEloSl+lcBqlEei7QxhnLq8U5JaWirR8r+R8m04huR+wAbnOjv 0UECsHLXoUuProoNwrzXm7aXzviTOttF4r0tOzYFuMal42deUwSha/QwChvpIATs9ZpC ywhy/sWe7D49aemIvLXZJjsfgFvvmmWDdadrBsDviEbCIIp8fTXbf1Ll+ZHHCMqspyB7 i2t8FHeOJIuYP5rgEHO/8CD3fQcen1K5M6x3v8YqRfFo7JAIxJ0Jy1ij74sTxEGLsrs0 ss6g== X-Gm-Message-State: AOAM531IGt1mCxiA+JjPcJdS3OF/RnsGtKfHynCW67uCvZ0L9bfdg7z7 PuU8f0FWrJUaZvuv7mKdprs= X-Received: by 2002:a05:6402:1941:b0:413:2555:53e3 with SMTP id f1-20020a056402194100b00413255553e3mr18035453edz.164.1652778770555; Tue, 17 May 2022 02:12:50 -0700 (PDT) Received: from krava ([193.85.244.190]) by smtp.gmail.com with ESMTPSA id g25-20020a056402115900b0042aaacd4edasm3844208edw.26.2022.05.17.02.12.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 02:12:50 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Tue, 17 May 2022 11:12:47 +0200 To: Eugene Syromiatnikov Cc: Masami Hiramatsu , Steven Rostedt , Ingo Molnar , Alexei Starovoitov , Daniel Borkmann , 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: Re: [PATCH bpf-next v3 2/4] bpf_trace: support 32-bit kernels in bpf_kprobe_multi_link_attach Message-ID: References: <525b99881dc144b986e381eb23b12617a311f243.1652772731.git.esyr@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <525b99881dc144b986e381eb23b12617a311f243.1652772731.git.esyr@redhat.com> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Tue, May 17, 2022 at 09:36:26AM +0200, Eugene Syromiatnikov wrote: > It seems that there is no reason not to support 32-bit architectures; > doing so requires a bit of rework with respect to cookies handling, > however, as the current code implicitly assumes > that sizeof(long) == sizeof(u64). > > Signed-off-by: Eugene Syromiatnikov > --- > kernel/trace/bpf_trace.c | 17 ++++++++--------- > 1 file changed, 8 insertions(+), 9 deletions(-) > > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c > index 9c041be..a93a54f 100644 > --- a/kernel/trace/bpf_trace.c > +++ b/kernel/trace/bpf_trace.c > @@ -2435,16 +2435,12 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr > struct bpf_link_primer link_primer; > void __user *ucookies; > unsigned long *addrs; > - u32 flags, cnt, size; > + u32 flags, cnt, size, cookies_size; > void __user *uaddrs; > u64 *cookies = NULL; > void __user *usyms; > int err; > > - /* no support for 32bit archs yet */ > - if (sizeof(u64) != sizeof(void *)) > - return -EOPNOTSUPP; > - > if (prog->expected_attach_type != BPF_TRACE_KPROBE_MULTI) > return -EINVAL; > > @@ -2454,6 +2450,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr > > uaddrs = u64_to_user_ptr(attr->link_create.kprobe_multi.addrs); > usyms = u64_to_user_ptr(attr->link_create.kprobe_multi.syms); > + ucookies = u64_to_user_ptr(attr->link_create.kprobe_multi.cookies); > if (!!uaddrs == !!usyms) > return -EINVAL; > > @@ -2461,8 +2458,11 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr > if (!cnt) > return -EINVAL; > > - if (check_mul_overflow(cnt, (u32)sizeof(*addrs), &size)) > + if (check_mul_overflow(cnt, (u32)sizeof(*addrs), &size) || > + (ucookies && > + check_mul_overflow(cnt, (u32)sizeof(*cookies), &cookies_size))) { > return -EOVERFLOW; > + } > addrs = kvmalloc(size, GFP_KERNEL); > if (!addrs) > return -ENOMEM; > @@ -2486,14 +2486,13 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr > goto error; > } > > - ucookies = u64_to_user_ptr(attr->link_create.kprobe_multi.cookies); > if (ucookies) { could we check all that in here? so the ucookies checks are on the one place.. also you would not need cookies_size jirka > - cookies = kvmalloc(size, GFP_KERNEL); > + cookies = kvmalloc(cookies_size, GFP_KERNEL); > if (!cookies) { > err = -ENOMEM; > goto error; > } > - if (copy_from_user(cookies, ucookies, size)) { > + if (copy_from_user(cookies, ucookies, cookies_size)) { > err = -EFAULT; > goto error; > } > -- > 2.1.4 >