Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3852372ybf; Tue, 3 Mar 2020 14:14:33 -0800 (PST) X-Google-Smtp-Source: ADFU+vsVCYr1cEMmn1cN3gyBd9xLeXjCa/q1jU16nBq9OgFMOg6R852uTw+jw+rfpDphlrvcvw/S X-Received: by 2002:a05:6830:1112:: with SMTP id w18mr31720otq.185.1583273672986; Tue, 03 Mar 2020 14:14:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583273672; cv=none; d=google.com; s=arc-20160816; b=ZoAFyjYr3PjCGW3s/Sa7lh8hrwBIu6B9hIfTb4cZRNQ3fF4BRv3h2wVo4wWx/a1Rv4 zbd/N42tSIm6S2J/rt5bMG3RNO4yDt1vwZmOBlaVllC8C/73g5H+ImVqIMWCOiJwTmRg GpCiqVkC5u8NK6XR2OHbr4mhf7RJGCxTbk4FU02EDsfbosmfEw1LX02EZK+nBHGanVA/ A4pI6zzRLrF8bd2e2px1Gscu5T6fd6r8g92ZCHDgSmi7Z/3Uw1MhvWGdrS8yMa4f6Duz sYm6pcOqvYbHDn69XusCryaISL8wq+1pkNOXZSJRa+6FvLkCRq7JFSSaWmjWhL+tMGU8 31BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=z7Rh8XJ8kSJSNPMKXViWJCfLmn5XBsgJg4UraZQqhb0=; b=gSgIbyeJoZJfnJmZxXoOsxdi3nSWSo4S/iCyKKeXVPzQXBOVQoHNSgn7VR1MFmzuEq MKHwg65PrapM9M7G4N91THQOXCCtIKXua/ydrG9acscXcokjDDgGIvMVyajV+aBPpNBe RzLmqODElxlxyHHVBeRVfA+XmXWkBba6DFLdJ3raPktClwAFSRa7/hv2UyrU8k7fFYDb n8ANm19L/FRPk1O/ETQBzSbJ+4zV8qP7NPbnLNFaNUan7QeOvle8dscLkGc80ZpELMQ5 ViHE20kusyhOSK7BU/FwB6+S77gV1x0d+Qtzf8rvvbz7ydnLbJRWzvRSWtFFXqH9Zugq P0aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kcEnUWfq; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2si10201741ots.284.2020.03.03.14.14.21; Tue, 03 Mar 2020 14:14:32 -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=@gmail.com header.s=20161025 header.b=kcEnUWfq; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728023AbgCCWM4 (ORCPT + 99 others); Tue, 3 Mar 2020 17:12:56 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:45889 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725932AbgCCWMz (ORCPT ); Tue, 3 Mar 2020 17:12:55 -0500 Received: by mail-qk1-f193.google.com with SMTP id z12so5070236qkg.12; Tue, 03 Mar 2020 14:12:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=z7Rh8XJ8kSJSNPMKXViWJCfLmn5XBsgJg4UraZQqhb0=; b=kcEnUWfqi0L6iLPVhUsKUNmI4LCqCLew+vBo0XSl1jiO4gsYjImV9UVdUUQF+IyuML lK+rF6T0r0cWTcfkgTrNxedI1giynJdjTlT7uLszDmn5FmjqTo/4O/meet2VwgN2waar Va9Lf19/CYr5DMbX6EK9Br6kqfwutNLfJnhommS23UPTmTRaUHJsJoDV8b2jXcsYTGR+ ISG7EoIVXNz6eibszHDZYLyBNi6o8v68KkwJ5QYcmAdeWTBiU7JTfAMMUJPRsDaFWwVL ri6GR/eUCVnz6nRaeJk/xckevsKg8TEe5IpldQx3cu/gx0aTow/UBySsiICvgP65XMA4 Pafg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=z7Rh8XJ8kSJSNPMKXViWJCfLmn5XBsgJg4UraZQqhb0=; b=kCQGpu0GTaaiu6oS28Zrj8ygIpJV7tP8xpnSmb8Eh0QLHgkxlMKhjarxpMfgCULGDV 2R9E5IiogQ66TnroznYhECLPtPSjeYvXCGDIUZO8A48Pol2TSl58NRsS2uptE2lG6dM9 PjZ1lj7vD8Q9MB2qCg5O4jLt/AAtdANksoNpnrxwBh0QmpZigKfUa2Nx48W5HpPko+V5 +dXf6AktdPTAM2XnMEcNieRf6ELOSDQrtArRcaL75XJpZmuHSqF8ofYqdvBM+NCkKfLa U3nGMgbD86sGkSmZbxKE1k1EYvJS7ydFez8MwzquKhciv/K1qn7KCdW7JfVx+3RASysK 4Dfw== X-Gm-Message-State: ANhLgQ2RWbaFkpAaf7mmfYx0O+xwgzoC8BmpGt9LGa4VYMK3YUx+sfnx rsMYhXPrSXwmLgwYcNDC/3PqFxs9B2PTgfmjp2g= X-Received: by 2002:a37:6716:: with SMTP id b22mr175857qkc.437.1583273574509; Tue, 03 Mar 2020 14:12:54 -0800 (PST) MIME-Version: 1.0 References: <20200303140950.6355-1-kpsingh@chromium.org> In-Reply-To: <20200303140950.6355-1-kpsingh@chromium.org> From: Andrii Nakryiko Date: Tue, 3 Mar 2020 14:12:43 -0800 Message-ID: Subject: Re: [PATCH bpf-next 0/7] Introduce BPF_MODIFY_RET tracing progs. To: KP Singh Cc: open list , bpf , Alexei Starovoitov , Daniel Borkmann , Paul Turner , Florent Revest , Brendan Jackman Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(...) > { > // 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 >