Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1978139lqe; Tue, 9 Apr 2024 06:28:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVC+Dtixm9Pwp+oMsqjX+IvVhtdtR8IbLL1f6Fnl+p6JcnbMgS8YbC/1F/SRstmynX8n4J93ZCdEinVvUjwxDhHqInNwEZ5Mw31feR5VQ== X-Google-Smtp-Source: AGHT+IG/nA3Ftyum1aOksYvhegJc/2f+1jICr0hvEwqd4ltvmLr7UDypFvDmagMjtL0UpRkdj98l X-Received: by 2002:a17:902:ec8a:b0:1e4:fd4:48db with SMTP id x10-20020a170902ec8a00b001e40fd448dbmr8087891plg.43.1712669302076; Tue, 09 Apr 2024 06:28:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712669302; cv=pass; d=google.com; s=arc-20160816; b=G76aR5h6ejztifny1E0gVc/8lg9w9c+wBdJqLBrmCK8RA0mcmJNIQDNdhTzY09YeEr Xi8a+ESiczc0d912ts3e2MFfyjFmLaoDzY15D9aOo/HGYa4bxrgobiKqD5pNZM7/YgDU Ndr+XyTR83dAeLrGmCVkwmRCR573LukiV8urWn5uXnq/2BxYzCWx5myi75ZRM0Y/ZiTH 4jIVoRoXJ6B2U2DeETCpbmIP//ODvvQoCebfKDB63/cyz7TBLoNOo9w1L++/KeVzCzZ9 GaAUvSLctXf6gGYq4Aw7pHUoAfbTNvijxRjB3qv1FeiserAu2nsJ2GoTSvwxqSFGGg39 6jPA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=89DtCtFIzkBOcJ+3ntnvcyi+RWzHywHNe0Lj3QwBK9k=; fh=/UMSaoTmtUkGzqpxRLHTWVjH4PLusFmYoodAFL+B1I8=; b=iMASuvG4W8FfjDSLXbM/lqJMhrLwhuzYaAFgTqpqz3UMe91Bo1AIVCypEuHu9/cu8T xZdMn2bTRwYBEeJ0QHB9R/L03pqDtC6Z7/acW5x1yQexty3PUwBLGKZFLji2qMr6EoQA sEm3OkEp/RirBtLPkuPFJ7aM+PxbEPE1tg4MK9L0HJcVIVr7U9Ev+3oVhcoPwJ4DDG7Q BRk7VHaxJP/EeNt0K1NtXmj/c/mCbBriV9JTgxEkbOUZubQvg0VpeFnp+jmF0z6Ag2HH Fr4Cmk9v6G981jXu/Du4wU2wF7X+PJ6kaPR6PVJmGGb2ZZfGHjK3o9FQjrLXt04YrsWj a/Yw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.com header.s=google header.b=VEIiwGvH; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-136925-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136925-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m13-20020a170902f64d00b001e29de896ecsi8753653plg.147.2024.04.09.06.28.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 06:28:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-136925-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=google header.b=VEIiwGvH; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-136925-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136925-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 39A96B22426 for ; Tue, 9 Apr 2024 13:16:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5335612A144; Tue, 9 Apr 2024 13:16:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="VEIiwGvH" Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (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 2419686AC2 for ; Tue, 9 Apr 2024 13:16:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712668597; cv=none; b=C8dl7b/FB5RtKJns3jWFz4QKHVUDG5o3mt5qBzOWwE+euG2jX3s2CUEFjVxpwjJk+6N8FMYk8xj4ZWySO3CcgoQzwcfrUr74ktbGYjHsBy9JQcaONgOr2GzunpDOg01YdE3qehb6ZshdPmuOGR3twYYtohllPL9TYp+FuU7gW2o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712668597; c=relaxed/simple; bh=phJMhIBVDBaqGVfRsivP2R4+eY5Tic9quqiYD1cmeAU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SeBKIlrq4gBWjYBw66bXlWrQGiZovB22jOfwx3rCyS3iNVh13IJwu0u2uX4Eyt3E8VUQyyU84k5KIcH8x4DVQWGtCY3F6tnjSmN5Wocsk+q8cUVIeppNNclWZia57xXka+0sVe2VdNXjJ96MO/ptupmldpmT2PCsc7Y1fpWj178= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=VEIiwGvH; arc=none smtp.client-ip=209.85.208.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2d6fc3adaacso69732011fa.2 for ; Tue, 09 Apr 2024 06:16:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1712668593; x=1713273393; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=89DtCtFIzkBOcJ+3ntnvcyi+RWzHywHNe0Lj3QwBK9k=; b=VEIiwGvHUVoimdcz4mUhrpHCZjB3uarOoHxPo6+OFnaJnVovmUwxG8PfYLIdG01sNM rbkMnfabSDLiR1FA+0qU93HVEKUwmo+MpUKNq27ZFYNw6o/qjkxMR6siJbQykKxSiEMr 2k3sHQAE1m0g+pKSfW5FdWM7SiNJfZdCvoeDNJR4ZrmEBCqaMv3Re/FfZNrPJ9++N/IP JK4YnyON2da1nOmqI6eYpPyF/sDn+5NsT3N1sJE+7Rl17K+BeOzKM7PaM2HNRCF4lfeb +NpRb/aQVzt2J7q8eC1eRBY4pUmXMpSI6BN70k3eRzSj8BjvzvYB1YqDNLpCnURJUbyp wx0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712668593; x=1713273393; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=89DtCtFIzkBOcJ+3ntnvcyi+RWzHywHNe0Lj3QwBK9k=; b=wf1NV8ARrBTXPUS3GgDp84aCioYS3upNIzK3brOTVS7zBY2JdL3+DlFXDFf2nvcaXR BBbiy5GIQ47RbKcYpGWQur+jV6AY2ctieHoKsMIaED1zbsZn7oy+tiAqRjS4GYzwodWc VYqUQPpu2QcFHN/lgTUeTZfzACdk/Ghr4B/Hr1fei/yaGUKlfFgsvGob1vIOH7sH8nT5 jorH3RmsefcOC5JFKoatT3OwNeQ+temGYTB9IeRifKhv/gm1MOmKVGAVwtvELtf0xJPa 0L7M+mg/ka3eAjaWCEwM8oLvl8uu6LbJIpKF6RkmiU2LuQe5TgIf7iOpv/UKFHRLFuYr +sJg== X-Forwarded-Encrypted: i=1; AJvYcCURKwo4kAVktJAqoFenk8ejXdbTG5mzT6aknexMz04ytaK+2FyRKRMOHO029Q51k7Ms+9Y3L/2BcERQmUWUd5+LIKejNviZOzObXJby X-Gm-Message-State: AOJu0YzfY9GGOLbzTr9Qgf5vOfa3fyXgpSqbvdhFjKojUFs18MirPmZ8 SeCp37/6NCaOa9xoHFFcUCDUmI9gjCcN8j0fOVgizg8uhLrm1a8Ka1ZdeFSJm98= X-Received: by 2002:a2e:b0fc:0:b0:2d8:87e2:3a4a with SMTP id h28-20020a2eb0fc000000b002d887e23a4amr4120399ljl.27.1712668593203; Tue, 09 Apr 2024 06:16:33 -0700 (PDT) Received: from u94a (2001-b011-fa04-1643-b2dc-efff-fee8-7e7a.dynamic-ip6.hinet.net. [2001:b011:fa04:1643:b2dc:efff:fee8:7e7a]) by smtp.gmail.com with ESMTPSA id z14-20020aa7990e000000b006e664031f10sm8204339pff.51.2024.04.09.06.16.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 06:16:32 -0700 (PDT) Date: Tue, 9 Apr 2024 21:16:23 +0800 From: Shung-Hsi Yu To: Edward Cree Cc: Harishankar Vishwanathan , ast@kernel.org, harishankar.vishwanathan@rutgers.edu, paul@isovalent.com, Matan Shachnai , Srinivas Narayana , Santosh Nagarakatte , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , "David S. Miller" , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Edward Cree Subject: Re: [PATCH v2 bpf-next] bpf: Fix latent unsoundness in and/or/xor value tracking Message-ID: References: <20240402212039.51815-1-harishankar.vishwanathan@gmail.com> <77f5c5ed-881e-c9a8-cfdb-200c322fb55d@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Apr 03, 2024 at 10:40:23PM -0400, Harishankar Vishwanathan wrote: > On Wed, Apr 3, 2024 at 9:25 AM Edward Cree wrote: > > On 4/2/24 22:20, Harishankar Vishwanathan wrote: > > > Previous works [1, 2] have discovered and reported this issue. Our tool > > > Agni [2, 3] consideres it a false positive. This is because, during the > > > verification of the abstract operator scalar_min_max_and(), Agni restricts > > > its inputs to those passing through reg_bounds_sync(). This mimics > > > real-world verifier behavior, as reg_bounds_sync() is invariably executed > > > at the tail of every abstract operator. Therefore, such behavior is > > > unlikely in an actual verifier execution. > > > > > > However, it is still unsound for an abstract operator to set signed bounds > > > such that smin_value > smax_value. This patch fixes it, making the abstract > > > operator sound for all (well-formed) inputs. > > > > Just to check I'm understanding correctly: you're saying that the existing > > code has an undocumented precondition, that's currently maintained by the > > callers, and your patch removes the precondition in case a future patch > > (or cosmic rays?) makes a call without satisfying it? > > Or is it in principle possible (just "unlikely") for a program to induce > > the current verifier to call scalar_min_max_foo() on a register that > > hasn't been through reg_bounds_sync()? > > If the former, I think Fixes: is inappropriate here as there is no need to > > backport this change to stable kernels, although I agree the change is > > worth making in -next. > > You are kind of right on both counts. > > The existing code contains an undocumented precondition. When violated, > scalar_min_max_and() can produce unsound s64 bounds (where smin > smax). > Certain well-formed register state inputs can violate this precondition, > resulting in eventual unsoundness. However, register states that have > passed through reg_bounds_sync() -- or those that are completely known or > completely unknown -- satisfy the precondition, preventing unsoundness. > > Since we haven’t examined all possible paths through the verifier, and we > cannot guarantee that every instruction preceding a BPF_AND in an eBPF > program will maintain the precondition, we cannot definitively say that > register state inputs to scalar_min_max_and() will always meet the > precondition. There is a potential for an invocation of > scalar_min_max_and() on a register state that hasn’t undergone > reg_bounds_sync(). The patch indeed removes the precondition. > > Given the above, please advise if we should backport this patch to older > kernels (and whether I should use the fixes tag). I suggested the fixes tag to Harishankar in the v1 patchset, admittedly without a thorough understanding at the same level of above. However, given smin_value > smax_value is something we check in reg_bounds_sanity_check(), I would still vote to have the patch backported to stable (with "Cc: stable@vger.kernel.org"?) even if the fixes tag is dropped. The overall change should be rather well contained and isolated for relatively ease of backport; and probably save some head scratching over the difference of behavior between mainline and stable. > [...]