From patchwork Mon Oct 14 10:55:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitar Kanaliev X-Patchwork-Id: 13834647 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 1AE7E19F132 for ; Mon, 14 Oct 2024 10:56:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728903364; cv=none; b=bO040N2NUc+vm07nyd2JTs3ml9zxFgHr119c/R88gQL+lwnthJkFV2GdhDVlmJNZJukFYKi/l53kDb8qXk9KUOv+R9+Qd6i8GRUd10BVZIsUsW/1L8/3CAw8skWzZZb/U4DGbgcGkxce1GPi4QeES25T/MnvREkj0n2u6LGVBqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728903364; c=relaxed/simple; bh=oMcjEnoD/IiHKTDHBe1+Sngt6VXkq2qz6K7GU6/jcy8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=I5MW4NEfV/5OWxElQ82e2BcH0n+nF/zBiRmPR3+pdvsZa+cJM15+ZPth52NTAxJ3bntrclZeQDm05vbLG2x1Yyku/nEam7H+iN5e3La9IzqrgzKzo6vra36MjcspRNNoPnovteQfRgZw7y42t5ckLFv3EkYcU4w9zNP3oU834qE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=siteground.com; spf=pass smtp.mailfrom=siteground.com; dkim=pass (1024-bit key) header.d=siteground.com header.i=@siteground.com header.b=s9b5dgMK; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=siteground.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=siteground.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=siteground.com header.i=@siteground.com header.b="s9b5dgMK" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a9a0c40849cso131464666b.3 for ; Mon, 14 Oct 2024 03:56:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=siteground.com; s=google; t=1728903360; x=1729508160; 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=/Tt8tpwQc0EVnwrif57LGDNgk40jiF/k60qMYgD9Xjs=; b=s9b5dgMKipeQVE0tt8v8JKywOlaDri04059fW7a8IhpkSAhewrk3fdADhrJzWFZIQX znwveePcUj3zgt9OhB67KQSprruY+9Xux9e1NheFRXYeqczEm/B9DoDnnYYdOixv0QsN gmIvx0s4PHGVWnj4/e/IvSKe613oq7FhISelE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728903360; x=1729508160; 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=/Tt8tpwQc0EVnwrif57LGDNgk40jiF/k60qMYgD9Xjs=; b=WjQ755occtKnnoKHvID/Nkm6Kxgam7uNHr5YbD0E2FjPqugVtW+csSeeLJLKcetDS8 JYZKXUX+SHufYtXPhB2NE2h0Jp0W+Iy9oIRHJJg1Joy72SMI5Pu12DhP2OK6DzV/y5FL F3uUUND+Og/KoGIO7M/dtIOldWdOQ9U4ZKIgW+hRpBStKXx2yJ+gyjwimMuMYIX1UWyW 8E8OnKM8VS2YZtFN0BEVxEs5kaBjaM88cizhF0P39E0jZugg7PBtFlKB1+gEqYZEnLtM 2ibLVPNrQkvzdv6MmXRe4+X8OWPWLb/Q8M3n7ujKa05IcqwQ4Hj2is7fQ2mFXuiZDt0/ 8xrQ== X-Forwarded-Encrypted: i=1; AJvYcCXDeYxjicmLowCettKV/41Nc8xHo9PulK63ov5NJeopw21BLu8nH2ngbrQ+cURYE+daLKc=@vger.kernel.org X-Gm-Message-State: AOJu0YzLmIQxVZIpAh9zPrCRlJozrR21CIbJq1d4dvXaDjTtaPIXquD8 ofCtNKwGKEzlgVT6FmzRdDXBfChATbcIdnjbNPGvG0D/cmYO8PawxERg9ofPNlg= X-Google-Smtp-Source: AGHT+IHuDrKfDX9RSVqqFq2zvjQKU+rNI1hRsNTehOuiMcfPn6ZDdJ/3Dun/IVckndlV5fBe9mA2ew== X-Received: by 2002:a17:906:7312:b0:a9a:139:5ef3 with SMTP id a640c23a62f3a-a9a01396165mr444122166b.55.1728903360394; Mon, 14 Oct 2024 03:56:00 -0700 (PDT) Received: from Dimitar_Kanaliev.sgnet.lan ([82.118.240.146]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a0c95c80asm159996866b.144.2024.10.14.03.55.59 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 14 Oct 2024 03:56:00 -0700 (PDT) From: Dimitar Kanaliev To: Yonghong Song , bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Dimitar Kanaliev , Shung-Hsi Yu Subject: [PATCH 1/3] bpf: Fix truncation bug in coerce_reg_to_size_sx() Date: Mon, 14 Oct 2024 13:55:39 +0300 Message-Id: <20241014105541.91184-2-dimitar.kanaliev@siteground.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20241014105541.91184-1-dimitar.kanaliev@siteground.com> References: <20241014105541.91184-1-dimitar.kanaliev@siteground.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 coerce_reg_to_size_sx() updates the register state after a sign-extension operation. However, there's a bug in the assignment order of the unsigned min/max values, leading to incorrect truncation: 0: (85) call bpf_get_prandom_u32#7 ; R0_w=scalar() 1: (57) r0 &= 1 ; R0_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=1,var_off=(0x0; 0x1)) 2: (07) r0 += 254 ; R0_w=scalar(smin=umin=smin32=umin32=254,smax=umax=smax32=umax32=255,var_off=(0xfe; 0x1)) 3: (bf) r0 = (s8)r0 ; R0_w=scalar(smin=smin32=-2,smax=smax32=-1,umin=umin32=0xfffffffe,umax=0xffffffff,var_off=(0xfffffffffffffffe; 0x1)) In the current implementation, the unsigned 32-bit min/max values (u32_min_value and u32_max_value) are assigned directly from the 64-bit signed min/max values (s64_min and s64_max): reg->umin_value = reg->u32_min_value = s64_min; reg->umax_value = reg->u32_max_value = s64_max; Due to the chain assigmnent, this is equivalent to: reg->u32_min_value = s64_min; // Unintended truncation reg->umin_value = reg->u32_min_value; reg->u32_max_value = s64_max; // Unintended truncation reg->umax_value = reg->u32_max_value; Fixes: 1f9a1ea821ff ("bpf: Support new sign-extension load insns") Reported-by: Shung-Hsi Yu , Zac Ecob Signed-off-by: Dimitar Kanaliev --- kernel/bpf/verifier.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 7d9b38ffd220..70a0cf0f1569 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -6333,10 +6333,10 @@ static void coerce_reg_to_size_sx(struct bpf_reg_state *reg, int size) /* both of s64_max/s64_min positive or negative */ if ((s64_max >= 0) == (s64_min >= 0)) { - reg->smin_value = reg->s32_min_value = s64_min; - reg->smax_value = reg->s32_max_value = s64_max; - reg->umin_value = reg->u32_min_value = s64_min; - reg->umax_value = reg->u32_max_value = s64_max; + reg->s32_min_value = reg->smin_value = s64_min; + reg->s32_max_value = reg->smax_value = s64_max; + reg->u32_min_value = reg->umin_value = s64_min; + reg->u32_max_value = reg->umax_value = s64_max; reg->var_off = tnum_range(s64_min, s64_max); return; } From patchwork Mon Oct 14 10:55:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitar Kanaliev X-Patchwork-Id: 13834648 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (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 E9CF41A4F15 for ; Mon, 14 Oct 2024 10:56:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728903366; cv=none; b=U1jQ2LR8ERCR11EDz4U9sFCM9yQNceOqPQcDxAuCk3LTpvFMLhu/5vtkPoQlit/Stco/6QOOFM6NALVz1pGQkdrgIBxyqHl7T6YiWjpmd/6FoGBCdeSPDq25pqZlfQLGSbAoo9VEAuf7pz9wTRYBDI3pWxbvNxj2LUJeydhaet0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728903366; c=relaxed/simple; bh=lVE0Ob+ihplK2ZdSoin0DUnQqzukpB6hkjsVZNfHAmc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=m32WtFBfP+SgXQPArIT8CfKF8e5AA3zLzgemoz8bAtpNRsNJ1jDJOB17aCsYyUrA0O5pbMzKcN3G3Q2XShEEVu+8iQaZC/+S4vMQ9IgKgkb4LkqU80ZwQNUCAjNi6TxjXXww3DIPLhVG7nL4SsMNIGMGcCiapVg1xSS8ScdXmRA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=siteground.com; spf=pass smtp.mailfrom=siteground.com; dkim=pass (1024-bit key) header.d=siteground.com header.i=@siteground.com header.b=juzleSGj; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=siteground.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=siteground.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=siteground.com header.i=@siteground.com header.b="juzleSGj" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a9a14cb0147so78376566b.0 for ; Mon, 14 Oct 2024 03:56:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=siteground.com; s=google; t=1728903363; x=1729508163; 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=OMLjbfjVZfKT8rnpaWVJZnN33l9IdfLPTHhbSw3d/xo=; b=juzleSGjqgj2/wsQK97yFHMms96ERAoxFgv1CcV9hziQ8brA/gXlR5pAx9T7Oei1hs 4q4kMnsOnd1rgYlBPwN14en96i2tTywwGuiqg7XJD/JU21r3a6jEgVcG0i0vRvBpO2Oe F8wDFrgcl328KuOk2kUxywdRNXXc8kJGKaaVI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728903363; x=1729508163; 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=OMLjbfjVZfKT8rnpaWVJZnN33l9IdfLPTHhbSw3d/xo=; b=Y/FnMaWY1wEez9c+Rh7p4CHWkaFBEmPMFi/xcsOSxmxq7avBx/ENwTwOtuZd8oJUs5 09/lD11B+kmHdCmWofnPtLEFS54Q+2snk978hC6V0LXEZd8RPDS5ZApIDLNU/Hby2pEO UlkGE3Sf6oyObpT/beXwTK2GaWa+sK8sZKfCUbSPYXYzvLRu1HMkgX3faP/kZy/seqQl aHVdqbTqOjmzkGgvHNm8vXilxx5Nd3zjNd6mljkanGjV+S3SBZlvjVkx8+C2X1wZAa/m xuSsSoUm6GLXoWzioTvxIEZNRM1FxDSzUEByA4IQk/Ez3yGtoIoI8tZR0KeU3t3nx+eP Kjow== X-Forwarded-Encrypted: i=1; AJvYcCXx2o9uVDUvPwnL0XE8OgvWorWRFjQ5MHDs4gS4v+CyU4swMJpwcU3DraeZczY3j10C3eU=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0SqeghiWP8vyH8ILXa8tb1jNXxzOhXHvq1cDEpTiJqTo8VmO6 q3uJhDgPiGtfiyek0jKQthkbc+0n5R0lzId+J3EyYcpyQtGPggQnkdoUv4sPmgg= X-Google-Smtp-Source: AGHT+IGIykltc+g0HpfZB3R+IdiUjtHz8zjpwIeHIr+pze/t1MPx+E/8kqgdLt1WR1NCagB8UiWt5Q== X-Received: by 2002:a17:906:fd88:b0:a99:d308:926 with SMTP id a640c23a62f3a-a99d3080adbmr856885266b.57.1728903363312; Mon, 14 Oct 2024 03:56:03 -0700 (PDT) Received: from Dimitar_Kanaliev.sgnet.lan ([82.118.240.146]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a0c95c80asm159996866b.144.2024.10.14.03.56.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 14 Oct 2024 03:56:03 -0700 (PDT) From: Dimitar Kanaliev To: Yonghong Song , bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Dimitar Kanaliev , Shung-Hsi Yu Subject: [PATCH 2/3] selftests/bpf: Add test for truncation after sign extension in coerce_reg_to_size_sx() Date: Mon, 14 Oct 2024 13:55:40 +0300 Message-Id: <20241014105541.91184-3-dimitar.kanaliev@siteground.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20241014105541.91184-1-dimitar.kanaliev@siteground.com> References: <20241014105541.91184-1-dimitar.kanaliev@siteground.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 test that checks whether unsigned ranges deduced by the verifier for sign extension instruction is correct. Without previous patch that fixes truncation in coerce_reg_to_size_sx() this test fails. Acked-by: Shung-Hsi Yu Signed-off-by: Dimitar Kanaliev --- .../selftests/bpf/progs/verifier_movsx.c | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/verifier_movsx.c b/tools/testing/selftests/bpf/progs/verifier_movsx.c index 028ec855587b..8e37d44d87e5 100644 --- a/tools/testing/selftests/bpf/progs/verifier_movsx.c +++ b/tools/testing/selftests/bpf/progs/verifier_movsx.c @@ -289,6 +289,26 @@ l0_%=: \ #else +SEC("socket") +__description("MOV64SX, S8, unsigned range_check") +__success __retval(0) +__naked void mov64sx_s8_range_check(void) +{ + asm volatile (" \ + call %[bpf_get_prandom_u32]; \ + r0 &= 0x1; \ + r0 += 0xfe; \ + r0 = (s8)r0; \ + if r0 < 0xfffffffffffffffe goto label_%=; \ + r0 = 0; \ + exit; \ +label_%=: \ + exit; \ +" : + : __imm(bpf_get_prandom_u32) + : __clobber_all); +} + SEC("socket") __description("cpuv4 is not supported by compiler or jit, use a dummy test") __success From patchwork Mon Oct 14 10:55:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitar Kanaliev X-Patchwork-Id: 13834649 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 E0B7B19F421 for ; Mon, 14 Oct 2024 10:56:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728903369; cv=none; b=KH276i4C6usH+guJupjWzfLr2t/gvD9aep3Er22lXwAyMsVKjAHC0dbF9j2IDMBqKRARye4i87Iz+tjJSG8VFsRa2kjJQ1u5iyMYoKsOjR3Ify//sVTBC6KaFXu+o6A/wiOLMhGAU/EwwnwP1N5qUGoSJtBIIVkJLDsHvyfj1n4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728903369; c=relaxed/simple; bh=h231vU2qaRTflxnYe/7yTVGhzXmAnqYnLWuVre2AGsk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WQ1Yl9Qkbs6vL45xaTdq3Dt6qrZPk/cJOJUD9afd6kI3Vl91jDFWauklS9MvNyvox9+SK8Gjwi4O0f3tA+GMLFTMEIkeDDFme6LWK8mSAdjph+/xoDOdYb9jtACU6NTbPvmQNsQhbfw1G/R47S3cSo1Ej1aRFjBuNb7lOHgzyII= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=siteground.com; spf=pass smtp.mailfrom=siteground.com; dkim=pass (1024-bit key) header.d=siteground.com header.i=@siteground.com header.b=GuhigUyp; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=siteground.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=siteground.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=siteground.com header.i=@siteground.com header.b="GuhigUyp" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a99ebb390a5so312566966b.1 for ; Mon, 14 Oct 2024 03:56:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=siteground.com; s=google; t=1728903366; x=1729508166; 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=03WgxT/9z6+jdMXK8yb43ceEYV6UMIJmFsUhqeDnZ/Q=; b=GuhigUypzfeZ8oNbb7alCh6OEEkEHOlOyo/CIYRjSkQUcMA9yqXcVTUEScJcDD9Odi MXb1n1+FBJdiuXKix2xlerNMBaxJS3aUED9l7RZ/oZqz3/bUgH1uk65PAvFU7zo2+Ux3 HkVgQGyGQklTUCATRVNnhkxS9ZrDKdDLd3/7I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728903366; x=1729508166; 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=03WgxT/9z6+jdMXK8yb43ceEYV6UMIJmFsUhqeDnZ/Q=; b=ZwHvxTpAxmgKFsJr+3RW2ZxSVRRjojQQff2X3mBXm1GM4jxOoJbNWdUmoyilC4rJVz GzicvGfvcwAMHgvqmNnduEaQ4Mfo6/hSFrbTW0BfgrlxTVzGl66KlK8SnQC+/aluwEj5 B/iT4wRa0E02T6i+prBT9Yk5QBRFnuLWyF99nqpqYdJkADFwbBZny9DJ5Vqnke4WzxGj D7yqTP5GD8t93Uufrb0VGQrzUFR0kJ3xHMoEteJ1seOojYfJZOOUY57KOmaX/03KUNNp UHNfH8cRQPOsvEHSKvQ1Ur+GG8VR8jaGUWAizkAvk2UmjncfS1cV3Xpvbmk3XY3JqjBr Q/bQ== X-Forwarded-Encrypted: i=1; AJvYcCXuTyzsAFF+bQLCZrGncZjcnqDJ+InQAqqjmKba0smBWTnMGHiYvSxa8L4Ri1Egq+6XSkQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yz2LOEc658keE3exftfjl9sOIxr30bUsERcKF9V78m6hTIgW2hG 0A33PWuMKD3YeXz/a8hwP9A5xHoHDuwuemShL9EkUavDgNfRxMvivnIJ0ZLmrGE= X-Google-Smtp-Source: AGHT+IFzwUYwxbGyE8JafAQVzjK8ebLG9egOa2Z9u1AHC6pwkUjLa92rmRhMkkrbaYynBbqU1niaDw== X-Received: by 2002:a17:907:6eab:b0:a9a:1575:23e3 with SMTP id a640c23a62f3a-a9a157525e0mr155020666b.19.1728903366203; Mon, 14 Oct 2024 03:56:06 -0700 (PDT) Received: from Dimitar_Kanaliev.sgnet.lan ([82.118.240.146]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a0c95c80asm159996866b.144.2024.10.14.03.56.05 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 14 Oct 2024 03:56:05 -0700 (PDT) From: Dimitar Kanaliev To: Yonghong Song , bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Dimitar Kanaliev , Shung-Hsi Yu Subject: [PATCH 3/3] selftests/bpf: Add test for sign extension in coerce_subreg_to_size_sx() Date: Mon, 14 Oct 2024 13:55:41 +0300 Message-Id: <20241014105541.91184-4-dimitar.kanaliev@siteground.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20241014105541.91184-1-dimitar.kanaliev@siteground.com> References: <20241014105541.91184-1-dimitar.kanaliev@siteground.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 a test for unsigned ranges after signed extension instruction. This case isn't currently covered by existing tests in verifier_movsx.c. Acked-by: Shung-Hsi Yu Signed-off-by: Dimitar Kanaliev --- .../selftests/bpf/progs/verifier_movsx.c | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/verifier_movsx.c b/tools/testing/selftests/bpf/progs/verifier_movsx.c index 8e37d44d87e5..2124d24e8bf9 100644 --- a/tools/testing/selftests/bpf/progs/verifier_movsx.c +++ b/tools/testing/selftests/bpf/progs/verifier_movsx.c @@ -309,6 +309,26 @@ label_%=: \ : __clobber_all); } +SEC("socket") +__description("MOV32SX, S8, unsigned range_check") +__success __retval(0) +__naked void mov32sx_s8_range_check(void) +{ + asm volatile (" \ + call %[bpf_get_prandom_u32]; \ + w0 &= 0x1; \ + w0 += 0xfe; \ + w0 = (s8)w0; \ + if w0 < 0xfffffffe goto label_%=; \ + r0 = 0; \ + exit; \ +label_%=: \ + exit; \ + " : + : __imm(bpf_get_prandom_u32) + : __clobber_all); +} + SEC("socket") __description("cpuv4 is not supported by compiler or jit, use a dummy test") __success