From patchwork Mon May 18 20:02:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Fastabend X-Patchwork-Id: 219059 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=-6.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS 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 ADF0FC433DF for ; Mon, 18 May 2020 20:03:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 81A33206D4 for ; Mon, 18 May 2020 20:03:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Y61lJUBm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726729AbgERUDH (ORCPT ); Mon, 18 May 2020 16:03:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726250AbgERUDG (ORCPT ); Mon, 18 May 2020 16:03:06 -0400 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9183DC061A0C; Mon, 18 May 2020 13:03:06 -0700 (PDT) Received: by mail-il1-x142.google.com with SMTP id c20so9000896ilk.6; Mon, 18 May 2020 13:03:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=hGopJ23Awe8jxA58mwcFFf07exvBHSCVePFTn+MGlQQ=; b=Y61lJUBmeumknlNq+e891qmunLIGNScJ8uK218PAslIp7gr7/zt/YsCop/t94uow6j 2PjB774TQw4Q6MUB3pvDfpSO0v1mdUD+i5cmh/Yh0CE4LCzNSOQBrT/FLJ1ZlWd/y8Ta yZZp14DzGJ2PrIEtl2aEl0oqktBkb6TmEgkQIOYM3r1wLFFLNOSmDc0IK4oclCu7CtPK BYxGZffhDNcyS3Wf91C0ISdXdrUQyES2LFk6wNWyCzW2bPpaHEF1ClTAhR9zC3eWXCgu 1UcY6R0pe0ZYb+vMJrBLDlQ7E4Ri2KC0wTIAuW9zFwVm1hxlFptaQmB9WrqpzlEsaZN0 EWig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=hGopJ23Awe8jxA58mwcFFf07exvBHSCVePFTn+MGlQQ=; b=bTSOqqsQ2HHrByhLe3XW6/N9tUy78mNi721Tua3nlxubxY0HcdVhVyAAHIpg/s9I67 Rh9WJCY4ptq2Pw+3BRtoEaJkihnyN0dptEd/dZ0Oy0GtzV26pt0hUO8RjAcKwL7pCk5p OW6RubjN2CR9aiu21P2v+3WyXv/5zO0nmoC3U6T7KIjGp9dz6LclHIdg0Q6m+8TknzEb EB3oBgWh3cAdJa2gyPjB1OqXmmpO58Ovzv117RH6ii3H13tBYl5DccZd+cTE7ZSOgTDj 0/FT0+Ban0EQFlzDkvD8hjpQ8HIGkGFM7Y07ERpj0JTfcs5RJqKEnRDI7mh1yvQ8jB0h 4zVA== X-Gm-Message-State: AOAM532TrifGaMmq2es64XY0XrWTt/IatVOg3Ru42SQ7FwA6+u1Rog4f eR1MT+wadD/MB8MOO5O861Ph6IcG X-Google-Smtp-Source: ABdhPJyfalBY6xuYwLp0myvWtGzvIc2Han1BgetJDOYK6K3p7slHWsx8d6RymXcamnMwD8W+NMM4fA== X-Received: by 2002:a92:3cd0:: with SMTP id j77mr19117788ilf.112.1589832185727; Mon, 18 May 2020 13:03:05 -0700 (PDT) Received: from [127.0.1.1] ([184.63.162.180]) by smtp.gmail.com with ESMTPSA id o17sm5129335ilo.75.2020.05.18.13.02.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 May 2020 13:03:05 -0700 (PDT) Subject: [bpf-next PATCH 2/4] bpf: selftests, verifier case for non null pointer check branch taken From: John Fastabend To: ast@kernel.org, daniel@iogearbox.net Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, john.fastabend@gmail.com Date: Mon, 18 May 2020 13:02:52 -0700 Message-ID: <158983217236.6512.3045049444791726995.stgit@john-Precision-5820-Tower> In-Reply-To: <158983199930.6512.18408887419883363781.stgit@john-Precision-5820-Tower> References: <158983199930.6512.18408887419883363781.stgit@john-Precision-5820-Tower> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When we have pointer type that is known to be non-null we only follow the non-null branch. This adds tests to cover this case for reference tracking. Signed-off-by: John Fastabend --- .../testing/selftests/bpf/verifier/ref_tracking.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/testing/selftests/bpf/verifier/ref_tracking.c b/tools/testing/selftests/bpf/verifier/ref_tracking.c index 604b461..d8f7c04 100644 --- a/tools/testing/selftests/bpf/verifier/ref_tracking.c +++ b/tools/testing/selftests/bpf/verifier/ref_tracking.c @@ -821,3 +821,19 @@ .result = REJECT, .errstr = "invalid mem access", }, +{ + "reference tracking: branch tracking valid pointer null comparison", + .insns = { + BPF_SK_LOOKUP(sk_lookup_tcp), + BPF_MOV64_REG(BPF_REG_6, BPF_REG_0), + BPF_MOV64_IMM(BPF_REG_3, 1), + BPF_JMP_IMM(BPF_JNE, BPF_REG_6, 0, 1), + BPF_MOV64_IMM(BPF_REG_3, 0), + BPF_JMP_IMM(BPF_JEQ, BPF_REG_6, 0, 2), + BPF_MOV64_REG(BPF_REG_1, BPF_REG_6), + BPF_EMIT_CALL(BPF_FUNC_sk_release), + BPF_EXIT_INSN(), + }, + .prog_type = BPF_PROG_TYPE_SCHED_CLS, + .result = ACCEPT, +}, From patchwork Mon May 18 20:03:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Fastabend X-Patchwork-Id: 219058 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=-6.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS 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 9790CC433E0 for ; Mon, 18 May 2020 20:03:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B675206D4 for ; Mon, 18 May 2020 20:03:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="T5Z6dfdd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726948AbgERUDp (ORCPT ); Mon, 18 May 2020 16:03:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726250AbgERUDp (ORCPT ); Mon, 18 May 2020 16:03:45 -0400 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4E33C061A0C; Mon, 18 May 2020 13:03:43 -0700 (PDT) Received: by mail-io1-xd43.google.com with SMTP id t15so5210543ios.4; Mon, 18 May 2020 13:03:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=N3rvqAX4uqzP8ZJYpHlcH0UIASMnlqmntD/M6QqshOc=; b=T5Z6dfddQv472Evjqb9BiRBnao7msU9//6vRnR/mkUtb7aIozt7nejWabjiPxy9Xnf db+7ZY59oU6fUuq5k7ICun9KrGI5f1S7u+d04VltIzZ2ZCliIFbzmJCFR+BmS/XqNWpB 9puUETlWIHJRfwM1X0QkBLH5js41XE6wWFiOvtx8cQJ/9bnloAFaZTrJ7tTn4OFLYN4K G+v4iGOnrOfFgmG22K7Fin9DINmua5XBlzpycbze+Y0Mm68OShjPfMdEVksSXXzlEPp8 pq3zUUPO0Meb4aMsGFxX0EXlKCQLMzuVJUJ3rUlrbbC1h+jeQTExfefuxYG2iauGi3Vo ISzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=N3rvqAX4uqzP8ZJYpHlcH0UIASMnlqmntD/M6QqshOc=; b=m8yV13TO3kqJXbEUaTQtamRIF6ZqTXY8q9ObmFm22QB/Mp4kTlh/dDM23ZhMk+lNPE rqN/V7uUnLn0DvzV5R6PC2QfC+2yaR9N+uCd6MRgVogAeGPJAYpTo9i91SgG7X59bxVz dDaB6Z0/mXfvvRGWOp+KwBLg+hISPyofIh7VgsEC27GGYvcQ9rBrXF5abvMrBFTAHNBk /bqYk2/Yq1gxjSVBxYkQbwhYLDItjrtJE7W+aa1KlqSTTKMAJe+SlSbIEDMyToyI6zOa pvEM5D0sLi/JULm9GfqTDhrNKNgSKjWDhBl58kC7Nc2WmhyRxMUT/1txNrmGmOIYf2bY +AxA== X-Gm-Message-State: AOAM531d5P9HnSOcUmudtPvlroq4/RPFStUSpCFziSqizeEXz4NIaj5I E+LqBYX7mpQnB2rYfxQlDuRYcE0X X-Google-Smtp-Source: ABdhPJzJ5tfoIJtDb/MHQ/a/ffjHIXXs6JRT/RFfBYrFNmcPgy7rbNA6zh34Y64h0fYZVqiqrolDPQ== X-Received: by 2002:a6b:6508:: with SMTP id z8mr15995597iob.130.1589832222983; Mon, 18 May 2020 13:03:42 -0700 (PDT) Received: from [127.0.1.1] ([184.63.162.180]) by smtp.gmail.com with ESMTPSA id c13sm5215475ilu.81.2020.05.18.13.03.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 May 2020 13:03:42 -0700 (PDT) Subject: [bpf-next PATCH 4/4] bpf: selftests, add printk to test_sk_lookup_kern to encode null ptr check From: John Fastabend To: ast@kernel.org, daniel@iogearbox.net Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, john.fastabend@gmail.com Date: Mon, 18 May 2020 13:03:30 -0700 Message-ID: <158983221039.6512.6745842570405722925.stgit@john-Precision-5820-Tower> In-Reply-To: <158983199930.6512.18408887419883363781.stgit@john-Precision-5820-Tower> References: <158983199930.6512.18408887419883363781.stgit@john-Precision-5820-Tower> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Adding a printk to test_sk_lookup_kern created the reported failure where a pointer type is checked twice for NULL. Lets add it to the progs test test_sk_lookup_kern.c so we test the case from C all the way into the verifier. We already have printk's in selftests so seems OK to add another one. Signed-off-by: John Fastabend --- .../selftests/bpf/progs/test_sk_lookup_kern.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/bpf/progs/test_sk_lookup_kern.c b/tools/testing/selftests/bpf/progs/test_sk_lookup_kern.c index d2b38fa..e83d0b4 100644 --- a/tools/testing/selftests/bpf/progs/test_sk_lookup_kern.c +++ b/tools/testing/selftests/bpf/progs/test_sk_lookup_kern.c @@ -73,6 +73,7 @@ int bpf_sk_lookup_test0(struct __sk_buff *skb) tuple_len = ipv4 ? sizeof(tuple->ipv4) : sizeof(tuple->ipv6); sk = bpf_sk_lookup_tcp(skb, tuple, tuple_len, BPF_F_CURRENT_NETNS, 0); + bpf_printk("sk=%d\n", sk ? 1 : 0); if (sk) bpf_sk_release(sk); return sk ? TC_ACT_OK : TC_ACT_UNSPEC;