From patchwork Fri Nov 13 00:59:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: KP Singh X-Patchwork-Id: 11902335 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8E91C2D0E4 for ; Fri, 13 Nov 2020 00:59:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8089621D79 for ; Fri, 13 Nov 2020 00:59:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="PKma7TRM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726187AbgKMA75 (ORCPT ); Thu, 12 Nov 2020 19:59:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726101AbgKMA74 (ORCPT ); Thu, 12 Nov 2020 19:59:56 -0500 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FB50C0613D6 for ; Thu, 12 Nov 2020 16:59:41 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id p19so7178898wmg.0 for ; Thu, 12 Nov 2020 16:59:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gpc+8RaEdy9qZiZdDQDUeaaADVDGgLUTfDOc8IUPCu4=; b=PKma7TRMmdiNVC9nQ3CYstKP6BtQL0TbUe9TzMWmWdtw5oP2N7Cm/kdclFsCzvyUIu Sx9SiVaxSdhTo36oodx51MWjGdtNJiWqbJjpn33sDPs6N4eeVOyTNkE5dLbjBH2dnvCq 2S58wCBjBQwR7O4klWGvRy2nsAPFu0+xlqiXc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gpc+8RaEdy9qZiZdDQDUeaaADVDGgLUTfDOc8IUPCu4=; b=DRrpJhbHFNp8edPTHC/j88Kb8CTsZ5vEd+0LJgpzioGGWZaGcmr13dt7l4zAyfxb5R v6EyeIA1GeE13Huv3bpJ4uTWyroIudUVZ02mlXMmbaSiuxXuKVBMG/+WwL1XXDezQd7N WDwNV0FEGOzm66imR5/773mbSuhUdoLO3/byQ4jM7NHaBKsWGHy3P8q9no1MAp9LGLVV pya98kpnq32vhoBJGmy2sRFyUT00t+T0Tx2fZ8zBz1/fIuQUiFidowHVexIO8JX1NINQ +hnmJ164vHs+VgbDCVAdJ0/psikB4l52TQeBSICPTxJZP+xN0rthl9DKHmTE1Euw/wnf vx+w== X-Gm-Message-State: AOAM532aM7sqqZUUrhySHCR/lw6k++CjktOyWYNJYYrGzPL/qOcATfC8 wsq+VavAyjofb+jOoE2MGcdh2s5pBg6MSkvr X-Google-Smtp-Source: ABdhPJwqRBtztictHPFaO1CqHOEPx3JAsYtBLem4ynSphW9/ITT1tfLOGIoBNi4uPq61r2hT1i1nhQ== X-Received: by 2002:a7b:cf1a:: with SMTP id l26mr538648wmg.18.1605229179819; Thu, 12 Nov 2020 16:59:39 -0800 (PST) Received: from kpsingh.c.googlers.com.com (203.75.199.104.bc.googleusercontent.com. [104.199.75.203]) by smtp.gmail.com with ESMTPSA id m3sm4508104wrv.6.2020.11.12.16.59.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 16:59:39 -0800 (PST) From: KP Singh To: linux-kernel@vger.kernel.org, bpf@vger.kernel.org Cc: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Jann Horn , Hao Luo , Florent Revest , Brendan Jackman Subject: [PATCH bpf-next v3 2/2] bpf: Expose bpf_d_path helper to sleepable LSM hooks Date: Fri, 13 Nov 2020 00:59:30 +0000 Message-Id: <20201113005930.541956-3-kpsingh@chromium.org> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog In-Reply-To: <20201113005930.541956-1-kpsingh@chromium.org> References: <20201113005930.541956-1-kpsingh@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: KP Singh Sleepable hooks are never called from an NMI/interrupt context, so it is safe to use the bpf_d_path helper in LSM programs attaching to these hooks. The helper is not restricted to sleepable programs and merely uses the list of sleeable hooks as the initial subset of LSM hooks where it can be used. Acked-by: Andrii Nakryiko Signed-off-by: KP Singh --- kernel/trace/bpf_trace.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index e4515b0f62a8..eab1af02c90d 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -1178,7 +1179,11 @@ BTF_SET_END(btf_allowlist_d_path) static bool bpf_d_path_allowed(const struct bpf_prog *prog) { - return btf_id_set_contains(&btf_allowlist_d_path, prog->aux->attach_btf_id); + if (prog->type == BPF_PROG_TYPE_LSM) + return bpf_lsm_is_sleepable_hook(prog->aux->attach_btf_id); + + return btf_id_set_contains(&btf_allowlist_d_path, + prog->aux->attach_btf_id); } BTF_ID_LIST_SINGLE(bpf_d_path_btf_ids, struct, path)