Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45CC221ADAE for ; Wed, 26 Feb 2025 02:24:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740536693; cv=none; b=q4w9S+u5Rl10zHJDiPnLnViki1B9GFARa3Gqh11FJxlG9LgBSQm5nLqFNBULvh2YnGRbP0cGBK+Pv/y86A05o8K7XEliDR3BrV8uoeZ7CUCRlcTXtUa03XRRlhGQMUDmszbA7LkxQr4d1aHw5dHjoPYK3KGNfw6MLSdoZ/FEhXA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740536693; c=relaxed/simple; bh=GBJ/aK+rFxcb0ec8HJhDntFHam3Ba723tzknlZDFt5s=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=liyLtpaihOt4TER0agOugatGK5ihovLzF49DvGkYAABqLBJ3hiK9uHzkBfx8V9mWdMYrcvC3NCfLFyUqUy/4yEnpPIm+pH/MBFFqDXpLy/W9CkNRuco1mBhragZsJuIkaRlmQt/5h3XJ5roaNj3YRU1p1Hqob86tHskOlsd3U54= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=mVhvYaqd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="mVhvYaqd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B39CC4CEDD; Wed, 26 Feb 2025 02:24:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1740536693; bh=GBJ/aK+rFxcb0ec8HJhDntFHam3Ba723tzknlZDFt5s=; h=From:To:Cc:Subject:Date:Reply-to:From; b=mVhvYaqdEZPKiRc+HPc1aDcriCezuMSETi1Ood2qA3GdyRNj9AZNbVmp8BiFpe9eQ 9VX5gVLDQVbItdli70ffGltvxVDQprzxdIEgimzT1nUc2fDWF5t/lNZVt8/I+v3zK1 3i7dG+ehXb4DOkO20yj9CUrnwsEdAPWFHJ+OjIic= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2022-49658: bpf: Fix insufficient bounds propagation from adjust_scalar_min_max_vals Date: Wed, 26 Feb 2025 03:23:41 +0100 Message-ID: <2025022621-CVE-2022-49658-37f3@gregkh> X-Mailer: git-send-email 2.48.1 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=6278; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=GBJ/aK+rFxcb0ec8HJhDntFHam3Ba723tzknlZDFt5s=; b=owGbwMvMwCRo6H6F97bub03G02pJDOn7qu6+iG74JTyX9bDI/iU5e7l41wiLXf9rotWSfZkv/ E8Ga2lhRywLgyATg6yYIsuXbTxH91ccUvQytD0NM4eVCWQIAxenAExk8TWG+YnZy2r5wyo+7e3n dFiqwbfMPNYkhWG+R2mSS7ZVgv4n4a0bn15KlfXa/cIOAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit Description =========== In the Linux kernel, the following vulnerability has been resolved: bpf: Fix insufficient bounds propagation from adjust_scalar_min_max_vals Kuee reported a corner case where the tnum becomes constant after the call to __reg_bound_offset(), but the register's bounds are not, that is, its min bounds are still not equal to the register's max bounds. This in turn allows to leak pointers through turning a pointer register as is into an unknown scalar via adjust_ptr_min_max_vals(). Before: func#0 @0 0: R1=ctx(off=0,imm=0,umax=0,var_off=(0x0; 0x0)) R10=fp(off=0,imm=0,umax=0,var_off=(0x0; 0x0)) 0: (b7) r0 = 1 ; R0_w=scalar(imm=1,umin=1,umax=1,var_off=(0x1; 0x0)) 1: (b7) r3 = 0 ; R3_w=scalar(imm=0,umax=0,var_off=(0x0; 0x0)) 2: (87) r3 = -r3 ; R3_w=scalar() 3: (87) r3 = -r3 ; R3_w=scalar() 4: (47) r3 |= 32767 ; R3_w=scalar(smin=-9223372036854743041,umin=32767,var_off=(0x7fff; 0xffffffffffff8000),s32_min=-2147450881) 5: (75) if r3 s>= 0x0 goto pc+1 ; R3_w=scalar(umin=9223372036854808575,var_off=(0x8000000000007fff; 0x7fffffffffff8000),s32_min=-2147450881,u32_min=32767) 6: (95) exit from 5 to 7: R0=scalar(imm=1,umin=1,umax=1,var_off=(0x1; 0x0)) R1=ctx(off=0,imm=0,umax=0,var_off=(0x0; 0x0)) R3=scalar(umin=32767,umax=9223372036854775807,var_off=(0x7fff; 0x7fffffffffff8000),s32_min=-2147450881) R10=fp(off=0,imm=0,umax=0,var_off=(0x0; 0x0)) 7: (d5) if r3 s<= 0x8000 goto pc+1 ; R3=scalar(umin=32769,umax=9223372036854775807,var_off=(0x7fff; 0x7fffffffffff8000),s32_min=-2147450881,u32_min=32767) 8: (95) exit from 7 to 9: R0=scalar(imm=1,umin=1,umax=1,var_off=(0x1; 0x0)) R1=ctx(off=0,imm=0,umax=0,var_off=(0x0; 0x0)) R3=scalar(umin=32767,umax=32768,var_off=(0x7fff; 0x8000)) R10=fp(off=0,imm=0,umax=0,var_off=(0x0; 0x0)) 9: (07) r3 += -32767 ; R3_w=scalar(imm=0,umax=1,var_off=(0x0; 0x0)) <--- [*] 10: (95) exit What can be seen here is that R3=scalar(umin=32767,umax=32768,var_off=(0x7fff; 0x8000)) after the operation R3 += -32767 results in a 'malformed' constant, that is, R3_w=scalar(imm=0,umax=1,var_off=(0x0; 0x0)). Intersecting with var_off has not been done at that point via __update_reg_bounds(), which would have improved the umax to be equal to umin. Refactor the tnum <> min/max bounds information flow into a reg_bounds_sync() helper and use it consistently everywhere. After the fix, bounds have been corrected to R3_w=scalar(imm=0,umax=0,var_off=(0x0; 0x0)) and thus the register is regarded as a 'proper' constant scalar of 0. After: func#0 @0 0: R1=ctx(off=0,imm=0,umax=0,var_off=(0x0; 0x0)) R10=fp(off=0,imm=0,umax=0,var_off=(0x0; 0x0)) 0: (b7) r0 = 1 ; R0_w=scalar(imm=1,umin=1,umax=1,var_off=(0x1; 0x0)) 1: (b7) r3 = 0 ; R3_w=scalar(imm=0,umax=0,var_off=(0x0; 0x0)) 2: (87) r3 = -r3 ; R3_w=scalar() 3: (87) r3 = -r3 ; R3_w=scalar() 4: (47) r3 |= 32767 ; R3_w=scalar(smin=-9223372036854743041,umin=32767,var_off=(0x7fff; 0xffffffffffff8000),s32_min=-2147450881) 5: (75) if r3 s>= 0x0 goto pc+1 ; R3_w=scalar(umin=9223372036854808575,var_off=(0x8000000000007fff; 0x7fffffffffff8000),s32_min=-2147450881,u32_min=32767) 6: (95) exit from 5 to 7: R0=scalar(imm=1,umin=1,umax=1,var_off=(0x1; 0x0)) R1=ctx(off=0,imm=0,umax=0,var_off=(0x0; 0x0)) R3=scalar(umin=32767,umax=9223372036854775807,var_off=(0x7fff; 0x7fffffffffff8000),s32_min=-2147450881) R10=fp(off=0,imm=0,umax=0,var_off=(0x0; 0x0)) 7: (d5) if r3 s<= 0x8000 goto pc+1 ; R3=scalar(umin=32769,umax=9223372036854775807,var_off=(0x7fff; 0x7fffffffffff8000),s32_min=-2147450881,u32_min=32767) 8: (95) exit from 7 to 9: R0=scalar(imm=1,umin=1,umax=1,var_off=(0x1; 0x0)) R1=ctx(off=0,imm=0,umax=0,var_off=(0x0; 0x0)) R3=scalar(umin=32767,umax=32768,var_off=(0x7fff; 0x8000)) R10=fp(off=0,imm=0,umax=0,var_off=(0x0; 0x0)) 9: (07) r3 += -32767 ; R3_w=scalar(imm=0,umax=0,var_off=(0x0; 0x0)) <--- [*] 10: (95) exit The Linux kernel CVE team has assigned CVE-2022-49658 to this issue. Affected and fixed versions =========================== Issue introduced in 4.14 with commit b03c9f9fdc37dab81ea04d5dacdc5995d4c224c2 and fixed in 5.10.130 with commit e917be1f83ea14a68b3cf64d3da9968eaf991dae Issue introduced in 4.14 with commit b03c9f9fdc37dab81ea04d5dacdc5995d4c224c2 and fixed in 5.15.54 with commit a7de8d436db92bab8b1f44624297c2554a6ac36b Issue introduced in 4.14 with commit b03c9f9fdc37dab81ea04d5dacdc5995d4c224c2 and fixed in 5.18.11 with commit b2a28bb36664c94375926cbbb91976242847699d Issue introduced in 4.14 with commit b03c9f9fdc37dab81ea04d5dacdc5995d4c224c2 and fixed in 5.19 with commit 3844d153a41adea718202c10ae91dc96b37453b5 Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2022-49658 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: kernel/bpf/verifier.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/e917be1f83ea14a68b3cf64d3da9968eaf991dae https://git.kernel.org/stable/c/a7de8d436db92bab8b1f44624297c2554a6ac36b https://git.kernel.org/stable/c/b2a28bb36664c94375926cbbb91976242847699d https://git.kernel.org/stable/c/3844d153a41adea718202c10ae91dc96b37453b5