Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp852908pxb; Fri, 22 Apr 2022 12:38:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNR1r5RgLS5MMzDu4Fx55Ob4qwODekIkz5YWBGfZjvD60hQMitp+1I5WsRX4VvE+o2IfSn X-Received: by 2002:a17:903:204:b0:15a:35be:58b3 with SMTP id r4-20020a170903020400b0015a35be58b3mr5979795plh.123.1650656305264; Fri, 22 Apr 2022 12:38:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650656305; cv=none; d=google.com; s=arc-20160816; b=BW/fJZOagWhDOgB4W6S/VgTCjLzfXijvvuhL5PNbEuxLL29NG1RxRVdy07KspV6pMI Z3WVrRWJf5Giqy48YuEaCs1NNv1SJR72PH56mdAi7Qn5po0XIXUOPwsshb6XC5UF5py+ vaVtEBDM9amSqjQLthr7jydsojGwhXeaB4O1ttbGSlEfxmDJmV2I1zL0ggCa5a6xvzNo 29W+xo+OZVTl+pLmAUrPmUKe1NStTox4EEkphkYnJ6zRWf6G9yVLU0CE2xnrb9YMta17 x6HMy5iTasFi3Pr5/BgvyQP8s3ADsdzVxlwzLkSpC5+cZlYtumqYmvsM7jpN5uhaa6Ik lSwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=howYSQGYDpGf0MCMMnBxueOpghmy2sP/424mO8pl1yc=; b=FOfPWIaIrSTwZxFQYY/ycFQ4dM7C17Icli8SQq938ptRps2PBglpk4Xl+T0Kv19ezD cZhDoCkIMx6PszF5EM89klci++Bc+H7JS7Jn2H+Wvy/QselUkWFgEjA2YGDoareLdpv0 f/W1aGgGhSereOzFtMKX/uE9eXRCFQCcmpg96epdrzblGJSC6txc9LlzvwY9OZaL2pqK B/yiBTMTDpAyOk1TSSZtnvPj8sc0NuvyLWSXeMWqy9KVV/L50ukJB+J3zzxU4hyh4zN8 cdWb8kdg5uoilQINdHog6W+WaJ4bDtPgwFlJu9tEffSliftM7xdpm/4Brte1DtwVjNYz stbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MPm4om4X; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q6-20020a056a00150600b0050c49f8ce5csi4583588pfu.271.2022.04.22.12.38.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 12:38:25 -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=@redhat.com header.s=mimecast20190719 header.b=MPm4om4X; 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=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1C54B16FAE9; Fri, 22 Apr 2022 11:48:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388993AbiDUOLD (ORCPT + 99 others); Thu, 21 Apr 2022 10:11:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1388836AbiDUOKr (ORCPT ); Thu, 21 Apr 2022 10:10:47 -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 E4C3DD46 for ; Thu, 21 Apr 2022 07:07:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650550077; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=howYSQGYDpGf0MCMMnBxueOpghmy2sP/424mO8pl1yc=; b=MPm4om4X6H2+Ca2lMAp8kkRhlTnWgsEDfITOFA9tJuXY3iqWodd99/8OWYEyYmEGA8hlEC GYW/2ehoMIGd9o+ovl2QaJkqX5u7Vem7JPfVdxhYAkgmBFvRXfoQSjJIit6K2UeJP28F52 /Ae2i/Xd6d4py664PUMj+0gvDzJ71NY= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-586-orAbwtltMvCYuCFo9f0gcw-1; Thu, 21 Apr 2022 10:07:53 -0400 X-MC-Unique: orAbwtltMvCYuCFo9f0gcw-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 ABDFE1E1AE69; Thu, 21 Apr 2022 14:07:52 +0000 (UTC) Received: from plouf.redhat.com (unknown [10.39.194.205]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9AEB840EC002; Thu, 21 Apr 2022 14:07:50 +0000 (UTC) From: Benjamin Tissoires To: Greg KH , Jiri Kosina , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh Cc: Tero Kristo , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, bpf@vger.kernel.org, Benjamin Tissoires Subject: [RFC bpf-next v4 3/7] error-inject: add new type that carries if the function is non sleepable Date: Thu, 21 Apr 2022 16:07:36 +0200 Message-Id: <20220421140740.459558-4-benjamin.tissoires@redhat.com> In-Reply-To: <20220421140740.459558-1-benjamin.tissoires@redhat.com> References: <20220421140740.459558-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE 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 When using error-injection function through bpf to change the return code, we need to know if the function is sleepable or not. Currently the code assumes that all error-inject functions are sleepable, except for a few selected of them, hardcoded in kernel/bpf/verifier.c Add a new flag to error-inject so we can code that information where the function is declared. Signed-off-by: Benjamin Tissoires --- new in v4: - another approach would be to define a new kfunc_set, and register it with btf. But in that case, what program type would we use? BPF_PROG_TYPE_UNSPEC? - also note that maybe we should consider all of the functions non-sleepable and only mark some as sleepable. IMO it makes more sense to be more restrictive by default. --- include/asm-generic/error-injection.h | 1 + kernel/bpf/verifier.c | 10 ++++++++-- lib/error-inject.c | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/asm-generic/error-injection.h b/include/asm-generic/error-injection.h index fbca56bd9cbc..5974942353a6 100644 --- a/include/asm-generic/error-injection.h +++ b/include/asm-generic/error-injection.h @@ -9,6 +9,7 @@ enum { EI_ETYPE_ERRNO, /* Return -ERRNO if failure */ EI_ETYPE_ERRNO_NULL, /* Return -ERRNO or NULL if failure */ EI_ETYPE_TRUE, /* Return true if failure */ + EI_ETYPE_NS_ERRNO, /* Return -ERRNO if failure and tag the function as non-sleepable */ }; struct error_injection_entry { diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 0f339f9058f3..45c8feea6478 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -14085,6 +14085,11 @@ static int check_non_sleepable_error_inject(u32 btf_id) return btf_id_set_contains(&btf_non_sleepable_error_inject, btf_id); } +static int is_non_sleepable_error_inject(unsigned long addr) +{ + return get_injectable_error_type(addr) == EI_ETYPE_NS_ERRNO; +} + int bpf_check_attach_target(struct bpf_verifier_log *log, const struct bpf_prog *prog, const struct bpf_prog *tgt_prog, @@ -14281,8 +14286,9 @@ int bpf_check_attach_target(struct bpf_verifier_log *log, /* fentry/fexit/fmod_ret progs can be sleepable only if they are * attached to ALLOW_ERROR_INJECTION and are not in denylist. */ - if (!check_non_sleepable_error_inject(btf_id) && - within_error_injection_list(addr)) + if (within_error_injection_list(addr) && + !check_non_sleepable_error_inject(btf_id) && + !is_non_sleepable_error_inject(addr)) ret = 0; break; case BPF_PROG_TYPE_LSM: diff --git a/lib/error-inject.c b/lib/error-inject.c index 2ff5ef689d72..560c3b18f439 100644 --- a/lib/error-inject.c +++ b/lib/error-inject.c @@ -183,6 +183,8 @@ static const char *error_type_string(int etype) return "ERRNO_NULL"; case EI_ETYPE_TRUE: return "TRUE"; + case EI_ETYPE_NS_ERRNO: + return "NS_ERRNO"; default: return "(unknown)"; } -- 2.35.1