From patchwork Sun Dec 17 13:17:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 13495856 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-il1-f196.google.com (mail-il1-f196.google.com [209.85.166.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2853F4438A; Sun, 17 Dec 2023 13:18:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AfeBzLBP" Received: by mail-il1-f196.google.com with SMTP id e9e14a558f8ab-35f96476fb3so10853075ab.0; Sun, 17 Dec 2023 05:18:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702819115; x=1703423915; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vIG7gX50kKtmhzIyeXshzVLZolIi3kTx5IiKTBxlLu0=; b=AfeBzLBP3Ji4QAVi7lLUbh9DM76OXM6lmJCPMv/nq/ui33zvH/NHOAYYkUOU2adLMm 5TtmtbZxIZmT3eCCzTEeX0QrLXZTngNvghJKdx9A3IOmePv9m8Tnm7Ogm9XcEcEtShDY lgjETwE497tF72SXO1S6Upyl8G4att9TP1ryfAj9/N+mFw49+wx9FuvzG7JYd2ZgekkW XhIh407i6PHBjZS9UFercvjiBuZVdw3OLQnbS3uS8w53pOUrrA00Pfs3kJw4jlddMRMo T73g8wHb2TdKJLcZPWNAf2J9CBis307DalPQ3iqKDbyhA23R0rVIi3OOA4W00xQ1JPVF wizA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702819115; x=1703423915; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vIG7gX50kKtmhzIyeXshzVLZolIi3kTx5IiKTBxlLu0=; b=Apj/4407NcEw7wXwuOv3pG/98AzDKtiLFWdZ5PiJPiiw47wI6o5488E1Bc91HCHgwT c6l9ZT8r8qNHiBNQKj9st0YjfsHeKSLrPRT4rgLjyXc8yzZ3+1semDPmg4y2S3J7/8Ia UH9poOJd27/e5kBdGpvFWpf3eiTgAnvkqijOIUJQ65TYAF4Za4cJLu33UWo+uhV7D4QT +Isf74+vqbTBmBSteLxV/kgDiktSQbCGpGiSyNEWNV18fZO5rPHiXv3Oum//E0gQ+7+t YdOvqnJDbjNHZe3RPsJDHcwdIBRJzyl1WkumL922XX866ZuEkCg1P4Zj1GHFa8vsPLal k03g== X-Gm-Message-State: AOJu0YwViGd36lOCWnSiB/Y0iolbFFxi7EBLJ4wBuzreZ2h3xaclS7HC zurKVkalfQzLY2u5fxncSLo= X-Google-Smtp-Source: AGHT+IFuYVYqCJXnlGSY0RyODewiiUKWPVJpKtwtNSLuGT8b2gpJNCbkzwTNT0Y1LI2TQsPuyAjZBA== X-Received: by 2002:a05:6e02:1a64:b0:35d:87d4:938c with SMTP id w4-20020a056e021a6400b0035d87d4938cmr23751297ilv.15.1702819115079; Sun, 17 Dec 2023 05:18:35 -0800 (PST) Received: from localhost.localdomain ([43.129.244.20]) by smtp.gmail.com with ESMTPSA id h10-20020a170902f7ca00b001d395d3df30sm1099425plw.130.2023.12.17.05.18.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Dec 2023 05:18:34 -0800 (PST) From: Menglong Dong To: andrii@kernel.org, eddyz87@gmail.com, yonghong.song@linux.dev, alexei.starovoitov@gmail.com Cc: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, martin.lau@linux.dev, song@kernel.org, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Menglong Dong , Shung-Hsi Yu Subject: [PATCH bpf-next v4 1/3] bpf: make the verifier tracks the "not equal" for regs Date: Sun, 17 Dec 2023 21:17:14 +0800 Message-Id: <20231217131716.830290-2-menglong8.dong@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231217131716.830290-1-menglong8.dong@gmail.com> References: <20231217131716.830290-1-menglong8.dong@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net We can derive some new information for BPF_JNE in regs_refine_cond_op(). Take following code for example: /* The type of "a" is u32 */ if (a > 0 && a < 100) { /* the range of the register for a is [0, 99], not [1, 99], * and will cause the following error: * * invalid zero-sized read * * as a can be 0. */ bpf_skb_store_bytes(skb, xx, xx, a, 0); } In the code above, "a > 0" will be compiled to "jmp xxx if a == 0". In the TRUE branch, the dst_reg will be marked as known to 0. However, in the fallthrough(FALSE) branch, the dst_reg will not be handled, which makes the [min, max] for a is [0, 99], not [1, 99]. For BPF_JNE, we can reduce the range of the dst reg if the src reg is a const and is exactly the edge of the dst reg. Signed-off-by: Menglong Dong Acked-by: Andrii Nakryiko Acked-by: Shung-Hsi Yu --- v2: - fix a typo in the subject - add some comments, as Eduard advised --- kernel/bpf/verifier.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 1863826a4ac3..29c41d66ea6f 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -14343,7 +14343,43 @@ static void regs_refine_cond_op(struct bpf_reg_state *reg1, struct bpf_reg_state } break; case BPF_JNE: - /* we don't derive any new information for inequality yet */ + if (!is_reg_const(reg2, is_jmp32)) + swap(reg1, reg2); + if (!is_reg_const(reg2, is_jmp32)) + break; + + /* try to recompute the bound of reg1 if reg2 is a const and + * is exactly the edge of reg1. + */ + val = reg_const_value(reg2, is_jmp32); + if (is_jmp32) { + /* u32_min_value is not equal to 0xffffffff at this point, + * because otherwise u32_max_value is 0xffffffff as well, + * in such a case both reg1 and reg2 would be constants, + * jump would be predicted and reg_set_min_max() won't + * be called. + * + * Same reasoning works for all {u,s}{min,max}{32,64} cases + * below. + */ + if (reg1->u32_min_value == (u32)val) + reg1->u32_min_value++; + if (reg1->u32_max_value == (u32)val) + reg1->u32_max_value--; + if (reg1->s32_min_value == (s32)val) + reg1->s32_min_value++; + if (reg1->s32_max_value == (s32)val) + reg1->s32_max_value--; + } else { + if (reg1->umin_value == (u64)val) + reg1->umin_value++; + if (reg1->umax_value == (u64)val) + reg1->umax_value--; + if (reg1->smin_value == (s64)val) + reg1->smin_value++; + if (reg1->smax_value == (s64)val) + reg1->smax_value--; + } break; case BPF_JSET: if (!is_reg_const(reg2, is_jmp32)) From patchwork Sun Dec 17 13:17:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 13495857 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E11DB446D3; Sun, 17 Dec 2023 13:18:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RzKLY7MN" Received: by mail-pf1-f193.google.com with SMTP id d2e1a72fcca58-6d3165ac96bso226580b3a.0; Sun, 17 Dec 2023 05:18:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702819119; x=1703423919; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/5PxWUcu/ifiy+mTxB+eS5k2/O2oeySj89/JuoUzQzw=; b=RzKLY7MNyryEyzhFh/RudabzSklYQPMtFF3J1EMz3YQgnADBRtufbCETHLfhHrv1FW /38nQsqt9I3k1ul9seIQtBVJH0LXt5gyywKTRgrPv4fzrnDKfw5iBt8ZWyimeCNpiRFj NwuCHrk2jnOXz2tquCqOwK2fU36R+hHOJG45UvEQPW6Q6a/tpnXgRzJsU3ASIPKs7VPi SlK1876oVUJlwt5Q/W+x707FZ4YET0BpZa+5YZxY6zccpX8FkQicJkcFkl0Y2ddbmoEB yuxws+3eXq/NoxFr4aaIYZk1NRbi8kXdDZm/F7dcqPiYdCemI0ffFdcsFCpYZ7aO67AY W9Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702819119; x=1703423919; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/5PxWUcu/ifiy+mTxB+eS5k2/O2oeySj89/JuoUzQzw=; b=t7Orx+RSEFW4M2FOXNNVUqcEACVW3ealtviMH6KbFXJ6fsRXfLdWaY5sSjKhsNCxfi z93ckoWIbUrv4KUR2UWjUHBAXYnGn/2Y9VI4E01PYmmFrJhSqLetaaQYkr7u9C//CmDT 5wtkzlpk/b9sAW3rBrAiCssxQVZb+YAhx3IHz4P0hu+GswuxGffCuLd1zL6Ej+mOUb6N To8gOEZ9CkU9ixYlQZ2ho/V7u+sAejgvjR4mETA0foqhlLj5eXqffVywqi6bC1TO8Y19 1wppkszcFqDTTuke7gcyDZ8Eg7dJoCW5gqVgwNUaDv0NDEQwxpKZoA7PzpJztZW+H5sT DSfA== X-Gm-Message-State: AOJu0Yw+plCUc5xijHbqwk+Nty3Q7Bt8D1INbvv9jNnsZ5kf4X4kYeHd 6AkFrYi2h3NUaT+QWCz0U+Q= X-Google-Smtp-Source: AGHT+IGPY16Yge/9iDfCYyCspVfPdW7X7tOPmmEr3ZXjdFPg0jTlouyPA+7+iesblpEZ3NVWZ5Jolg== X-Received: by 2002:a05:6a20:7d93:b0:18f:97c:8244 with SMTP id v19-20020a056a207d9300b0018f097c8244mr9127608pzj.78.1702819119160; Sun, 17 Dec 2023 05:18:39 -0800 (PST) Received: from localhost.localdomain ([43.129.244.20]) by smtp.gmail.com with ESMTPSA id h10-20020a170902f7ca00b001d395d3df30sm1099425plw.130.2023.12.17.05.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Dec 2023 05:18:38 -0800 (PST) From: Menglong Dong To: andrii@kernel.org, eddyz87@gmail.com, yonghong.song@linux.dev, alexei.starovoitov@gmail.com Cc: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, martin.lau@linux.dev, song@kernel.org, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Menglong Dong Subject: [PATCH bpf-next v4 2/3] selftests/bpf: activate the OP_NE login in range_cond() Date: Sun, 17 Dec 2023 21:17:15 +0800 Message-Id: <20231217131716.830290-3-menglong8.dong@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231217131716.830290-1-menglong8.dong@gmail.com> References: <20231217131716.830290-1-menglong8.dong@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net The edge range checking for the registers is supported by the verifier now, so we can activate the extended login in tools/testing/selftests/bpf/prog_tests/reg_bounds.c/range_cond() to test such logic. Besides, I added some cases to the "crafted_cases" array for this logic. These cases are mainly used to test the edge of the src reg and dst reg. All reg bounds testings has passed in the SLOW_TESTS mode: $ export SLOW_TESTS=1 && ./test_progs -t reg_bounds -j Summary: 65/18959832 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Menglong Dong --- v3: - do some adjustment to the crafted cases that we added v2: - add some cases to the "crafted_cases" --- .../selftests/bpf/prog_tests/reg_bounds.c | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/reg_bounds.c b/tools/testing/selftests/bpf/prog_tests/reg_bounds.c index 0c9abd279e18..c9dc9fe73211 100644 --- a/tools/testing/selftests/bpf/prog_tests/reg_bounds.c +++ b/tools/testing/selftests/bpf/prog_tests/reg_bounds.c @@ -590,12 +590,7 @@ static void range_cond(enum num_t t, struct range x, struct range y, *newy = range(t, max_t(t, x.a, y.a), min_t(t, x.b, y.b)); break; case OP_NE: - /* generic case, can't derive more information */ - *newx = range(t, x.a, x.b); - *newy = range(t, y.a, y.b); - break; - - /* below extended logic is not supported by verifier just yet */ + /* below logic is supported by the verifier now */ if (x.a == x.b && x.a == y.a) { /* X is a constant matching left side of Y */ *newx = range(t, x.a, x.b); @@ -2101,6 +2096,19 @@ static struct subtest_case crafted_cases[] = { {S32, S64, {(u32)(s32)S32_MIN, (u32)(s32)-255}, {(u32)(s32)-2, 0}}, {S32, S64, {0, 1}, {(u32)(s32)S32_MIN, (u32)(s32)S32_MIN}}, {S32, U32, {(u32)(s32)S32_MIN, (u32)(s32)S32_MIN}, {(u32)(s32)S32_MIN, (u32)(s32)S32_MIN}}, + + /* edge overlap testings for BPF_NE, skipped some cases that already + * exist above. + */ + {U64, U64, {0, U64_MAX}, {U64_MAX, U64_MAX}}, + {U64, U64, {0, U64_MAX}, {0, 0}}, + {S64, U64, {S64_MIN, 0}, {S64_MIN, S64_MIN}}, + {S64, U64, {S64_MIN, 0}, {0, 0}}, + {S64, U64, {S64_MIN, S64_MAX}, {S64_MAX, S64_MAX}}, + {U32, U32, {0, U32_MAX}, {0, 0}}, + {S32, U32, {(u32)(s32)S32_MIN, 0}, {0, 0}}, + {S32, U32, {(u32)(s32)S32_MIN, 0}, {(u32)(s32)S32_MIN, (u32)(s32)S32_MIN}}, + {S32, U32, {(u32)(s32)S32_MIN, S32_MAX}, {S32_MAX, S32_MAX}}, }; /* Go over crafted hard-coded cases. This is fast, so we do it as part of From patchwork Sun Dec 17 13:17:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 13495858 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 340D844C84; Sun, 17 Dec 2023 13:18:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="K9hAjbwN" Received: by mail-pl1-f195.google.com with SMTP id d9443c01a7336-1d04c097e34so14932175ad.0; Sun, 17 Dec 2023 05:18:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702819123; x=1703423923; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PexKnGDC9KL8jYd/W6R/JoiOIqAz49gn3mOLUjN8jRE=; b=K9hAjbwN0tlxoQd+GPw1ZMwCm8qU2p6EoMyz0Cmjbl/JqZvUetX0fJT/kPadUAY7WX KQeLVdIqTST6t1+dSSq8sgxVEw6ZUZ7tEFbhO+rJjLYJwdjNQ602DY4eMwbKcJ45o9hT HS4USO49UfNmEdwZ1s1Oklnnc6PbyF/GS/tmbatCsEcvs1eNNSGQIEHM40/mddSdW0SK V24aXudhzhmCnX88le8pGKqXUFF48UoP8d1HUwgresvCyF4BUtwhnHKRhJOJJ0xDAgIW Y6HH/3ua0iuUaglg2Dkd+jNAKgRTrTwjaemHkDs52QFzblMdI5d1WSstCpFQH1PtNc6+ RTIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702819123; x=1703423923; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PexKnGDC9KL8jYd/W6R/JoiOIqAz49gn3mOLUjN8jRE=; b=vCjvD0poxFEbQSq7p0260BgzJWC6Eo1718zvv/Kub0UH3n26etid6V3lVQ2UQTd3xa BNvJ8wU+ZkwrM+hphhlqt118IDGCmn2mVYteJ3M4Gseuecipp4BV4osOnrAxWgF06l0z rmW9fsh0bstyZ12X25POE2ZOboAQulxY0VpXg4W8kYoVkHyTfhLDqHmKMajl8lNI1xiR HcNIeECO72kILnj/dBTWzYugD2cB45yOM0d8ToYe14uGRfY/gtkfBSskULnI56B946rI VMUUoCFqid7geWkhHOjMx/bicZxbPyHBi83R7sHTrTnBsc2XBUmKTy30XjJ3oe5f6rbC y36Q== X-Gm-Message-State: AOJu0Yy6RtJa3gFKOiyrsRF4e1bvjYOHZP8QyLjSydDXdkKMQ9ZdDdyG pud2CqODYtxmbAm/ZOqmfqo= X-Google-Smtp-Source: AGHT+IFSKFKS7ShBmrZbgsjYihorhPt4xMO6ojj00w2oovDASLD6r75Xm3pDP8KAgJjKK0IkLGxqAQ== X-Received: by 2002:a17:903:2307:b0:1d0:6ffd:610d with SMTP id d7-20020a170903230700b001d06ffd610dmr17224306plh.47.1702819123386; Sun, 17 Dec 2023 05:18:43 -0800 (PST) Received: from localhost.localdomain ([43.129.244.20]) by smtp.gmail.com with ESMTPSA id h10-20020a170902f7ca00b001d395d3df30sm1099425plw.130.2023.12.17.05.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Dec 2023 05:18:43 -0800 (PST) From: Menglong Dong To: andrii@kernel.org, eddyz87@gmail.com, yonghong.song@linux.dev, alexei.starovoitov@gmail.com Cc: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, martin.lau@linux.dev, song@kernel.org, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Menglong Dong Subject: [PATCH bpf-next v4 3/3] selftests/bpf: add testcase to verifier_bounds.c for JMP_NE Date: Sun, 17 Dec 2023 21:17:16 +0800 Message-Id: <20231217131716.830290-4-menglong8.dong@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231217131716.830290-1-menglong8.dong@gmail.com> References: <20231217131716.830290-1-menglong8.dong@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Add testcase for the logic that the verifier tracks the BPF_JNE for regs. The assembly function "reg_not_equal()" that we add is exactly converted from the following case: u32 a = bpf_get_prandom_u32(); u64 b = 0; a %= 8; /* the "a > 0" here will be optimized to "a != 0" */ if (a > 0) { /* now the range of a should be [1, 7] */ bpf_skb_store_bytes(skb, 0, &b, a, 0); } Signed-off-by: Menglong Dong --- .../selftests/bpf/progs/verifier_bounds.c | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/verifier_bounds.c b/tools/testing/selftests/bpf/progs/verifier_bounds.c index ec430b71730b..3fe2ce2b3f21 100644 --- a/tools/testing/selftests/bpf/progs/verifier_bounds.c +++ b/tools/testing/selftests/bpf/progs/verifier_bounds.c @@ -1075,4 +1075,31 @@ l0_%=: r0 = 0; \ : __clobber_all); } +SEC("tc") +__description("bounds check with JMP_NE for reg edge") +__success __retval(0) +__naked void reg_not_equal(void) +{ + asm volatile (" \ + r6 = r1; \ + r1 = 0; \ + *(u64*)(r10 - 8) = r1; \ + call %[bpf_get_prandom_u32]; \ + r4 = r0; \ + r4 &= 7; \ + if r4 == 0 goto l0_%=; \ + r1 = r6; \ + r2 = 0; \ + r3 = r10; \ + r3 += -8; \ + r5 = 0; \ + call %[bpf_skb_store_bytes]; \ +l0_%=: r0 = 0; \ + exit; \ +" : + : __imm(bpf_get_prandom_u32), + __imm(bpf_skb_store_bytes) + : __clobber_all); +} + char _license[] SEC("license") = "GPL";