Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp980567lqh; Fri, 29 Mar 2024 03:27:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVQJzYH6BTiqPS2478pDqEg6bVXpvrVrKtzB+MIwhzaCTiSKja9vNuPoD3POYmGSrSpnynSI/CFQ7hDWwqVR5zCZojumGTaYrV9cNj0RQ== X-Google-Smtp-Source: AGHT+IH0XdTwWMXnU1gsA/tbb85zKrG8MuqDGBiqGTs+1lZ15/3vFJph3rH7r/iC52u3VK5SG8yo X-Received: by 2002:a17:906:1951:b0:a4e:2017:16dc with SMTP id b17-20020a170906195100b00a4e201716dcmr1299628eje.35.1711708042765; Fri, 29 Mar 2024 03:27:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711708042; cv=pass; d=google.com; s=arc-20160816; b=rUr2f+hEQ9bL6i5ziVilKZFJrupwCKJtThq0Qr7A7AYKoaybv3fInLTTZn0/k28jMX WDwRVd7woWPtXZp088z8BmEz6OWjJ4pnGaAlMp6VOdetFxqhTf6496N9mkIDoxoWGX0m CQkc3CPWm2ELdUpm1G8MuhEMaiBrUzqEeANaeJyYg6jepAL58Y7zNzd2kmiSvoj8rq/G wP+U7Ogy/yvSfHUKtU1DP4D8knt76eD3L+380lCg8p2JcOsJqs9BdOj2pZFjOuBLpRbw n6d8egDrw/lEWUEJ42momPRjY3h88Oe/dFfM8s4uMNsZ0NMDM6h1j0A4H964T1CJeowv GBcA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:autocrypt:references :in-reply-to:date:cc:to:from:subject:message-id:dkim-signature; bh=8LLwF7Wf3KpK5d9C0oJzew2cz/6pNOfGmInaZ55x8RE=; fh=9hO/G36KONmkMGccP+dv7tRayjaWn+LwEU7Wjt8qMsI=; b=Bq36a2URJR/+nXvKYOnL82HHE57vtgN8X3lvPolLfLmewJeHcEstjqPlUICI+uxByW BO1TeAY12rgbof7Y2KCIeFN1JNsxmSuKoPmyAVUJ0vOMcp8FC9XUfcsODBVz8WbSkI8Y pH1Ae/op8wiFPohgsDIN8g9axjxiizkR13nyfdvyTSRy7NxbQpkQvs5bZ57f6ODJWG4u tQn+ebTWLA5ZU8CNN8kHlui11RFZ70foAg6eCb2RIM04SxeQ4Yk8Idm4QMJwtgV1QDR2 EtXnNwZAVUm2W82u8pe/6YMlqXzMUX8UcmgcKZsfWFC7wDPC48Y+RbSOGc5jdG3e5pXT Yf9g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=b+EStlJx; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-124386-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124386-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id oq2-20020a170906cc8200b00a44d0209395si1529781ejb.915.2024.03.29.03.27.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 03:27:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124386-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=b+EStlJx; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-124386-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124386-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 385C31F22C78 for ; Fri, 29 Mar 2024 10:27:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4F3BA54659; Fri, 29 Mar 2024 10:27:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b+EStlJx" Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 AF4644AEDF; Fri, 29 Mar 2024 10:27:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711708031; cv=none; b=ftEXkea3+kHH01FatktHUE5Ieve1DIpB338E/av//MAx41lywwEJxO1S7Qhact5dQYaJG2cItMKMyH0NOnTdxeVY5DSTlctxAT/DxhQQNmMzS72+Miismyee5CW1d2ciGT5e1P1lCXgOITCN/kSxV0eZJhWu3W6AvynosOtGes8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711708031; c=relaxed/simple; bh=9LuXtRdpTRMxadJHryFC6X2b+VM8qPOM/I4Lm6J3rFE=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=UaGpdX1ly/fSq9bk79pqI+fSAAhTiDjmN7Sopf4MJ0upfYmC2AC8SJEw/Mk242CCbSxl9sk+uVmXoV6hiMLs6YvpsR/AMSACciJ+GGsDwQDukiw6LyFQhrEyWXbjSWG+2I4fQlrdOheHlxTBfr8aAmCMAB6lGm/yZMC+6UJZyzI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=b+EStlJx; arc=none smtp.client-ip=209.85.218.50 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 Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a46ba938de0so250986666b.3; Fri, 29 Mar 2024 03:27:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711708028; x=1712312828; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:autocrypt :references:in-reply-to:date:cc:to:from:subject:message-id:from:to :cc:subject:date:message-id:reply-to; bh=8LLwF7Wf3KpK5d9C0oJzew2cz/6pNOfGmInaZ55x8RE=; b=b+EStlJxyR51gVpEee1r67oZmBDE5+XCgDE0lhu5xOwsIdTdDJpQLYOclI3eYaHpDS VGVoyLQk4M63ZJxaCsfVvVI6CVhempNaE8SBwQuS0/oHirCi51MzTSeG/5T6B6x2PMxA ZaiMGb112pUWL+3Ded1t444iWNljchRmYFkPZvel5VFewH+1MNBpkkuj4qYybg1rw+Mo x7nOOk53TS5g0DPeRNqZ4eA2htfCS76lJpQN4XhZYUHlnvJdWH+N455lKnUtmGTiFAz6 YaCecTkBZDWxPEqjlUEWpM/XfR8w/4rwa8M5jI9EmARyyeRr0BMEx6MtEN3M7JLipiTN oP7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711708028; x=1712312828; h=mime-version:user-agent:content-transfer-encoding:autocrypt :references:in-reply-to:date:cc:to:from:subject:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8LLwF7Wf3KpK5d9C0oJzew2cz/6pNOfGmInaZ55x8RE=; b=h8ExwbtDml5eLPSpHsDgirh4KUTGOFGXYbyS7tShyu6yxu9UXsArE+2DPyQH2+aTMv iHk8IIKpr+Ji+XpYmhEoBSEDdZK/PdZRmDo865j1putzJd+zpIofUptRccnRHZO2DsLJ ARN0ZAxKHlwAYu9ZCuYV8xuohWXMVzxZ7lqaMlzcDWdtktZJ21uMpuwAsHNh/qtCJp5A tA5mS3z+GNKKfrhdy+ZmYOoEVtTdIDVetBsz9xOUMI2b4QtGruKmJAqQVtPh4tOg9auT Sl0OtOdIVNZFfAblf+bNskmNsz6fFWyX9p8xbRKan/1QKCOYt7aQZ4x+QacwmlD0A+2a hhpw== X-Forwarded-Encrypted: i=1; AJvYcCVDaXTwALL28yqLGH3NgFJeb1qcuts0tltOgfll1meFDYg/xOCt2m80JF08hE6GzSvSsSzvHbWYvdP3kSSdaXTX7FGegz/SvDmKPxXqFUJwYQO6+QmVJ+QNLTLiU2UkiHjc X-Gm-Message-State: AOJu0Yx2AjH6Y+th52TZ7xzcH/AM62bzdXVa42uHoj74/KcfRFzcB6oq 8T9aGsCeIfwObOw0JpfeErhaFE+aNkWy5A9KPOLXji6E3aOIVXkA X-Received: by 2002:a17:906:1b09:b0:a47:4234:eaf5 with SMTP id o9-20020a1709061b0900b00a474234eaf5mr1303313ejg.69.1711708027787; Fri, 29 Mar 2024 03:27:07 -0700 (PDT) Received: from ?IPv6:2a00:1858:1027:8084:dcff:fef3:4040:e18d? ([2a00:1858:1027:8084:dcff:fef3:4040:e18d]) by smtp.gmail.com with ESMTPSA id qf31-20020a1709077f1f00b00a4df4243473sm1757419ejc.4.2024.03.29.03.27.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 03:27:07 -0700 (PDT) Message-ID: Subject: Re: [PATCH bpf-next] Fix latent unsoundness in and/or/xor value tracking From: Eduard Zingerman To: Harishankar Vishwanathan , ast@kernel.org Cc: harishankar.vishwanathan@rutgers.edu, sn624@cs.rutgers.edu, sn349@cs.rutgers.edu, m.shachnai@rutgers.edu, paul@isovalent.com, Srinivas Narayana , Santosh Nagarakatte , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 29 Mar 2024 12:26:50 +0200 In-Reply-To: <20240329030119.29995-1-harishankar.vishwanathan@gmail.com> References: <20240329030119.29995-1-harishankar.vishwanathan@gmail.com> Autocrypt: addr=eddyz87@gmail.com; prefer-encrypt=mutual; keydata=mQGNBGKNNQEBDACwcUNXZOGTzn4rr7Sd18SA5Wv0Wna/ONE0ZwZEx+sIjyGrPOIhR14/DsOr3ZJer9UJ/WAJwbxOBj6E5Y2iF7grehljNbLr/jMjzPJ+hJpfOEAb5xjCB8xIqDoric1WRcCaRB+tDSk7jcsIIiMish0diTK3qTdu4MB6i/sh4aeFs2nifkNi3LdBuk8Xnk+RJHRoKFJ+C+EoSmQPuDQIRaF9N2m4yO0eG36N8jLwvUXnZzGvHkphoQ9ztbRJp58oh6xT7uH62m98OHbsVgzYKvHyBu/IU2ku5kVG9pLrFp25xfD4YdlMMkJH6l+jk+cpY0cvMTS1b6/g+1fyPM+uzD8Wy+9LtZ4PHwLZX+t4ONb/48i5AKq/jSsb5HWdciLuKEwlMyFAihZamZpEj+9n91NLPX4n7XeThXHaEvaeVVl4hfW/1Qsao7l1YjU/NCHuLaDeH4U1P59bagjwo9d1n5/PESeuD4QJFNqW+zkmE4tmyTZ6bPV6T5xdDRHeiITGc00AEQEAAbQkRWR1YXJkIFppbmdlcm1hbiA8ZWRkeXo4N0BnbWFpbC5jb20+iQHUBBMBCgA+FiEEx+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IGNNAqK+SiLLXt51G7P30TVavIeB6s2lCt1QKt62ccLqUAEQEAAYkBvAQYAQoAJhYhBMfui64wKUMqp1wmBC4MZXpJYEQJBQJijTUBAhsMBQkDwmcAAAoJEC4MZXpJYEQJkRAMAKNvWVwtXm/WxWoiLnXyF2WGXKoDe5+itTLvBmKcV/b1OKZF1s90V7WfSBz712eFAynEzyeezPbwU8QBiTpZcHXwQni3IYKvsh7s t1iq+gsfnXbPz5AnS598ScZI1oP7OrPSFJkt/z4acEbOQDQs8aUqrd46PV jsdqGvKnXZxzylux29UTNby4jTlz9pNJM+wPrDRmGfchLDUmf6CffaUYCbu4FiId+9+dcTCDvxbABRy1C3OJ8QY7cxfJ+pEZW18fRJ0XCl/fiV/ecAOfB3HsqgTzAn555h0rkFgay0hAvMU/mAW/CFNSIxV397zm749ZNLA0L2dMy1AKuOqH+/B+/ImBfJMDjmdyJQ8WU/OFRuGLdqOd2oZrA1iuPIa+yUYyZkaZfz/emQwpIL1+Q4p1R/OplA4yc301AqruXXUcVDbEB+joHW3hy5FwK5t5OwTKatrSJBkydSF9zdXy98fYzGniRyRA65P0Ix/8J3BYB4edY2/w0Ip/mdYsYQljBY0A== Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Thu, 2024-03-28 at 23:01 -0400, Harishankar Vishwanathan wrote: [...] > @@ -13387,18 +13389,19 @@ static void scalar32_min_max_or(struct bpf_reg_= state *dst_reg, > */ > dst_reg->u32_min_value =3D max(dst_reg->u32_min_value, umin_val); > dst_reg->u32_max_value =3D var32_off.value | var32_off.mask; > - if (dst_reg->s32_min_value < 0 || smin_val < 0) { > + if (dst_reg->s32_min_value > 0 && smin_val > 0 && Hello, Could you please elaborate a bit, why do you use "> 0" not ">=3D 0" here? It seems that having one of the min values as 0 shouldn't be an issue, but maybe I miss something. > + (s32)dst_reg->u32_min_value <=3D (s32)dst_reg->u32_max_value) { > + /* ORing two positives gives a positive, so safe to cast > + * u32 result into s32 when u32 doesn't cross sign boundary. > + */ > + dst_reg->s32_min_value =3D dst_reg->u32_min_value; > + dst_reg->s32_max_value =3D dst_reg->u32_max_value; > + } else { > /* Lose signed bounds when ORing negative numbers, > * ain't nobody got time for that. > */ > dst_reg->s32_min_value =3D S32_MIN; > dst_reg->s32_max_value =3D S32_MAX; > - } else { > - /* ORing two positives gives a positive, so safe to > - * cast result into s64. > - */ > - dst_reg->s32_min_value =3D dst_reg->u32_min_value; > - dst_reg->s32_max_value =3D dst_reg->u32_max_value; > } > } [...] > @@ -13453,10 +13457,10 @@ static void scalar32_min_max_xor(struct bpf_reg= _state *dst_reg, > /* We get both minimum and maximum from the var32_off. */ > dst_reg->u32_min_value =3D var32_off.value; > dst_reg->u32_max_value =3D var32_off.value | var32_off.mask; > - > - if (dst_reg->s32_min_value >=3D 0 && smin_val >=3D 0) { > - /* XORing two positive sign numbers gives a positive, > - * so safe to cast u32 result into s32. > + if (dst_reg->s32_min_value > 0 && smin_val > 0 && Same question here. > + (s32)dst_reg->u32_min_value <=3D (s32)dst_reg->u32_max_value) { > + /* XORing two positives gives a positive, so safe to cast > + * u32 result into s32 when u32 doesn't cross sign boundary. > */ > dst_reg->s32_min_value =3D dst_reg->u32_min_value; > dst_reg->s32_max_value =3D dst_reg->u32_max_value; [...]