Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3444757ybf; Tue, 3 Mar 2020 06:12:36 -0800 (PST) X-Google-Smtp-Source: ADFU+vt0ACwJq1ObQa2CsuXqjY0prGcQ2MUAFSDGLCkbLSchI1SNc8zYuE5Pa5OsMFpnVwQxdW9J X-Received: by 2002:a05:6830:1351:: with SMTP id r17mr3259668otq.227.1583244756395; Tue, 03 Mar 2020 06:12:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583244756; cv=none; d=google.com; s=arc-20160816; b=KV+p+1U7iRTjBBNIb9aLwb1JRyJ6hncTksSgUiCd5g60h172K5M1U/2gj0kn+5a1mh vBefdpNnIElUkUmZG+jOqzkLUg39DZZMpCa19ySEXtkYnedYRPl3L+LkzuvEN/hi2kil aVfdhxJv/A5GCXW5HB5UzxrqWLeT4Ol9Lz51xrnACefPr276UD0fRZY5+O5F90CShgyX vEGP5tExa+S3FDE+X0SjrlpFv5Q7RUFtzY/Xpd7TnvFxhEy7FEbanHT7UwpczG3TNmb1 cownaDFubIWT8kSm0amSzrG8kJJxu5aDlLYGuFOdh2TguRMubCIVPO9igTrsw8qU/o6W hkrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=JL2Fpw/lCnaQ/XUN6zAHALWLaBMkxZHS+mEJ+EF0ZVY=; b=feiv+OGapuE4Dyn1kKN9ydBT5WCbDByXhEWLDGl70zaq+kp8tSARFlxQS9FZZy7aBy vIbmCSWi7rUVx8EvQvKrK4FxedsGLNAbshrYefAxCM82L0IQhCheZKQSHkKpGuANyU86 4NRUhlThTKFa0ovLh2YZ41Zn28tcs7veF1h92mt3XiLTyZunrbxssjuuNq2caBOurDfv S3wysvhVZD0TawfC02Bexv2lVyUU7bJspULOmJom2woK+Np1VhtTxnI3cfrWhOceILXm N7A3eNVSTRXZITn/qpF86zByfktXA3sjPv0F4T+fXIHl3Er0imYyZcpB40O0KpttrJD7 AVXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=laBzjI5h; 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 p3si8539567oih.186.2020.03.03.06.12.20; Tue, 03 Mar 2020 06:12:36 -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=laBzjI5h; 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 S1729551AbgCCOKD (ORCPT + 99 others); Tue, 3 Mar 2020 09:10:03 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:35815 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728533AbgCCOKC (ORCPT ); Tue, 3 Mar 2020 09:10:02 -0500 Received: by mail-wr1-f67.google.com with SMTP id r7so4541842wro.2 for ; Tue, 03 Mar 2020 06:10:01 -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:mime-version :content-transfer-encoding; bh=JL2Fpw/lCnaQ/XUN6zAHALWLaBMkxZHS+mEJ+EF0ZVY=; b=laBzjI5h6krI1uPEgUkHv/ZKSQ+Z8ids/RVkJijNF9hmmkdASTBoYnB/7xl7Hgb1Mg BubzGGprkGLSjK6uC17l7JKFmAuNKQAe7mebom121Rb1ZX7t8afUG1d1oG5ksP4iW46a WR8Rvo74RTKxnPZPwBPH3sMykyYqZfLGRC0mc= 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:mime-version :content-transfer-encoding; bh=JL2Fpw/lCnaQ/XUN6zAHALWLaBMkxZHS+mEJ+EF0ZVY=; b=RWFUkVLdxo65JgdJbVbaY21iGmNe7B3uuz/81FzSwxVefq/mYANFRlBh6gXvDDy1Cb Ig8zN6SsY6XYVwrDER8RDjzvtHgXezfFABbmC8J/QQoDVDN6zuV1+liNCxG/3K6ZudXu Y/fkfJerCckJVSfW82LOvUeD2E3rfwjV5Y1xDIWSGHH+nNNtUFv2425G/XuL+w/QrHNF BnOGoPEIhQ48DXqTUbrjZwHbqYhpl8mCIG8P5pS33lluU+cRkD+WJAVUHSjQaYvT5A0S nCMnfGhu7D3UDQ0vlOddk0dglHociE/U+oj2daYqChD/DkFLpT+4kX/hGgWlgryfgmsS Oa2g== X-Gm-Message-State: ANhLgQ1Pn8ZSCxnHyT9Xe1Zliyl8BbbhfJ6oE0Bt5kWJqKeGKQbwyBBH ZY9Nc5MbsS9FXIp+jXumAfbxtdf6lj4= X-Received: by 2002:a05:6000:10c8:: with SMTP id b8mr5438416wrx.287.1583244600891; Tue, 03 Mar 2020 06:10:00 -0800 (PST) Received: from kpsingh-kernel.localdomain ([2a00:79e1:abc:308:2811:c80d:9375:bf8a]) by smtp.gmail.com with ESMTPSA id h20sm11746823wrc.47.2020.03.03.06.10.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 06:10:00 -0800 (PST) From: KP Singh To: linux-kernel@vger.kernel.org, bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Paul Turner , Florent Revest , Brendan Jackman Subject: [PATCH bpf-next 0/7] Introduce BPF_MODIFY_RET tracing progs. Date: Tue, 3 Mar 2020 15:09:43 +0100 Message-Id: <20200303140950.6355-1-kpsingh@chromium.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) { // 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