From mboxrd@z Thu Jan 1 00:00:00 1970 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=-16.6 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham 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 01BF7C282CB for ; Tue, 5 Feb 2019 17:36:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C392C20821 for ; Tue, 5 Feb 2019 17:36:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DENo7a4A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729356AbfBERgt (ORCPT ); Tue, 5 Feb 2019 12:36:49 -0500 Received: from mail-it1-f202.google.com ([209.85.166.202]:43581 "EHLO mail-it1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726550AbfBERgs (ORCPT ); Tue, 5 Feb 2019 12:36:48 -0500 Received: by mail-it1-f202.google.com with SMTP id p124so6858844itd.8 for ; Tue, 05 Feb 2019 09:36:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Q9fKpbZ2qEVipedmSVTcebqa5wWTKQ+vjEWvnCVVATo=; b=DENo7a4AY5ibV5Eox/muYygnBiJQjbaADIQrEIt0xq3hPZmd9IpOyBzClxIDhMMWFl 5nnDPBv6019BD5Sqs2hb+8bP0kNDbNmOSuLO5xWdiJk8bIAkBpOZIIIdqjCb4dhIV4kP 4DZIAOCNu9+yKLtDo8QWJy4LGjPM630H1EzCNBcDTNO5qmKxlhFXK5ekuYWtUY5GUcEg UnfHMz6NHnP7D0ctu0rnioGeu20MWJQSynHsTKCzlNIly4wlT9fAtb1JHNv5UvvKgOeL 58HIEhCxCN219Rm/UM4/VCtjhulZeXZhYO2xciPPnrBhr/yfrZnE8q1gMqeBSKSkIP4X PyqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Q9fKpbZ2qEVipedmSVTcebqa5wWTKQ+vjEWvnCVVATo=; b=QiWdeFgy8dx77YsfYxY9S/mBs4rYBfMgJuXV3pP24TipPBLkJC4MdJ8aQvPUIm7xyM /iMJUbO25cM4QQfvvKYOA2QNeN/91rgnc93c6zXd6klDLVQPlh1C3/hPelfPEU6fjjvE Q04ndGX570jD78HdQbuaGQ05S/CNLBnb/P3RIep7Tlb/LbTNqaEwSmrIbFO056C9c9Om pOBUFwyxIW4hWAcMDXjwRarsLqSsmu7ewBNvmqb3AnQoUIrQlsKS9Ybiibmn3fMq3equ sZLpC1YqHGUMDPzVnvpV6juQwPiE4AHHDlnjPT+pyqKy7y0DLDA8hqy6g3AHqTlPl8m+ XDtQ== X-Gm-Message-State: AHQUAuafZMXwgVCF0D8jzwT3So71noNROnNQMhncpaOUIGXKIXRu5enT OMypl0tAKVN8Xmw36YMRq3mBAa5SQZQKq2z0Mznn0K0tYPy9mvQJMwZ7tN/a5w/dbDPhcdMUTPE ifP6a2eziF3TeFBvXTOu2s1ERvE3w5lAI8/H/eRQHUSRIpt5Xd6jsiQ== X-Google-Smtp-Source: AHgI3IZpO+DEYYFKuRtMAolScfIquobejehcUHu/1ao7IHa6ZFrAIOLU/JUcGMX67Nk0htdCyDXo6Pg= X-Received: by 2002:a24:4c42:: with SMTP id a63mr3772624itb.40.1549388207295; Tue, 05 Feb 2019 09:36:47 -0800 (PST) Date: Tue, 5 Feb 2019 09:36:28 -0800 In-Reply-To: <20190205173629.160717-1-sdf@google.com> Message-Id: <20190205173629.160717-7-sdf@google.com> Mime-Version: 1.0 References: <20190205173629.160717-1-sdf@google.com> X-Mailer: git-send-email 2.20.1.611.gfbb209baf1-goog Subject: [RFC bpf-next 6/7] selftests/bpf: add flow dissector bpf_skb_load_bytes helper test From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, ast@kernel.org, daniel@iogearbox.net, simon.horman@netronome.com, willemb@google.com, Stanislav Fomichev Content-Type: text/plain; charset="UTF-8" Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org With the on-stack skb, we want to make sure we don't trigger any shinfo access. Add small test which tries to read the data past the packet boundary. Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/bpf/test_progs.c | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c index c52bd90fbb34..c12f61efc427 100644 --- a/tools/testing/selftests/bpf/test_progs.c +++ b/tools/testing/selftests/bpf/test_progs.c @@ -1995,6 +1995,54 @@ static void test_flow_dissector(void) bpf_object__close(obj); } +static void test_flow_dissector_load_bytes(void) +{ + struct bpf_flow_keys flow_keys; + __u32 duration, retval, size; + struct bpf_insn prog[] = { + // BPF_REG_1 - 1st argument: context + // BPF_REG_2 - 2nd argument: offset, start at last byte + 1 + BPF_MOV64_IMM(BPF_REG_2, sizeof(pkt_v4)), + // BPF_REG_3 - 3rd argument: destination, reserve byte on stack + BPF_ALU64_REG(BPF_MOV, BPF_REG_3, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_3, -1), + // BPF_REG_4 - 4th argument: copy one byte + BPF_MOV64_IMM(BPF_REG_4, 1), + // bpf_skb_load_bytes(ctx, sizeof(pkt_v4), ptr, 1) + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, + BPF_FUNC_skb_load_bytes), + BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 2), + // if (ret == 0) return BPF_DROP (2) + BPF_MOV64_IMM(BPF_REG_0, BPF_DROP), + BPF_EXIT_INSN(), + // if (ret != 0) return BPF_OK (0) + BPF_MOV64_IMM(BPF_REG_0, BPF_OK), + BPF_EXIT_INSN(), + }; + int fd, err; + + /* make sure bpf_skb_load_bytes helper doesn't cause any + * problems when used with the fake skb in the flow + * dissector (try to read past the last byte) + */ + fd = bpf_load_program(BPF_PROG_TYPE_FLOW_DISSECTOR, prog, + ARRAY_SIZE(prog), "GPL", 0, NULL, 0); + CHECK(fd < 0, + "flow_dissector-bpf_skb_load_bytes-load", + "fd %d errno %d\n", + fd, errno); + + err = bpf_prog_test_run(fd, 1, &pkt_v4, sizeof(pkt_v4), + &flow_keys, &size, &retval, &duration); + CHECK(size != sizeof(flow_keys) || err || retval != 1, + "flow_dissector-bpf_skb_load_bytes", + "err %d errno %d retval %d duration %d size %u/%lu\n", + err, errno, retval, duration, size, sizeof(flow_keys)); + + if (fd >= -1) + close(fd); +} + static void *test_spin_lock(void *arg) { __u32 duration, retval; @@ -2136,6 +2184,7 @@ int main(void) test_queue_stack_map(QUEUE); test_queue_stack_map(STACK); test_flow_dissector(); + test_flow_dissector_load_bytes(); test_spinlock(); test_map_lock(); -- 2.20.1.611.gfbb209baf1-goog