Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3861392ybf; Tue, 3 Mar 2020 14:27:21 -0800 (PST) X-Google-Smtp-Source: ADFU+vsy7IJo2BgiSEB7XVkW6RFIvqsCsE1VBLOa/0Mcvz0Tkl9jr597xUw0lRd9NQi/PEe30N0L X-Received: by 2002:aca:330b:: with SMTP id z11mr533120oiz.96.1583274441129; Tue, 03 Mar 2020 14:27:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583274441; cv=none; d=google.com; s=arc-20160816; b=oxu7HuBt9El5aPBC6KCnEeMLxQqrYKMxjZX8cxecos4FM6MV2dbQDvi7M8AQP0gMey JrT/fuuBwu86YzcBGdFewBS8AFnlNIOAq23iyCIBPhQ58vq8mOncSXcl0fxR2rThDlic eYxG2MEuMGdLIWmHU9Wejks3G/4jsEGctf7QyLhrvJ9zJxaubRlc1KASTL0lwZZMqkXU Zap5C03nJVHJcNwaP8k2HWYzejc4eGP+F84whsj6ihFE9D6vxhRIrS2sSSQOn/o0Fbe0 trENlUXd9PO8hmpcZ38EOEMIWfFnc0mW0exrneLgZ6+OnOROole9d3bgV7Ux2ov08ZZt OrLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:date:from:dkim-signature; bh=gvAxgZ/6W5bHeK8l8B5LmkTF734H/cPgrewZ41WzMkc=; b=HMYPKRUCK6ct5NJeDTxEVkhEqvvxZ/jGR27PFifmIhKjh2EjbqiTqf5PQNrcx4p2Gb lRRIjeTrd5uO0K3L7fxCWaaeuVZnenAYaaT2/vdeNs26Iykf8I7kBq2ghJcUrGDO5C3H XWirkZw+83JdFZyItyXsdkeAoNtq4/Kt6iYIR7gCdhHVJDXSEh0AdTOPKwa5Qrt7zOxj ckm+VFsby1Yizm8P5xXVG/MKeloMn5KJZPxWGTUxUj3mGq/+uKlMrF2tbbKfiG7mVe6a V5ckA6OjDl/zWvQygQ/gQDSirHvc87U5xKiBY24w5hSY2jDKk3Vwx6cSHkcaM/8RUFal KbVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=k4b8wlNW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f187si62065oia.218.2020.03.03.14.27.09; Tue, 03 Mar 2020 14:27:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=k4b8wlNW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727507AbgCCWZv (ORCPT + 99 others); Tue, 3 Mar 2020 17:25:51 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:40691 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726766AbgCCWZv (ORCPT ); Tue, 3 Mar 2020 17:25:51 -0500 Received: by mail-wr1-f68.google.com with SMTP id r17so6491140wrj.7 for ; Tue, 03 Mar 2020 14:25:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=gvAxgZ/6W5bHeK8l8B5LmkTF734H/cPgrewZ41WzMkc=; b=k4b8wlNWPojtXCMpFiS5KbV5zlyci+qf48lnJA1vBqcTxUWZCsgg00p4o+pICG5jpO tyU/foUtvQ7+agLbpxyypl2czslVNrxX/3Z9JKGNJlRHP08hjLWhWQwTWwc0EO4+ti1k I5lRxtvZuUHgTy8zqHmU63CoH8bm8+YITh5/Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=gvAxgZ/6W5bHeK8l8B5LmkTF734H/cPgrewZ41WzMkc=; b=mxRpg1bMQmkN1PY0dd4VFo2MvlEAQFQaWsgtdlRVWtIHsPnl2R1jssL69lkxsBN7+u DIa/hTxcDsLKXmTjbUZjesWJp3LWgZKyu09dxqRsP9dIEz3ZY9GTptxGAZkTIG9AUQeo 7mYVfINQKVOiOiqsnRqFQyv1hzx+FyWFiPX7qMPnoGMQsan3QokvFdvJqxDlRQTHVbcf U5cbDt+iSHQsL1SbRZp1I5tW5MjkqhQhWgeLPnpL8eKmDly2dIu6RDli6hRCl/4A6YMW R7+C1AnFi7ZpBxPMwwBSdG4fx3kl9ekEITaL/1euztZz7/KLC6MMWiJX3RWyNTwE1sCF DpfA== X-Gm-Message-State: ANhLgQ0pUVSTyKz6I5jj/0o6FeY/TxHOS2iZLTasD9xknk/2XMiZGLlj /cQIga7re6XAbyrlbnKa+cHayA== X-Received: by 2002:a5d:62c9:: with SMTP id o9mr83887wrv.2.1583274347840; Tue, 03 Mar 2020 14:25:47 -0800 (PST) Received: from chromium.org (77-56-209-237.dclient.hispeed.ch. [77.56.209.237]) by smtp.gmail.com with ESMTPSA id a7sm37190726wrm.29.2020.03.03.14.25.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 14:25:47 -0800 (PST) From: KP Singh X-Google-Original-From: KP Singh Date: Tue, 3 Mar 2020 23:25:45 +0100 To: Andrii Nakryiko Cc: open list , bpf , Alexei Starovoitov , Daniel Borkmann , Paul Turner , Florent Revest , Brendan Jackman Subject: Re: [PATCH bpf-next 0/7] Introduce BPF_MODIFY_RET tracing progs. Message-ID: <20200303222545.GB3272@chromium.org> References: <20200303140950.6355-1-kpsingh@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03-M?r 14:12, Andrii Nakryiko wrote: > On Tue, Mar 3, 2020 at 6:12 AM KP Singh wrote: > > > > From: KP Singh > > > > This was brought up in the KRSI v4 discussion and found to be useful > > both for security and tracing programs. > > > > https://lore.kernel.org/bpf/20200225193108.GB22391@chromium.org/ > > > > The modify_return programs are allowed for security hooks (with an > > extra CAP_MAC_ADMIN check) and functions whitelisted for error > > injection (ALLOW_ERROR_INJECTION). > > > > The "security_" check is expected to be cleaned up with the KRSI patch > > series. > > > > Here is an example of how a fmod_ret program behaves: > > > > int func_to_be_attached(int a, int b) > > { <--- do_fentry > > > > do_fmod_ret: > > > > if (ret != 0) > > goto do_fexit; > > > > original_function: > > > > > > > > } <--- do_fexit > > > > ALLOW_ERROR_INJECTION(func_to_be_attached, ERRNO) > > > > The fmod_ret program attached to this function can be defined as: > > > > SEC("fmod_ret/func_to_be_attached") > > BPF_PROG(func_name, int a, int b, int ret) > > nit: int BPF_PROG(...) Noted. Thanks! - KP > > > > { > > // This will skip the original function logic. > > return -1; > > } > > > > KP Singh (7): > > bpf: Refactor trampoline update code > > bpf: JIT helpers for fmod_ret progs > > bpf: Introduce BPF_MODIFY_RETURN > > bpf: Attachment verification for BPF_MODIFY_RETURN > > tools/libbpf: Add support for BPF_MODIFY_RETURN > > bpf: Add test ops for BPF_PROG_TYPE_TRACING > > bpf: Add selftests for BPF_MODIFY_RETURN > > > > arch/x86/net/bpf_jit_comp.c | 261 +++++++++++++----- > > include/linux/bpf.h | 24 +- > > include/uapi/linux/bpf.h | 1 + > > kernel/bpf/bpf_struct_ops.c | 13 +- > > kernel/bpf/btf.c | 27 +- > > kernel/bpf/syscall.c | 1 + > > kernel/bpf/trampoline.c | 66 +++-- > > kernel/bpf/verifier.c | 32 +++ > > kernel/trace/bpf_trace.c | 1 + > > net/bpf/test_run.c | 57 +++- > > tools/include/uapi/linux/bpf.h | 1 + > > tools/lib/bpf/libbpf.c | 4 + > > .../selftests/bpf/prog_tests/fentry_fexit.c | 12 +- > > .../selftests/bpf/prog_tests/fentry_test.c | 14 +- > > .../selftests/bpf/prog_tests/fexit_test.c | 69 ++--- > > .../selftests/bpf/prog_tests/modify_return.c | 65 +++++ > > .../selftests/bpf/progs/modify_return.c | 49 ++++ > > 17 files changed, 509 insertions(+), 188 deletions(-) > > create mode 100644 tools/testing/selftests/bpf/prog_tests/modify_return.c > > create mode 100644 tools/testing/selftests/bpf/progs/modify_return.c > > > > -- > > 2.20.1 > >