Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2601623rwb; Fri, 2 Dec 2022 12:07:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf7a7V1nsh0QJkxjbbu13sC+wjAG7XbFD/WvBWg7/8tstEtZB+loGM3RtsUSMqXvmszxIDW2 X-Received: by 2002:a05:6a02:187:b0:46b:26a6:51bc with SMTP id bj7-20020a056a02018700b0046b26a651bcmr64243032pgb.204.1670011639248; Fri, 02 Dec 2022 12:07:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670011639; cv=none; d=google.com; s=arc-20160816; b=MKLnMvLuXsL6GlxM0Q9/dvUXrkhX+Jvu9b44lEXpSFwdGCq8ieVthRwD6Qe07VZAfl UMPmby5RcEaHKcqA3gLyWD7HhWA9RGJqHaM0P4UaKRw21BRhEjwKsjCFTuvx2p2KW4Yj whmoPlPXi6cjIhiXVhjZ4/i0TAJsA9TvcEsypdhKnntZeRjTsfp0hRcu9SriMhq21JpM rVcKkW7t0H6OySaKzjpZecsKXmnsseFlFrTjP42Z6HHwnKbMKEvj76iXICjs8khxv8Qo y503SDCpKrZKuGn5THLyo5jFyoEhJQhrliAYrejXXlLuh4bmNqL/S2WDi5e4CCUR+eIU h50w== 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:from:date:dkim-signature; bh=c4lTGxL2A35iMA/bzpPtas8WyqEmZI1JlvurkUw6N00=; b=dRwSD2VOwQZYJDAhxTlpFAp7Ncbvg/yKdOSnihS4hLRhRhyTGCnFJ6Q1nrG4locKDh qw05NmMNnqigxh2PXjEcCJliAila++K9AXdroK7Wc87eSbYCkBTQ50LlpheCW6MDjjHS 7UXyK1B96FUKvdzs6MhTazweczCrt0K4dDIZxaCO6KKmusWHQdDv+2OAWufwOQXcZnPn L3awkUmw+83ONmwnBw/uLWx10WUfu2Z0YO1cYveh3sqvbei9KoFBSKBivKZHKOBeiihO IYbmKM0cHHw0M9C/4lALua/MQGWWrwKO+yu0OzLlO0o30OmY2HNFG3lki60uAWfseJAp UAFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=K9wVvTym; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x24-20020a634a18000000b00478162ac428si7810760pga.211.2022.12.02.12.07.07; Fri, 02 Dec 2022 12:07:19 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=K9wVvTym; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234567AbiLBTat (ORCPT + 82 others); Fri, 2 Dec 2022 14:30:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233679AbiLBTaq (ORCPT ); Fri, 2 Dec 2022 14:30:46 -0500 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F6FFEC80E for ; Fri, 2 Dec 2022 11:30:46 -0800 (PST) Received: by mail-pf1-x42c.google.com with SMTP id c7so2414363pfc.12 for ; Fri, 02 Dec 2022 11:30:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=c4lTGxL2A35iMA/bzpPtas8WyqEmZI1JlvurkUw6N00=; b=K9wVvTymW8HSkZXdGkRKRVJ4ShwxDmAlV0FXM9Kn4q3xgRmi1yVHjeJtZmSohh+Qzm q7bf5bPSMr/w7q6tVBFl9d5BpBzAxoRl/nYhypjJZ21cHW0rCK2ldw1k0efvv4D0EJTY 1OzWvJVn8ujw+AoEGv6PUDn45c2tBx5TemGkewFB9Z+6SlCCve5gBz2AQMQ6ly0p57xc SmjWZbhhuwgeRqc0EvGtkS46cXNYDs3QDhv9yejeIm55KlIfAO1mZP/0qHGUWo8Y7aR/ WfTjWEWI6NkpXNMaMOSsCpk3bsnPYQryLylgadjZ7diaEMQHM8lpz3h0h6z9eWdRxoOa 5EZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=c4lTGxL2A35iMA/bzpPtas8WyqEmZI1JlvurkUw6N00=; b=It3It4qdImz6ydvlteuIEhQ6m4CD1Dw5yripZzKeT0P5pN0B6uUqcHT8om3o7tFbC7 B4HqnIufO1kC189nIiZNDUQKRJXF6kJJhpd/9/N+wd9buGKE58//0ULn9tHMO5oeG5t1 Xz3yPVm54stQ6gYdS6Ogusn3abzfyNmQfxlwX6AI1tAWRkplepO0vB01RT23vaO5j4Dj OHVNhztVPqwyiEVu8aoxHAhLjKZMNc0cxUBBvRo4Jyv0rYFnxIkraqB2E7YdkMD1QtJq tkXF1en1Rr/Pi8OvypOc9us8ygbc7c6SeTMgH7OL1Sdy9gN3+EXXF/nw8uKX6GRz4T6Y atgA== X-Gm-Message-State: ANoB5plRJLYnGE6pgyjGxlSl6tuEq2s+3pYvmpvoYYm4wrUeekr0ymW4 aTLd0rSsbLMyH8DMMvYf+JQ= X-Received: by 2002:a63:2251:0:b0:476:cb2a:b99b with SMTP id t17-20020a632251000000b00476cb2ab99bmr65009694pgm.436.1670009445389; Fri, 02 Dec 2022 11:30:45 -0800 (PST) Received: from macbook-pro-6.dhcp.thefacebook.com ([2620:10d:c090:400::5:c181]) by smtp.gmail.com with ESMTPSA id b16-20020aa79510000000b00574f83c5d51sm5440151pfp.198.2022.12.02.11.30.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 11:30:43 -0800 (PST) Date: Fri, 2 Dec 2022 11:30:39 -0800 From: Alexei Starovoitov To: Benjamin Tissoires Cc: Linus Torvalds , Andrew Morton , Chris Mason , Steven Rostedt , Borislav Petkov , LKML , Masami Hiramatsu , Peter Zijlstra , Kees Cook , Josh Poimboeuf , KP Singh , Mark Rutland , Florent Revest , Greg Kroah-Hartman , Christoph Hellwig Subject: Re: [PATCH] error-injection: Add prompt for function error injection Message-ID: <20221202193039.jle5fek5t5tff2lp@macbook-pro-6.dhcp.thefacebook.com> References: <3fa8ec60-dd96-c41f-ea46-8856bf855949@meta.com> <20221122132905.12a8d5ad@gandalf.local.home> <20221130143719.07e36277d1471b83e9a1b627@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 Fri, Dec 02, 2022 at 03:55:38PM +0100, Benjamin Tissoires wrote: > > > On 12/1/22 22:13, Linus Torvalds wrote: > > On Thu, Dec 1, 2022 at 8:59 AM Alexei Starovoitov > > wrote: > > > > > > The hid-bpf framework depends on it. > > > > Ok, this is completely unacceptably disgusting hack. > > [foreword: I have read the other replies, just replying to this one > because it is the explicit ask for a fix] > > > > > That needs fixing. > > > > > Either hid-bpf or bpf core can add > > > "depends on FUNCTION_ERROR_INJECTION" > > > > No, it needs to be narrowed down a lot. Nobody sane wants error > > injection just because they want some random HID thing. > > > > And no, BPF shouldn't need it either. > > > > This needs to be narrowed down to the point where HID can say "I want > > *this* particular call to be able to be a bpf call. > > So, would the following be OK? I still have a few concerns I'll explain > after the patch. > > --- > From 1290561304eb3e48e1e6d727def13c16698a26f1 Mon Sep 17 00:00:00 2001 > From: Benjamin Tissoires > Date: Fri, 2 Dec 2022 12:40:29 +0100 > Subject: [PATCH] bpf: do not rely on ALLOW_ERROR_INJECTION for fmod_ret > > The current way of expressing that a non-bpf kernel component is willing > to accept that bpf programs can be attached to it and that they can change > the return value is to abuse ALLOW_ERROR_INJECTION. > This is debated in the link below, and the result is that it is not a > reasonable thing to do. > > An easy fix is to keep the list of valid functions in the BPF verifier > in the same way we keep the non-sleepable ALLOW_ERROR_INJECTION ones. > However, this kind of defeat the point of being able to add bpf APIs in > non-BPF subsystems, so we probably need to rethink that part. > > > Link: https://lore.kernel.org/all/20221121104403.1545f9b5@gandalf.local.home/ > Suggested-by: Alexei Starovoitov > Signed-off-by: Benjamin Tissoires > --- > drivers/hid/bpf/hid_bpf_dispatch.c | 2 -- > drivers/hid/bpf/hid_bpf_jmp_table.c | 1 - > kernel/bpf/verifier.c | 20 +++++++++++++++++++- > 3 files changed, 19 insertions(+), 4 deletions(-) > > diff --git a/drivers/hid/bpf/hid_bpf_dispatch.c b/drivers/hid/bpf/hid_bpf_dispatch.c > index 3c989e74d249..d1f6a1d4ae60 100644 > --- a/drivers/hid/bpf/hid_bpf_dispatch.c > +++ b/drivers/hid/bpf/hid_bpf_dispatch.c > @@ -44,7 +44,6 @@ __weak noinline int hid_bpf_device_event(struct hid_bpf_ctx *ctx) > { > return 0; > } > -ALLOW_ERROR_INJECTION(hid_bpf_device_event, ERRNO); > u8 * > dispatch_hid_bpf_device_event(struct hid_device *hdev, enum hid_report_type type, u8 *data, > @@ -105,7 +104,6 @@ __weak noinline int hid_bpf_rdesc_fixup(struct hid_bpf_ctx *ctx) > { > return 0; > } > -ALLOW_ERROR_INJECTION(hid_bpf_rdesc_fixup, ERRNO); > u8 *call_hid_bpf_rdesc_fixup(struct hid_device *hdev, u8 *rdesc, unsigned int *size) > { > diff --git a/drivers/hid/bpf/hid_bpf_jmp_table.c b/drivers/hid/bpf/hid_bpf_jmp_table.c > index 579a6c06906e..207972b028d9 100644 > --- a/drivers/hid/bpf/hid_bpf_jmp_table.c > +++ b/drivers/hid/bpf/hid_bpf_jmp_table.c > @@ -103,7 +103,6 @@ __weak noinline int __hid_bpf_tail_call(struct hid_bpf_ctx *ctx) > { > return 0; > } > -ALLOW_ERROR_INJECTION(__hid_bpf_tail_call, ERRNO); > int hid_bpf_prog_run(struct hid_device *hdev, enum hid_bpf_prog_type type, > struct hid_bpf_ctx_kern *ctx_kern) > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > index 225666307bba..4eac440d659f 100644 > --- a/kernel/bpf/verifier.c > +++ b/kernel/bpf/verifier.c > @@ -24,6 +24,7 @@ > #include > #include > #include > +#include > #include "disasm.h" > @@ -14827,6 +14828,20 @@ static int check_non_sleepable_error_inject(u32 btf_id) > return btf_id_set_contains(&btf_non_sleepable_error_inject, btf_id); > } > +/* Manually tag fmod_ret functions to not misuse ALLOW_ERROR_INJECTION */ > +BTF_SET_START(btf_modify_return) > +#if CONFIG_HID_BPF > +BTF_ID(func, hid_bpf_device_event) > +BTF_ID(func, hid_bpf_rdesc_fixup) > +BTF_ID(func, __hid_bpf_tail_call) > +#endif /* CONFIG_HID_BPF */ > +BTF_SET_END(btf_modify_return) > + > +static int check_function_modify_return(u32 btf_id) > +{ > + return btf_id_set_contains(&btf_modify_return, btf_id); > +} > + > int bpf_check_attach_target(struct bpf_verifier_log *log, > const struct bpf_prog *prog, > const struct bpf_prog *tgt_prog, > @@ -15047,7 +15062,10 @@ int bpf_check_attach_target(struct bpf_verifier_log *log, > bpf_log(log, "can't modify return codes of BPF programs\n"); > return -EINVAL; > } > - ret = check_attach_modify_return(addr, tname); > + ret = -EINVAL; > + if (!check_function_modify_return(btf_id) || > + check_attach_modify_return(addr, tname)) > + ret = 0; > if (ret) { > bpf_log(log, "%s() is not modifiable\n", tname); > return ret; > -- > 2.38.1 > --- > > While this patch removes the need for ALLOW_ERROR_INJECTION it has a > couple of drawbacks: > - suddenly we lose the nice separation of concerns between bpf core and > its users (HID in my case) > - it would need to be changed in 6.3 simply because of the previous > point, so it is just a temporary fix. Agree, but it works short term. A silver lining is BTF_SET approach consumes 4 bytes per mark while ALLOW_ERROR_INJECTION consumes 16 bytes for struct error_injection_entry and then another 48 bytes per mark for struct ei_entry. An alternative would be to define a known prefix like "bpf_modret_" or "bpf_hook_" and rename these three functions. Then there will be no need for #include in bpf core. > So I am not sure if this would qualify HID-BPF for 6.2. Please speak up. Since that was the only thing I think it's fine to stay in the queue.