Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3831163pxb; Mon, 30 Aug 2021 11:40:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBQ9/OwpyxVpoaEbmNZGqXZnhTijmz0bGpEDOFztVZK39RCrjcgBZjq7g1ifoU7TVQ/wiA X-Received: by 2002:a5e:990e:: with SMTP id t14mr19598585ioj.75.1630348801596; Mon, 30 Aug 2021 11:40:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630348801; cv=none; d=google.com; s=arc-20160816; b=DzQXIKZwn+eyD8GZX12E72PSKz8HzZ9vKVlD3eRgT3dcH8Y3UHXPAVBO5nOC9jh8jC JzzTN1yCLjb+LYwLVtekgyI/1Jeti6KcozTpywx2So2fsz56wDJNBA3hIsdE+4sqwY0L BOAnHgFzwV68Qw4qSRvxqFBRhHEVRP0S2TUuEJiGV6oR/goPQCXgj9A+wbBipz/KqNGt RPOkyL109qJv1rVesf7XFamfpAIva7wymR27MpkGalaWch7kHkLe9htfnIZsFpO43Idq zrxT9blQDYzIWaR1rpvPJ3INbNLCBpUyNHxbfbLVSdvyYh+NvEMbS2SiYGymGwZGUxfZ Bzwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=dP2bWFnr904Q3phxdSJFO6HdgfMSWA65sEUBMQrG98c=; b=P8pOiUuQHgi7GLeU6Z8/MYAk8D/7xYQQYRlx4LPn3fXCN4U3eK95lssLX3VSHyYTQB BxJ84dg2t8+ry5avHE645WPlb1RZaMrOgAeXnSGWQy/YBFSQ+g/cZ4W5n4M0vwDo65UI /k55ceGuO2CPYt+ZW/plFu9tdTVtOnC4n2eBE8qiKCx6vPRVu0IDQ1qPErmz1duQv+cF 0Hq3aJSHjdvZoss6iExSFqlEBMJ3ZWq9YKWPxMytopMsW9vxhtWLJzQoxa1sLEpFqki7 egrkojUQ2kvuefc6iPl4UttEd4dVvsJ0e2KMEg+nTGOaIlP+EQz3TWD6JeWYBywkkj/2 yRmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=tEEdtAHG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 10si15595066ilz.71.2021.08.30.11.39.46; Mon, 30 Aug 2021 11:40:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=tEEdtAHG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230181AbhH3Sjf (ORCPT + 99 others); Mon, 30 Aug 2021 14:39:35 -0400 Received: from smtp-relay-canonical-1.canonical.com ([185.125.188.121]:36162 "EHLO smtp-relay-canonical-1.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229738AbhH3Sje (ORCPT ); Mon, 30 Aug 2021 14:39:34 -0400 Received: from mussarela (201-69-234-220.dial-up.telesp.net.br [201.69.234.220]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id 093D340178; Mon, 30 Aug 2021 18:38:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1630348719; bh=dP2bWFnr904Q3phxdSJFO6HdgfMSWA65sEUBMQrG98c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:In-Reply-To; b=tEEdtAHGeXWPANZY9GSNFafDKT6z1GKu2nWOlfBIS5uxclCTIR+OK6BAg4Or0lddr 7eM/MOYbnRMI5cy14s8OTfzI3xxyCdrpWicFgGEmp7NF6tDKlRXWzrSj9R525VyKXY HWGPF9TAWc7iCr/1oDyPbxDz9t0FApF31/RyuLlsG7z8NijAQBbfUa5pwF/hIsltuK dCHv/HjFi6HCXmZgfdKFZPxT7KpfIKDHbyW/XA0MLwQnFn6HwuJhPQiLtu5SF28/gZ hvxsKGH9U8JRSo6Jkhe7JH+B0fo94WfYDbFxmE+l73jzJu78L+rEdssvswM0inoqzc 6xPnmnMin+MHg== Date: Mon, 30 Aug 2021 15:38:34 -0300 From: Thadeu Lima de Souza Cascardo To: Pavel Machek Cc: stable@vger.kernel.org, kernel list , daniel@iogearbox.net, john.fastabend@gmail.com, ast@kernel.org Subject: Re: CVE-2021-3600 aka bpf: Fix 32 bit src register truncation on div/mod Message-ID: References: <20210826102337.GA7362@duo.ucw.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210826102337.GA7362@duo.ucw.cz> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 26, 2021 at 12:23:37PM +0200, Pavel Machek wrote: > Hi! > > As far as I can tell, CVE-2021-3600 is still a problem for 4.14 and > 4.19. > > Unfortunately, those kernels lack BPF_JMP32 support, and that support > is too big and intrusive to backport. > > So I tried to come up with solution without JMP32 support... only to > end up with not seeing the bug in the affected code. > > Changelog says: > > bpf: Fix 32 bit src register truncation on div/mod > > While reviewing a different fix, John and I noticed an oddity in one of the > BPF program dumps that stood out, for example: > > # bpftool p d x i 13 > 0: (b7) r0 = 808464450 > 1: (b4) w4 = 808464432 > 2: (bc) w0 = w0 > 3: (15) if r0 == 0x0 goto pc+1 > 4: (9c) w4 %= w0 > [...] > > In line 2 we noticed that the mov32 would 32 bit truncate the original src > register for the div/mod operation. While for the two operations the dst > register is typically marked unknown e.g. from adjust_scalar_min_max_vals() > the src register is not, and thus verifier keeps tracking original bounds, > simplified: > > So this explains "mov32 w0, w0" is problematic, and fixes the bug by > replacing it with jmp32. Unfortunately, I can't do that in 4.19; plus > I don't really see how the bug is solved -- we avoided adding mov32 > sequence that triggers the problem, but the problematic sequence could > still be produced by the userspace, no? > > Does adjust_scalar_min_max_vals still need fixing? > > Do you have any hints how to solve this in 4.19? > > Best regards, > Pavel > -- > DENX Software Engineering GmbH, Managing Director: Wolfgang Denk > HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Hi, Pavel. I have just sent the fixes for 4.14. I sent fixes for 4.19 last Friday. The problem here is that the verifier assumes the source register has a given value, but the fixups change that value to something else when it is truncated. The fixups run after the verifier, so a similar sequence produced by userspace will be correctly verified, so no fixes are necessary on adjust_scalar_min_max for this specific issue. The fixed-up code is not verified again. The challenge in providing those fixes to 4.14 and 4.19 is the absence of JMP32 in those kernels. So, AX was taken as a temporary, so it would still work on JITs. Cascardo.