From patchwork Mon Apr 29 21:22:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 13647751 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 D1D3E181CE1 for ; Mon, 29 Apr 2024 21:23:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714425814; cv=fail; b=fAtXYJokfvM3awTUMEqyQm8AjjVs7h0PBQJN1oW/h2knuMI4jDA4qXJI50ZfpvNZhjDs12b8uD2Z4nfOZJM2aXxiMz6y0g+zOD/jnQE1JMBEDfIHrniKIO5zyiuknvou80P3r/fE4/jVHKJRTrrVzzc6cjwFxQ0F65XQuvVNqZo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714425814; c=relaxed/simple; bh=BxfJ/cSEyH7X2E/oOj6V8QyjZVS+7LGrG7rYX6OqUuA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=f7G9ZIaZOO1xf96nkUwMCJgJhS8nLqWaYtVVaelyafO5Hu0mfgfOrpLmCmSRtGtxNmR6kfibUy9TgGQP9cRjpPhFsweCG+T9zkFr+n2/huDIkpm9HUzw4zga7IE147CcLz/yPSOnVekryrICIUIWv2OnQ9slk9TG8Pti52uoFB8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=iwnWZdRR; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=VjTc57nh; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="iwnWZdRR"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="VjTc57nh" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TKFdYn013329; Mon, 29 Apr 2024 21:23:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=TLZBu/J9zzqT61og26lnaL5HnWeYvmlSTTwj17M5ZzI=; b=iwnWZdRR4sJWtUE9g+7p8DyASXcvJcepqZD33RrYJmOH26FyX/yA1+FyEvCKy+z7AOqm x6qNVc/0FfVwhVQ+cV2qcFZQrtrkNZMVTt2bSzDmfOWI8vlK6K9MfqamsOFuP3/JzhcP rcP6re92OS6ca8JcuN5yDFSKSYk8I/tmZM8oKaRBl6nEb482qEnWY938tW9kn6VJ4uXV agfS3UDJ8Tc4kDnixAJjpi+K4y/KSTQgmPKrJuqrWaI/nlMn9UULaEl2hf7qeBxu54o7 QHMJZGnEWEayruS2TwFw1NrnUGFu0Wa0NpcNLx1GmE3SvRy2ZKd+V6sgmeuJ9pTopPOh vA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrqy2urk5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 21:23:28 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TJlXVl033179; Mon, 29 Apr 2024 21:23:26 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2169.outbound.protection.outlook.com [104.47.58.169]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6qy47-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 21:23:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fLl3qQTMWb3cMbkgO61xB26XOVSpJ8iPMi7AvpUzga/T4uWIkS9Lo9Rltvfc58GIuumQrBUuNaun7bcKh6fCd2x2pFfQd3XTA9TzXPv4RqZoMuNu92Q7bjgWkBpP90ajj/Z/iG2t//C3o50+ZWrileKZUGY/tMHtuUpqMREChEje0fwsumK0qAZau2C1mU4micQsjqUBTmgHujiwaKxrcr8Ka6SeVObddzSAr+KS4dMyI7LPb8deBvZFR+CBI8trNA3X6jT6IiD8m7D+7onQQUWqfUhyuZmsUbLj2AEeSxeZbPodvhua2Tz+7SY4ONUS77cofvn4KO+kxmGsXWWAzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TLZBu/J9zzqT61og26lnaL5HnWeYvmlSTTwj17M5ZzI=; b=jDilGTYa3osKzqTv98sqkDDB+6gydxYF0i4w54AvLAU8N4+inePoyZjhllZbZiE7COA9wXbuOHsVFB+WIaP3sOIYLx7nzJ/Zfhlhv98wjgkZdJvZuOmEtGyVUQ8qKEP/mc57pEgQoVv4AweUNN7LkwuIHzepFyd2tQaut5p5Orv+0z3XA6INHXIj6PTj1x14Oc9p/SQDXVtXAb2R3hez1pXBaqWkLhQMcjbzzqRWzfacR4kSdUN6KtDwxdz4t+ev6Ae2TwJpqEm8Z64uVL7Ao2bffE2bqKedIhiWI7AKGDIPDkVBQP0JvZGmUXjdJ7Zpxpq5BBlyZ3Fjt2paC4g3AA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TLZBu/J9zzqT61og26lnaL5HnWeYvmlSTTwj17M5ZzI=; b=VjTc57nhBRcvQ3C7vYy3te1vqbiVDBRO4UIzM1yJI6JJtEfnlXC19OPzoZ6y/f892PuATHz+uolqOQP90zmu2LaupJs7b5SBeGdzmAMZ/rvkMRFM8NqeGfBTDrVAa8ZHTd97aPiy/DGyaNj8dZSiKnQWiAXDWqkomHXzN4Phnfg= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by IA0PR10MB7232.namprd10.prod.outlook.com (2603:10b6:208:406::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.35; Mon, 29 Apr 2024 21:23:22 +0000 Received: from MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c]) by MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c%4]) with mapi id 15.20.7519.030; Mon, 29 Apr 2024 21:23:22 +0000 From: Cupertino Miranda To: bpf@vger.kernel.org Cc: Cupertino Miranda , Eduard Zingerman , Yonghong Song , Alexei Starovoitov , David Faust , Jose Marchesi , Elena Zannoni , Andrii Nakryiko Subject: [PATCH bpf-next v4 1/7] bpf/verifier: replace calls to mark_reg_unknown. Date: Mon, 29 Apr 2024 22:22:44 +0100 Message-Id: <20240429212250.78420-2-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240429212250.78420-1-cupertino.miranda@oracle.com> References: <20240429212250.78420-1-cupertino.miranda@oracle.com> X-ClientProxiedBy: AM8P191CA0015.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:21a::20) To MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB4382:EE_|IA0PR10MB7232:EE_ X-MS-Office365-Filtering-Correlation-Id: 290aafe7-a797-4ddc-1002-08dc689298e5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|366007; X-Microsoft-Antispam-Message-Info: M6SqMNBgfGbe6v/K9VREl0sL/lSlbtGuGKk6FEScUUdzuNpkqsXRTSdhrs4ooClL4anq9rooguH9IucIfxHOMdjrX+YcXZH3gWmZFGkDMD2kLjXweYzXYFaYCzHb7xx+0jvwYSgJaBdwrXXkMv3l5oxyPAp/BH/eu/wI3GY2rnlTi0zJFw3Zd7+CZjYihoj/TQLI+hcjLnxYPdRoXZ+QDv05TuFlhj/+ykBKtLbm/EGE3pT6gD1dYfaVA89nfYuxMA1PhqWf1TqrlTxovsN3d7vjxxaEVPGDAtJWOxvNveun6W6dfLcvrTlbPfOAVgx0meq0N+XhS5FcXk3Ncx84P765mHm785Mu8//45L0qywWOFrIi04FhIUngpZ+HAX4LcO6psQ/AG1RWEZVz/5pt4CFFBmJk93OzrJPBatkcEOvFuou9Q4p0tPHfoA4n+ACAHP1WW/Bs2nLmfc3we4IH8NXXSjltmoO0OZ96JujGkDVUfCs1w6vf4hYtvCcN4kZhMT2k+/kw4rEUdQQagCcUVZl1zma1KCNIo7TS6HiMsdnjckeKxqRUiKzbp91AJQhUpl+B3vWqlpgjxJPrZRQF8TVuToOE/cjyF75w2mCM5PDWYiu2U4v80X14Pp7kxtVSTQcwlnLTpGGforsROxPLDObodGkcUBdbbv0fGrV9xAPqLf/6eME8m6yDWDBg1MC4HO1kn2nmmC1KFs0e/79fhSYcElfre2B5yfyxseK1JNinYMyFfok1ZgBKWtgipc9VjldqmhaoHbOLS4PlrW+0xmq6+EAgwf716/iehAIR40V7cLjs3EFXVw+f8zkJbvndWHSqbMU1ij0wTC38Trg0eL0pxPwefAusDfh6RR8bXtgLwxaQ+oQXk+5o6Wmjds0taOYcblkzjLpz0ptsDFRP5dm3+k5oMD7xqkcpuoZcmdIJeYwCZuzT+k3oTaZ4YixaFry6g8bnxBVHd9+vvzyxdMX+/aia64qj4aCZzw2pyCVdPcpJ9VefTmMWlmoQQK/Ou5FoBNRkHLPopdTEWv1Zg0X6uUnUyn95jmEKe9HARM5QdBh4hmDrehkO5TM+lCeTk7Vr7dnbpU7ghJN3Or5T6xyPOCGVzZXB8YjaXWbUYKcoXjBzTLZJS+e9BhhxtuER1sF8aQaHNpBFnSD99xSDeI5I9VC/iQ1Z+X/RvV3JJEl5ntb2TMa3mO5qrFwJvFU6YVeO5kPv41xUdGNt0UVvvYzurfwOLvB0aqVIopBqMYSsEQhaQz00qHxfm4CgrpwTDV/ahk010Tum+Ffs5zis9A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR10MB4382.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(366007);DIR:OUT;SFP:1101; X-MS-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VeLFPaJS1QoJfyF1aecxoT8hmHHgXZ7C4+L0Z4O3TcVRHQujznLOvNbUkkH8gJz5XVZGzad/qXMnLY3nx8DSpxN/e8gPm+XFZiBsyyo9mNThhaEZ2GxHTs2hq2Of+okOdCMOOxK6aI0A2u8R2U3541W4uz2uHxgaFlciuv/rQzA9Zi5gDUv3jXUrvsJ5HHyfmkjxabckoUrdg8zF5+mUNxn8MOZYlz7z/9zh1INUVv1VgDERtR25TQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 290aafe7-a797-4ddc-1002-08dc689298e5 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2024 21:23:22.1085 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: txsHB5Muhr2RiUZfY7auKw2nJfUV6KRkQZLZG7u7QFg33PuYePXEh5xTeGzYHDOkV5pQo0+iVRfVvUtpT54hikBfBlJ9G5gNWBsdKIQfb88= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB7232 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_18,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 bulkscore=0 suspectscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290141 X-Proofpoint-ORIG-GUID: E1ysYDmMauwe-klFJe99mRBgoR87Yayh X-Proofpoint-GUID: E1ysYDmMauwe-klFJe99mRBgoR87Yayh X-Patchwork-Delegate: bpf@iogearbox.net In order to further simplify the code in adjust_scalar_min_max_vals all the calls to mark_reg_unknown are replaced by __mark_reg_unknown. static void mark_reg_unknown(struct bpf_verifier_env *env, struct bpf_reg_state *regs, u32 regno) { if (WARN_ON(regno >= MAX_BPF_REG)) { ... mark all regs not init ... return; } __mark_reg_unknown(env, regs + regno); } The 'regno >= MAX_BPF_REG' does not apply to adjust_scalar_min_max_vals(), because it is only called from the following stack: - check_alu_op - adjust_reg_min_max_vals - adjust_scalar_min_max_vals The check_alu_op() does check_reg_arg() which verifies that both src and dst register numbers are within bounds. Signed-off-by: Cupertino Miranda Acked-by: Eduard Zingerman Cc: Yonghong Song Cc: Alexei Starovoitov Cc: David Faust Cc: Jose Marchesi Cc: Elena Zannoni Cc: Eduard Zingerman Cc: Andrii Nakryiko --- kernel/bpf/verifier.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 5a7e34e83a5b..6fe641c8ae33 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -13704,7 +13704,6 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env, struct bpf_reg_state *dst_reg, struct bpf_reg_state src_reg) { - struct bpf_reg_state *regs = cur_regs(env); u8 opcode = BPF_OP(insn->code); bool src_known; s64 smin_val, smax_val; @@ -13811,7 +13810,7 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env, /* Shifts greater than 31 or 63 are undefined. * This includes shifts by a negative number. */ - mark_reg_unknown(env, regs, insn->dst_reg); + __mark_reg_unknown(env, dst_reg); break; } if (alu32) @@ -13824,7 +13823,7 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env, /* Shifts greater than 31 or 63 are undefined. * This includes shifts by a negative number. */ - mark_reg_unknown(env, regs, insn->dst_reg); + __mark_reg_unknown(env, dst_reg); break; } if (alu32) @@ -13837,7 +13836,7 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env, /* Shifts greater than 31 or 63 are undefined. * This includes shifts by a negative number. */ - mark_reg_unknown(env, regs, insn->dst_reg); + __mark_reg_unknown(env, dst_reg); break; } if (alu32) @@ -13846,7 +13845,7 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env, scalar_min_max_arsh(dst_reg, &src_reg); break; default: - mark_reg_unknown(env, regs, insn->dst_reg); + __mark_reg_unknown(env, dst_reg); break; } From patchwork Mon Apr 29 21:22:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 13647750 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (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 F0AA5141999 for ; Mon, 29 Apr 2024 21:23:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714425813; cv=fail; b=Pfhia3BMfIm4LdE+hw8IuRSUxN0eLNIDBE9BfIMstA93d9UHgLK13Bu17ofkxFkqWCqAnj+tiglY5fv2Z2PXyQlwRwkZjhVoH7mxdZ0UhSnFahscX1DytmR4NQk9ZXfJVhDBGn8x1xwQooiGl+v1Gxg8dnFZgFi1InpAAun8dHs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714425813; c=relaxed/simple; bh=WRs8dd/N4EwzwCuXW4w7fAPS7n5FU+3UL6VZ+zQJKPM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=hnQOStMuOu+Xn4EnvKiz4grsZTsvjhOlPzHrpZC4onT4tH7k4zRJ4DvOAoSmwTMeMNvBIh9q68MPfRwtDE2kt6ciCBH8HEHtL82fgbc27cp/QJHOeOTZlLBDrZHwVGebfv88fOOo0NTeK3qhAxZOgnPKaZFozyqLnLTWrCIDc90= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=DZ6XP87v; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=FXIuJrb2; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="DZ6XP87v"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="FXIuJrb2" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TKFxGx002944; Mon, 29 Apr 2024 21:23:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=GF0jG1TNPg+xdDAKilPbXz7r0c2+MRy1+GFXWe7UgXM=; b=DZ6XP87vTLVtxylTcl6uThIetaztdmmh9IKw3ExJMKhp999cS0e+B7EaOhmOL2XPhB2R /rEDcfii9PEfSa0mDwOzDgNCbYkdHqTfDYmIkWGi4JKRR0QrjymOw1fu08D6sJnmt75V ho2LJjI0l6WgoUX1sfUnKlMMLmiL5jLWYpK5kbw8PWSFMcDggLGTpMSH/Kj2c9UL8RZz lVRABhg7VOWl7T91in1Kh4l3RHHGQPPDWZ1y/s+KAMZGv0Fr32w2rJz9/N+tklx/Zan/ beAvB1YGkqh3RgkOj0oVTX29AcI+vnmSd8nL7ig/aBt+14nUHMAROtew8+kR8z9hQJwt nA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrr54bpdw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 21:23:30 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TLMSvV005063; Mon, 29 Apr 2024 21:23:29 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2172.outbound.protection.outlook.com [104.47.58.172]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6g6hk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 21:23:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cG6aMZ7VdFlQTurGiuMj/993CONg92r9RBLedxbgiwNUNrkgbgI7Fvi/WEiuiD49rc+KISvzjP/P7vOTy2hs8PKDf7qSC+6VjJG8yUqj23sk7Ksx6nuPIEAAjORIZXB8Rypsh59rXvK+MOw9NrRKBELVowld9OtDQraCugVxF30wFYC1Cu6wTIGHfXAv3ySSdfNI34LJMLL+1W9vIgJrjszTT0f10RDpLs2kSOENm1H8aH28mNxV6YsgCf/TEdoyLp4BAtJhLBIHszcdWPqbJYNigsTxrwiZBmz21GUqalqYG0/f6wJFJ6nhTgZ/8+14GXRn9uwziSXK4UruhJtpHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GF0jG1TNPg+xdDAKilPbXz7r0c2+MRy1+GFXWe7UgXM=; b=MjckQ/DjtH9EwjPNg0cqKN36hKsXeNYrPIGBS1IpITPpeRo/NkGDtwHjUSLKXBwLgUohU8NZ2VDijxqlV0qBS4XG+A62a3iTsyzj9FvMtVRW+5w7LQpWoyl8LE/PCJJue6XJoYyndE9r05zdFaW+YR/qvMOjHYN1FSbIl+ybcMpbCDoKX3QlHzsBUmmt83vIGLRa+Dq4xJCHBNTmJBcPsD4t7m6nBFQs8VVsIZHPvWy6Ejj29I/sdfU42kms458P6q+x05ppVp1NN5u/A0XV/0+V/nYQJh2iyo8NNpLcfEzVfwFJqRsYY6H6menWe+ulm2alCftIxnCfhQxyYxDWwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GF0jG1TNPg+xdDAKilPbXz7r0c2+MRy1+GFXWe7UgXM=; b=FXIuJrb2/CLAS8ms98zmuTYfs7xp/cZI5bbXCa5HiOJV3RA8L6aSyQ5l4M0VYuOUVOHf38bVHRViImWRDAzNrQM779olsOqop+g1hS/Sw/hM0g4jkJOfoEOefSRttnAvV1B4K4co87fX+DyScTibK0/XrWrcmMgZhfohMniP/As= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by IA0PR10MB7232.namprd10.prod.outlook.com (2603:10b6:208:406::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.35; Mon, 29 Apr 2024 21:23:26 +0000 Received: from MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c]) by MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c%4]) with mapi id 15.20.7519.030; Mon, 29 Apr 2024 21:23:26 +0000 From: Cupertino Miranda To: bpf@vger.kernel.org Cc: Cupertino Miranda , Eduard Zingerman , Yonghong Song , Alexei Starovoitov , David Faust , Jose Marchesi , Elena Zannoni , Andrii Nakryiko Subject: [PATCH bpf-next v4 2/7] bpf/verifier: refactor checks for range computation Date: Mon, 29 Apr 2024 22:22:45 +0100 Message-Id: <20240429212250.78420-3-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240429212250.78420-1-cupertino.miranda@oracle.com> References: <20240429212250.78420-1-cupertino.miranda@oracle.com> X-ClientProxiedBy: AM0PR10CA0039.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::19) To MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB4382:EE_|IA0PR10MB7232:EE_ X-MS-Office365-Filtering-Correlation-Id: 0b7ef4d8-8c76-44f7-8596-08dc68929bab X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|366007; X-Microsoft-Antispam-Message-Info: qVD2vCNs0rGfMGwZe6uMeZU23HXLABxMVhpuLPOnIsTqNT/5z09WY9JxglfyV07E/MQNQWY+5mxXxX3PoeGB+JWigJdjH6QjtJR7bnHf/I00pCPitucN0bPoWI0dowRV0cEMGJ5L9YlJ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IjUc+1K91tM04J3FXdcVL0ZrZ/4HVMVqRd1KvliPtU94lWXTNX5wu64wozPXngojrVkjtRPuX8BTE2Vch/K7oRPsUg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR10MB4382.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UHoEfTr7UWxulw/xe8oALdt2mwBUjZuG4z5jBcI5U/sGK10duaC9slLBmRigu58QNkvFZpxQH1tc0zNnRjExWJ120oPfX+hk5PI9VgxjDS8QRGA1BFVu/oFxHzVio7sxYcTtkR8ZIiaERbgOUGQ6XbKyfmLpVq76uMeDOChZeVktMzqKTHhRUvDqULVMfkdYr81E/TdaE71RN1jvf4kyuk/3bBoGq/0Kzm0Jr8VU7qSm7jg+JTJzLyUw6QTGQnh/m0pkVvGlHpVocPIWntkxYQvDqkdwNde9Ul1phuWSVPRc+3eAngMI5rY19B0GzndVdXy1gCkBCA2JxPjYoIlC8XQ2nbBzLDb0fYBYV974s4f/1vWAHafWZMu0/lu26E47Iq6Js4T3Rbs0blI1nJEpMUu36jznDAWbdBphJ45IL8fGVsswP24FAcHcnUdVlLpUHC+FBBVwUlxK7/dOW0PNK9Lpr+SuaxrMaWg8a2yX4J6EZg2uGzip4tzXMbWNrZVNtxH0mLqET0uGkq0kPh9VMhyYsPZS7PncLIE62UimFnniVVqxC3m3dDT6toUg3Y6wWWzbj58rV7TdWQ/R51C46Hd1jDvJ85pGos94++R9nrOgqB1brTD/IQK0YkAIGZON9G0J1gDNyPngwjgiN9o7Lo3NblRver81n7V9SY2OtFt1oBBK2aJ/l0wtm4jdiCQ4pUKsEd8yT5fzEYIBq2Kzb43xk/AwXvI38EOeZj6cikJYZ5pvD1K1/rESB0jyMRFDh1NA91yEwnwj4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h72+OAO3zrg29hY44DUvODtEzWYAOLgGnp443pjtco9hstIpnlaAkPJVtrHaKTu58U79Khby7xOHC+TQDapuyRg7NqGQjqWE1In4Jkv9YeKfUA1BKdOrAynVptZ7ZjApWyrDgHmFEM904kIxAK55kaqrvQKCFebsFPW6DZ+ARBB/zH2O8vbMFuCkcSz3nX0PqI8FuFAvRS9BGYZ+1uonipMsxMntOfY806Vap5yBeolYp/f+GPhaujRTzR9d067v6Mx4KDnBlXvTwVwgoH23JGME5UBln3uhAvtXNoSTQrZmFNr7tJ9pesFXpzIwLshJPqMvI5VsTe0X8RnpVQk4Dy9rDdYRBTL+GtmSsF+EnwDz7JEaWmN2lRUGEhr1H0OJ4VQ2y01V1296Dpay7cYOAHAF3xxkLl2PLNXG3SAW88AJZm/UED6aZNfkAndb39aNZ7k2/8s4BLIC9RXRhseFk37sQtePTvu8Llw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0b7ef4d8-8c76-44f7-8596-08dc68929bab X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2024 21:23:26.7670 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LhreFzKtS4+8sb+vTTjB/474kLgfAdiCoD8G2e6odvPvDEhPvYzri482ZxDNophmmG3UNkXlb0RnruL1O1Ypd2G2Q3l0QIWOBDFz5jf4g5A= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB7232 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_18,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290141 X-Proofpoint-ORIG-GUID: siLPwhy0UXmSHw_mb6aUbcT7hV_Ma-uU X-Proofpoint-GUID: siLPwhy0UXmSHw_mb6aUbcT7hV_Ma-uU X-Patchwork-Delegate: bpf@iogearbox.net Split range computation checks in its own function, isolating pessimitic range set for dst_reg and failing return to a single point. Signed-off-by: Cupertino Miranda Acked-by: Eduard Zingerman Cc: Yonghong Song Cc: Alexei Starovoitov Cc: David Faust Cc: Jose Marchesi Cc: Elena Zannoni Cc: Eduard Zingerman Cc: Andrii Nakryiko --- kernel/bpf/verifier.c | 136 ++++++++++++++++++++++-------------------- 1 file changed, 72 insertions(+), 64 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 6fe641c8ae33..1777ab00068b 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -13695,6 +13695,77 @@ static void scalar_min_max_arsh(struct bpf_reg_state *dst_reg, __update_reg_bounds(dst_reg); } +static bool is_const_reg_and_valid(const struct bpf_reg_state *reg, bool alu32, + bool *valid) +{ + s64 smin_val = reg->smin_value; + s64 smax_val = reg->smax_value; + u64 umin_val = reg->umin_value; + u64 umax_val = reg->umax_value; + s32 s32_min_val = reg->s32_min_value; + s32 s32_max_val = reg->s32_max_value; + u32 u32_min_val = reg->u32_min_value; + u32 u32_max_val = reg->u32_max_value; + bool is_const = alu32 ? tnum_subreg_is_const(reg->var_off) : + tnum_is_const(reg->var_off); + + if (alu32) { + if ((is_const && + (s32_min_val != s32_max_val || u32_min_val != u32_max_val)) || + s32_min_val > s32_max_val || u32_min_val > u32_max_val) + *valid = false; + } else { + if ((is_const && + (smin_val != smax_val || umin_val != umax_val)) || + smin_val > smax_val || umin_val > umax_val) + *valid = false; + } + + return is_const; +} + +static bool is_safe_to_compute_dst_reg_range(struct bpf_insn *insn, + const struct bpf_reg_state *src_reg) +{ + bool src_is_const; + u64 insn_bitness = (BPF_CLASS(insn->code) == BPF_ALU64) ? 64 : 32; + bool valid_const = true; + + src_is_const = is_const_reg_and_valid(src_reg, insn_bitness == 32, + &valid_const); + + /* Taint dst register if offset had invalid bounds + * derived from e.g. dead branches. + */ + if (valid_const == false) + return false; + + switch (BPF_OP(insn->code)) { + case BPF_ADD: + case BPF_SUB: + case BPF_AND: + return true; + + /* Compute range for the following only if the src_reg is const. + */ + case BPF_XOR: + case BPF_OR: + case BPF_MUL: + return src_is_const; + + /* Shift operators range is only computable if shift dimension operand + * is a constant. Shifts greater than 31 or 63 are undefined. This + * includes shifts by a negative number. + */ + case BPF_LSH: + case BPF_RSH: + case BPF_ARSH: + return (src_is_const && src_reg->umax_value < insn_bitness); + default: + return false; + } +} + /* WARNING: This function does calculations on 64-bit values, but the actual * execution may occur on 32-bit values. Therefore, things like bitshifts * need extra checks in the 32-bit case. @@ -13705,51 +13776,10 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env, struct bpf_reg_state src_reg) { u8 opcode = BPF_OP(insn->code); - bool src_known; - s64 smin_val, smax_val; - u64 umin_val, umax_val; - s32 s32_min_val, s32_max_val; - u32 u32_min_val, u32_max_val; - u64 insn_bitness = (BPF_CLASS(insn->code) == BPF_ALU64) ? 64 : 32; bool alu32 = (BPF_CLASS(insn->code) != BPF_ALU64); int ret; - smin_val = src_reg.smin_value; - smax_val = src_reg.smax_value; - umin_val = src_reg.umin_value; - umax_val = src_reg.umax_value; - - s32_min_val = src_reg.s32_min_value; - s32_max_val = src_reg.s32_max_value; - u32_min_val = src_reg.u32_min_value; - u32_max_val = src_reg.u32_max_value; - - if (alu32) { - src_known = tnum_subreg_is_const(src_reg.var_off); - if ((src_known && - (s32_min_val != s32_max_val || u32_min_val != u32_max_val)) || - s32_min_val > s32_max_val || u32_min_val > u32_max_val) { - /* Taint dst register if offset had invalid bounds - * derived from e.g. dead branches. - */ - __mark_reg_unknown(env, dst_reg); - return 0; - } - } else { - src_known = tnum_is_const(src_reg.var_off); - if ((src_known && - (smin_val != smax_val || umin_val != umax_val)) || - smin_val > smax_val || umin_val > umax_val) { - /* Taint dst register if offset had invalid bounds - * derived from e.g. dead branches. - */ - __mark_reg_unknown(env, dst_reg); - return 0; - } - } - - if (!src_known && - opcode != BPF_ADD && opcode != BPF_SUB && opcode != BPF_AND) { + if (!is_safe_to_compute_dst_reg_range(insn, &src_reg)) { __mark_reg_unknown(env, dst_reg); return 0; } @@ -13806,46 +13836,24 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env, scalar_min_max_xor(dst_reg, &src_reg); break; case BPF_LSH: - if (umax_val >= insn_bitness) { - /* Shifts greater than 31 or 63 are undefined. - * This includes shifts by a negative number. - */ - __mark_reg_unknown(env, dst_reg); - break; - } if (alu32) scalar32_min_max_lsh(dst_reg, &src_reg); else scalar_min_max_lsh(dst_reg, &src_reg); break; case BPF_RSH: - if (umax_val >= insn_bitness) { - /* Shifts greater than 31 or 63 are undefined. - * This includes shifts by a negative number. - */ - __mark_reg_unknown(env, dst_reg); - break; - } if (alu32) scalar32_min_max_rsh(dst_reg, &src_reg); else scalar_min_max_rsh(dst_reg, &src_reg); break; case BPF_ARSH: - if (umax_val >= insn_bitness) { - /* Shifts greater than 31 or 63 are undefined. - * This includes shifts by a negative number. - */ - __mark_reg_unknown(env, dst_reg); - break; - } if (alu32) scalar32_min_max_arsh(dst_reg, &src_reg); else scalar_min_max_arsh(dst_reg, &src_reg); break; default: - __mark_reg_unknown(env, dst_reg); break; } From patchwork Mon Apr 29 21:22:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 13647752 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 72BE91836EF for ; Mon, 29 Apr 2024 21:23:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714425824; cv=fail; b=tSgLW0ihXDBWKBBUtuLE+iVtRHb05uBdH89SsAVOiLPjS/7Jcc7saTaZIZ9Ekc+2uvrTmIPchlyvJoTko4OfBWWB228O0uQ5Yq3GNLn1jCzmunzojgOFsU5sjmEVhG7OCYI1/KyG8FT+ecwSm5C5bxWMHALaMnpIuGISIw8RxKs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714425824; c=relaxed/simple; bh=i8S/+wrErany3wbZTX14ooLr381ax0IlqpQ0kBXQJww=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=VxqFoCuzIOIHpNSjipagrrhzxHq4qt3+WjynkV/9aQ/bwk8ZyXz+oLik9+b882sp/ENpt3Dfiho1dXHNsXh0okk7G2crupbt3w0JXkBwvHkvU95s9lNE4LltZCSEovwhhh0x0Is7TXRuIvnVCWJA48Nr25q+cnmIhEw3bVZZ2Yo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=F7s+eZM/; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=BAUPfpTM; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="F7s+eZM/"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="BAUPfpTM" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TKFmgE005279; Mon, 29 Apr 2024 21:23:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=Kiy1j7ZxtprfAnIbOIFVcUwqUiROQa96z0TzvqUhSvs=; b=F7s+eZM/HQHOxSP9fHLbO0sHlDGMdRlPG1Pakdha/ujuVOma/9p6nUG1AyyT3mAh9aZL pb/fEA0AAUMQMFojL1kgulJDUSpHE27stG9eQHmuXMswgq24iLQqDmLiCVXmBndiPnHt HTv7Y0UsuC7wWJuwws5MP5cO9rqCHk3YD6Cc8nUAv/RfR8XyjM/bZD9H8t/jzZmnGuQz AfpiSqqjGw9E/zloPjG6ZT/4IJx8CkdhEHWQPcuSkQ4gJTwVsdVcEwDGYdVGH66BJzXn TRRXG0tptCW5yvLkNHfEf12L/SX8mxhzP6uhV+53J5SVwUCSLmauFy1sVnOw6Oz3mIsy Sw== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrswvkpd9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 21:23:38 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TK84Ao008598; Mon, 29 Apr 2024 21:23:37 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2173.outbound.protection.outlook.com [104.47.58.173]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6wbww-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 21:23:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PPj6aFUqOjgyt6awPBhGMPigLxTsPLjVJvRVxDP0PMgnAdW+1/TVbD5u8J03M7AUsvO/dPH9++edCHYrOOJ4Xd987JNBXkwaq8RNEukgvrqRfL9Ff+sOpHH+l4FIim0yWNdM68E8tfmouVx773JwhOVyRAhNXI8pVQtYF3B3ofiHPSd+5aH5/dVVCi0snH5OWSkJ/BFzFfpcRLZeWXy+gSqCijceTc7mcVfstIF4VfiXCAHcwsh9oa+/ptOxtOV+cL75/XxHQoHzuWIYK79pC1aUhJKzQp/uQFv10ieKs53PE6vyREOUFciEZSgC4Fdxg4gKzcIbnvAN13Psp8sS3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Kiy1j7ZxtprfAnIbOIFVcUwqUiROQa96z0TzvqUhSvs=; b=bQ30AwmKlinJ7lVaAq3rK9hHjz89MFdFjNY+7tenRP8VPQl6643kpAmogQPVeSI8KMo/PjeBs3gBSMabq4AnHR487rkXIX6Rtdh0hTpP4q6SevHeFh0Nyx3h8DFOX4PnRZtWMWAHQqxk67lGD7a/qGN4l9BxfzbDjCIS9TeSy59kRuvvkhvV02xRGgGN4aCdCesQJ3VMpeA9YsFfJPiIQ9+NGhhElyganzUNjcFnwoGUNwMazyWTqoGBJrLJyjRz2kyTW6XcStumXpXaLqj+uggKLYT9SWrPsfWeSaLCuYGt0rTAvFQR7VQQj/UgSx6UWgb22JoCFnWvhEyFkFkLVQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Kiy1j7ZxtprfAnIbOIFVcUwqUiROQa96z0TzvqUhSvs=; b=BAUPfpTMOmO24gmknvrPXNSx6g20ctGWkSTk63CI8ZDQ6mtesXazzb1g9xXPMoIJrGluvl92OhJg9UhRUB1NrgDaOys2g0Bhrwtj2/ab+qY1MFr6jVZn2zNrVEJHbB1j8cEaktFY2BYjVkdiRMfxqUTeVjd/bW9U0juVB3ePxP4= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by IA0PR10MB7232.namprd10.prod.outlook.com (2603:10b6:208:406::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.35; Mon, 29 Apr 2024 21:23:35 +0000 Received: from MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c]) by MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c%4]) with mapi id 15.20.7519.030; Mon, 29 Apr 2024 21:23:35 +0000 From: Cupertino Miranda To: bpf@vger.kernel.org Cc: Cupertino Miranda , Eduard Zingerman , Yonghong Song , Alexei Starovoitov , David Faust , Jose Marchesi , Elena Zannoni , Andrii Nakryiko Subject: [PATCH bpf-next v4 3/7] bpf/verifier: improve XOR and OR range computation Date: Mon, 29 Apr 2024 22:22:46 +0100 Message-Id: <20240429212250.78420-4-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240429212250.78420-1-cupertino.miranda@oracle.com> References: <20240429212250.78420-1-cupertino.miranda@oracle.com> X-ClientProxiedBy: AM4PR05CA0010.eurprd05.prod.outlook.com (2603:10a6:205::23) To MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB4382:EE_|IA0PR10MB7232:EE_ X-MS-Office365-Filtering-Correlation-Id: 8bd4b8f8-d1c7-4414-b269-08dc6892a096 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|366007; X-Microsoft-Antispam-Message-Info: /wY7MPCuQxcQnPtOXJkbaB2dzPbYOTV7Qka8kyYM+bX1swAaUdPaBa9z2UyKYWaag5IEt9sB0znY7xDQSycotP5IqGqsIFgD+nKOUYAlqAoIReX0cU1+9kA30uMe/CuhuUVw41krQyCLFr+OInC/KgDk627h/ARuFRtA8Khd5t8XtxwqhWGmiQsv7K9U8ka1K3+090AwcR6C8DJ2rzemuEYXrb6oupW1XZC3o1ziwVXioB6Y3MXG9n3iBYmmS/dBYcTCUNVsrGP4Q3UBN1piRzWUnFxEZj73Y5l4kTB2s6Znqs9r2sUj45M7diWuLLJnJDpSk26UOC0HJFOSbJd3t8G7VzjYVafV75Az1em83w3VzXaScNt4xYu2AculGQblpVjsVSbxdLILu25xs+B1xOdrtiJUK1MKCZFbK8OLH9K7/YnQkx8X90TpqqmBz9YjYFOEZIpjzBnfd3c7onqNgbiQURTZWlWSjVdUzYtMYoJPNvoksqeesitxYsCmoYPsoixx2npAmXKeqrIwWwpGJp/SxCO6qxyn1JaALi+QV55hWXKrZyqtJVnvTZFer3CgCjDZc5d7lhVPvYl6uWxkHgv4PvH+TPbP0Ar4UJ6y97S69i6UCC9lZg9XqBF73K5coyFXSqtPj8WsUz8dfHAZNlyt1ui62B6zxnuxP1AF87v5ta4EctlrNSssFbuXOJamZ/5irnlsjHKrgi6qYk6gCMANBVOBQTW3oPZkeK0qaEl0U+9xv4mFNhFTTMIW3W0ZBEq96PkS43chFXvUdR0C9R9ym/SvPHDgM5gOsJdYhdiGE5OaDVEYfjGZzI5qpLwkniOaiRYsqxHkQFHKr94Y+ZgkWwTYbhmTHmyhNUVZXK2g8jlo/QC39GGuwEij9aHl5Y71adked5HGEbBSvL4YpTM0ox6YZsJieiIEqX8rSOVd5kJgdXVcoZZZPxfyHN/yw3LFTdJ8e/PgtmQ7E/Xpob9qM49KYmpnkGvnrAFpKNU5UdreYn8JXDzD/H1y0ls432+xpGq5n9gR5LCNBjSiwqTyzkjYqYnQ/1ZWKCsxrXvsrx6jy3HB7IBGqAKhwxjyax2m1QXqFCHy0w5B93m3EEzhqByS+KqxBn5PrEXlOZOwFyKgG2YECaQlZ5snm/h8SypP7MxoUw+63tHCMJIcHW9LeSdDhDwsaGPf//0+6qis/8xlRj//R5rMI51kNV05cUWs3wrbM1hNemfUkelzblS+PkpBKVKNbw6bmyJXyEfmu2V8nGPKjBplLip/pbgw362exqxgjoz55IKxjAj4Xw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR10MB4382.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ++pfixPidk1e5p+569QdnYTFfnY96vIsqLdpc1C0NCpo4K6kGzWsoxuiX31hchOCdkP8gux9OiWzpIKhkaiWsQqgW7BsVzvtTkgugHEuU3X6dnIlZ3xxvFWdfxGvs0bqUfsz1Ve1rETFu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3Abr54fBoxBsphworuMEFQfU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8bd4b8f8-d1c7-4414-b269-08dc6892a096 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2024 21:23:35.0168 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VVypPe1FqYvoJRgHPg88QTeYMbJcYO9YQFgrn0aeRNpteGvKf/Y/uEg2g4tOZqFU+uyP2tkCR+GL5o7fIHYs4lYHMjiRmKUX4QzP/XAEgjY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB7232 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_18,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 adultscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290141 X-Proofpoint-GUID: dozftlAR2o2G6nlv7DRn9NXqoqkOYmwr X-Proofpoint-ORIG-GUID: dozftlAR2o2G6nlv7DRn9NXqoqkOYmwr X-Patchwork-Delegate: bpf@iogearbox.net Range for XOR and OR operators would not be attempted unless src_reg would resolve to a single value, i.e. a known constant value. This condition is unnecessary, and the following XOR/OR operator handling could compute a possible better range. Acked-by: Eduard Zingerman Signed-off-by: Cupertino Miranda Cc: Yonghong Song Cc: Alexei Starovoitov Cc: David Faust Cc: Jose Marchesi Cc: Elena Zannoni Cc: Eduard Zingerman Cc: Andrii Nakryiko --- kernel/bpf/verifier.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 1777ab00068b..54aca9b377a4 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -13744,12 +13744,12 @@ static bool is_safe_to_compute_dst_reg_range(struct bpf_insn *insn, case BPF_ADD: case BPF_SUB: case BPF_AND: + case BPF_XOR: + case BPF_OR: return true; /* Compute range for the following only if the src_reg is const. */ - case BPF_XOR: - case BPF_OR: case BPF_MUL: return src_is_const; From patchwork Mon Apr 29 21:22:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 13647753 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 CA571181CE1 for ; Mon, 29 Apr 2024 21:23:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714425829; cv=fail; b=o6VvZjBYP2U4VI8CkbVhAllkoltA3K8ysgCG7DMOkJpT6JI7LYodUKWoGSWBXE1LQ2fvYoJmGyLQLa0+NMu4twXj7JVO/L8VrIxlmxCBuE8t/U5NDnl6e1c8J1e9sKfpcaX4pbLSw2pzLCmB0pS1miuW+1VoQOmbTcfuXV2d4NA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714425829; c=relaxed/simple; bh=C1QgBYla+LEzpbFbQTnqC+/5tLYIIffgrXEhs6aX83Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=JDXfdxL7cVziozqpCcbxSKI/znkWDR8zNwP0sygkvLnko3qV+GK3Kg4DUrav+j8s0yY+GQvY3w2ao/SgR6Vr3EOCTVeDFwKMcYgaRNIAiyCEVLyxyadsCx2q6oGCVijqbwObRBX+YQFiEl5kBWprAoIMZ4o9yEWmajeLvpYunAg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=Bm+dPgzp; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=cSSzGPHh; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Bm+dPgzp"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="cSSzGPHh" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TKFg6A015469; Mon, 29 Apr 2024 21:23:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=xsnL++MmLOo1Fs7S8xQ575NKiGIAAkMC1NZQHDvYYG4=; b=Bm+dPgzpAOat617C4XB0JLiKhPPGS3rc8PemDmJ2qNjJw2ZudLdWN0gZ8xvL2hKUpzLF ojpuYkw3+gDkz0Ineyc2I0qlYmyyFAC0A3gjpyUnrGK3hc9FnFIr3y3PQK/NO2NQwasI jWVf+uLbBwdNez22HkJvDpNsClNWAQDeN8WIL5KJn/DOuAawJwcIs4JJxerm7948x+KT ZS0yUOJvgJLtjv6LAq+8b+HGKIk9fDGu+WHHpySe/0rFlV5CUaz1gbrSd9/gju3mWeHo xPRyN2bR6zUmsZesCPJRE6IdnkXtBlKVzg79mH477Hi8/CkQb1bDBaiPIpqvGQJWT4ne +Q== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrr9ckrhb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 21:23:43 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TK3Uuu033171; Mon, 29 Apr 2024 21:23:42 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2169.outbound.protection.outlook.com [104.47.58.169]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6qyce-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 21:23:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fTQB7BEJL9a3Av914CVDEN70Sf40A2FNxotXdzFrPWFBi1il9fV20lxK2wgtYW/Yx5URFKzISYHuFNGOKEvpg6AqD7PWYHXF6lisw6BvRrIb20zK4Lw8pIpUYf0VOJHdDIJBGVsyq3pdxwaMehiv5EFpLC8DFPcW3hukr95aPYHqHHRNLtmHHqJkJkhxopvsbsSDd4F3BLBlSmbC2IAi19tkj5J2OhA09m3I7S0d/dnWl9L/zvyUzn1bm5TpjK+wJIcLn+eSzHW1oj7XFHUGSJt1lN2/SfAXkysd03FYGo9uCezDddIQ9swkzeOAUMecISd02++YG5fNEQBiLK3A4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xsnL++MmLOo1Fs7S8xQ575NKiGIAAkMC1NZQHDvYYG4=; b=NpHGxijbZD9ZSlor6nJfxO8H67OODzZgVpk7nRoVpfcOg2Km2l+CPzp/u+TaOGgFP76jyexcYLyNtboTWVrIlK4gGCHie1UzElDYK9vyeQxVX8Xn/NxsQ2pqOOnxOtdAdPBloowkfik/o7sldXktRtOE3iellPu/ErQiPYj6OwIFU6oJtr3JY17xr1rAEaPNLbwtxqNZi9Cc5wIc+f9AZ4lUoEOBL7aPxiWvRsLY/0wmzveczIKyvVbnRSxJERDsXYECXTKOGN84ztsaXwi4P32hlWqWMS5JxQA6kgfZR5lihu9eSAaP+yoS2xAmBlA8jXlMbfOaZha+hxYVU94S1Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xsnL++MmLOo1Fs7S8xQ575NKiGIAAkMC1NZQHDvYYG4=; b=cSSzGPHh3A38yguR21+fYvlvh9eT3K+IebhRJRpsQ4I3mL0UPv+jnAtAir5TPYYuYsR/PCF/390VM5Ty8slhXb42MXXqJdJjFbkw08nU3zZ7GvKcbr4/uYmOnbmoSQb+WiZ63w4pbaJ61X1mqVQZyhSDjmh+RKOsU3STU6btQPs= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by IA0PR10MB7232.namprd10.prod.outlook.com (2603:10b6:208:406::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.35; Mon, 29 Apr 2024 21:23:40 +0000 Received: from MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c]) by MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c%4]) with mapi id 15.20.7519.030; Mon, 29 Apr 2024 21:23:40 +0000 From: Cupertino Miranda To: bpf@vger.kernel.org Cc: Cupertino Miranda , Eduard Zingerman , Yonghong Song , Alexei Starovoitov , David Faust , Jose Marchesi , Elena Zannoni , Andrii Nakryiko Subject: [PATCH bpf-next v4 4/7] selftests/bpf: XOR and OR range computation tests. Date: Mon, 29 Apr 2024 22:22:47 +0100 Message-Id: <20240429212250.78420-5-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240429212250.78420-1-cupertino.miranda@oracle.com> References: <20240429212250.78420-1-cupertino.miranda@oracle.com> X-ClientProxiedBy: AM8P189CA0019.EURP189.PROD.OUTLOOK.COM (2603:10a6:20b:218::24) To MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB4382:EE_|IA0PR10MB7232:EE_ X-MS-Office365-Filtering-Correlation-Id: 2c3b9449-ee75-46c1-5354-08dc6892a3d3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|366007; X-Microsoft-Antispam-Message-Info: zR7UmqiAo375DpoM4v7+/QnhKpt0xRofBECSAziIZQu3WXb0fWk1qbn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8K7nHZx5ud0VRyIwTMAv05GrLOWvP83GB3U8tEMqo5CaidCP/oB0RGyHSiGh5FX+HK6W9lVRZrmBpZdKhjsM5m6iO9sBc7qJt+spXd8dI53lLev7XYFjnBcoN/CS4ezjW7wv32/1OxY4F9wNZtmS/s9Snb90lnRotdmrWNZouJnN/i0Zh+hQ6oYxA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR10MB4382.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nLEOD+tYBEaGu8aN+aV/9+1MFW6LK4MFlfOZsBM1yWqesHt9oFc4EvKTPFilSo9VX1DUlnUYCUNzSF+kmxTWjVf8VYDcf0oqaQPfj0SpN0z8BBbKi5o70b8mrKkn1V18V2aLZUsymNXvYidzz+qDTpirZ5jreqyg3hAjQW2sLcg7JRiEtbcHWixu6mTh5uR/DaVVIlCARsR4/tjpCSsA+yPUt5OJCeq7Zt5aMckEKEs3FNNP/rUD2+J81Q5Zj3j4KDmnYjfDzK8F7Jmj6ryyBoD9ImlmG0Fk08A6NAy+u/koRhu78Tmt+3MmJnB/8Sv6SsNekRCyECrWAmCF2C3pXwQ/BCUAp+EtXqcJ04hu2hZg9O3M5qwl2LoYk5fvlRPe7aALnQJX+DB5zMEPUqkCZ+XmQ7ZY8rJtx6ttKRHW5mp1f2u+0fiCvQO6ulRDJjYiBsIhqbIBSNBRqpIqJkwerdh5lXo17p3pFo94jPtj0uqqhNBnEYZa7PUrH3DjaK4FcvHz0VUyy+CJtwEDDFPq0dVvNLUkIx7Sh1v75ROG/yD9azYKoSpE52a5SqCmYzQ6VkYnTy4qgNbCWE2LwOH5vehqGvLxVuLOK9PVN3WuuWocHxKS2sOmepEevQaFM2wM7xTFEcHBQ/fGMSetn14E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+mlNIxAaDLJ3oCGd8PclqV0WRs/lQ3e77vmKZW1GFFGr6f/MoQ97v7lfJtldjRTXB5rg6XEBOUXbuClkjkaIga5lJgUD5NG19I1DpSlNrTuausRGzZLUFI4Gm3MMAKQG7eq5oxPspv34H9CFl/CMBqpRshqtVXcZiwEjF+VlZF1DkLvNAGsvYzLw6yfCgfuC6hMPebkbX0SkFnPup8FCDd+F8bUevYa9eBhNNHtowZIWyP+8xEGuTMXQZwJF1a5E8R9tiH6ktm4KmGU2HtKUvyzLfJOne6erlozY36S4Ai7bsNmzN8MTEnPQCWfd11FRwcmUl0nCtLdLKDfIynfg8rx3K4BhePQMRZ3lcmHOvzDF2miWesCxEni7LNoP1qlvuh/E3bDrgoeQk+yvUvx4ab5+BtKjzHohgX+zjMsiyQeHF0VsyIojiMo+Fi7ORhJIyTpkRVA72UaSj8srlQD6rDU152MB2VDScoE7//BNYjK2v4EaJ+XMAEbOT0VYrdbHXlVOdtt0s5a/aBMA4bGyHU/YnewC5fT0n7RmARkXvGmeLioaECHpsEYhzSwI/hTC4i1fmL5QdVQEv4Kvn7SBY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2c3b9449-ee75-46c1-5354-08dc6892a3d3 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2024 21:23:40.4516 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 15Pzf1quirrYulUItyro3pXNab2T/9TwmFnTBdgZUII4rlZy2zLGWiKKhNHLfdUhKVI0zQftD2FjP/JdC2ye97csmqQdhFcDXmfZOAuvqS4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB7232 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_18,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 bulkscore=0 suspectscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290141 X-Proofpoint-GUID: _L__vg8NZLwAB71WAPuJ2M0Uy2_uqAkz X-Proofpoint-ORIG-GUID: _L__vg8NZLwAB71WAPuJ2M0Uy2_uqAkz X-Patchwork-Delegate: bpf@iogearbox.net Added a test for bound computation in XOR and OR when non constant values are used and both registers have bounded ranges. Signed-off-by: Cupertino Miranda Acked-by: Eduard Zingerman Cc: Yonghong Song Cc: Alexei Starovoitov Cc: David Faust Cc: Jose Marchesi Cc: Elena Zannoni Cc: Eduard Zingerman Cc: Andrii Nakryiko --- .../selftests/bpf/progs/verifier_bounds.c | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/verifier_bounds.c b/tools/testing/selftests/bpf/progs/verifier_bounds.c index 960998f16306..7d570acf23ee 100644 --- a/tools/testing/selftests/bpf/progs/verifier_bounds.c +++ b/tools/testing/selftests/bpf/progs/verifier_bounds.c @@ -885,6 +885,48 @@ l1_%=: r0 = 0; \ : __clobber_all); } +SEC("socket") +__description("bounds check for non const xor src dst") +__success __log_level(2) +__msg("5: (af) r0 ^= r6 ; R0_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=431,var_off=(0x0; 0x1af))") +__naked void non_const_xor_src_dst(void) +{ + asm volatile (" \ + call %[bpf_get_prandom_u32]; \ + r6 = r0; \ + call %[bpf_get_prandom_u32]; \ + r6 &= 0xaf; \ + r0 &= 0x1a0; \ + r0 ^= r6; \ + exit; \ +" : + : __imm(bpf_map_lookup_elem), + __imm_addr(map_hash_8b), + __imm(bpf_get_prandom_u32) + : __clobber_all); +} + +SEC("socket") +__description("bounds check for non const or src dst") +__success __log_level(2) +__msg("5: (4f) r0 |= r6 ; R0_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=431,var_off=(0x0; 0x1af))") +__naked void non_const_or_src_dst(void) +{ + asm volatile (" \ + call %[bpf_get_prandom_u32]; \ + r6 = r0; \ + call %[bpf_get_prandom_u32]; \ + r6 &= 0xaf; \ + r0 &= 0x1a0; \ + r0 |= r6; \ + exit; \ +" : + : __imm(bpf_map_lookup_elem), + __imm_addr(map_hash_8b), + __imm(bpf_get_prandom_u32) + : __clobber_all); +} + SEC("socket") __description("bounds checks after 32-bit truncation. test 1") __success __failure_unpriv __msg_unpriv("R0 leaks addr") From patchwork Mon Apr 29 21:22:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 13647754 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 7E1A51836DD for ; Mon, 29 Apr 2024 21:23:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714425835; cv=fail; b=uDyEWQnCPCOPbYpVASW5e2iRt5oDHBlIXWDZfNmFd4erwbNz4VYK/D9TaozqDsh3YV2oH1RlPSfNBV3CocPD5peG/xzKC9HDvtDKNBguMJqvS0A88PKXQVstmnKmn25okXMALQRq4O0QBXA1Kq9Ya9i0gv5RkpMILtXT/cs+EJc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714425835; c=relaxed/simple; bh=i1WEvAk5/l0Sx2OouKxQZPvr3Z3NVO/ibggQdsms8ZQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=kYV+4m5yA1AkIhqShTfEOMnvi3/FCCnPq6D3i+VWJSzaKHFlIgSw7Rqpttt5msl/QY5hv0k2kRul4Nx8WYKDtZtrqfGTw01xwOGP2qFAuYgsdjqfGJ6rfPRKDNnk8ArkGjYdFLEaDeCnazSWOnxWIGlHJ5vwGvT2HpopJKCspWs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=L1Yfk4Pg; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=IZMgFKDf; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="L1Yfk4Pg"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="IZMgFKDf" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TKFhcw015535; Mon, 29 Apr 2024 21:23:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=rUrrHaI67OFq2TQjWV/dILXIRUzE1IaaNzhCAY0THFM=; b=L1Yfk4PgFGgOncknf8gUqGYV2AE2A8xOMsDAKYTDMkKYdWWek8b9l1InoSKoXKNDT4qB nnBLWQQaAoui+TVZwVUCF3PKw1V7JkwMeuYR1DzQW7S1aFIiGAfhJwuoSUWNN1nu+62v FB5Xz6q2lkyvtfXBreL3+B9BtpbDeYHce0KmfDEf7kcbEFq447UC98lommE+eDp/GTM7 RxWvouudthOENIHObN5GekKiCK3lFcCQECHGEisW316xLzG+2NLZvC8I+gGbQJcHvTUo f6VunXeuvgOXRY0cXh3wgE2mvTpIczk8JMoWYervHLNSBVIQWltl5s5taxgh5+Lfvjql IA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrr9ckrhf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 21:23:50 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TKs2wU005034; Mon, 29 Apr 2024 21:23:49 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2170.outbound.protection.outlook.com [104.47.58.170]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6g6wn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 21:23:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zsm+zZbV1eZoX0BGkrI6HWGZiJcaRT+cHwaa6yO26B9bNxg2Mo9dD2JrpQleAEiCeyWVSVdHmJpG4qS/x+LKZ7cHGHFlAbma8BRL8gsUMDR8BjkaLdkB+wtED6WqNPMqMtbLvobgkOGqkWnUImn44N5LDKAMt5bBePvAhxYO4z6MgzsUtAy8tDnLf1syzNuqzAe7i3RaUPbzx3+YWDNVOCl07U2GAJkzzblAMbhG2/wdiFhdgjRFmxWR6P75n02otnE5L9Gi9ZH86p4fUQ755KKtjS74zx7iwQXT2rJ0ca7brQG0ZKLLyf5yQgM4DVeqCrG+y/W9H2VQsjJl8l/Epg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=rUrrHaI67OFq2TQjWV/dILXIRUzE1IaaNzhCAY0THFM=; b=VRXJ0Cwy98HfrQcZyllVM79sJlCyl0283KI0/uPxDsT5aykQslGDoj9EfiNhQvlNIqXrJPXmdJ8H4ySljyPjbpTrHfp7knTO4Rc7NuHW5Inj2+5EwfSldRKukR15J2b8aga3N4jRLECjJB/6+mkBbd61WzEwU8DWRXzHv6EEjEYOlVRfKzs/q1PjfcOH47A1eX22oKDlMz2YtociSEf6VkBpkBPZTlZ4nrD9OTPU+WNMCKPv28TauR2jCVASLPZ0gvJYfQwBCuYwOuNJfkkCFeWRXtgiw3PhBQ2rFS0luRRIDHMha0T7id8n8BJXQaQrwHtni/HdhS8l3Bx3xT0Ehg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rUrrHaI67OFq2TQjWV/dILXIRUzE1IaaNzhCAY0THFM=; b=IZMgFKDfUN1B9aWE2ayRZomei1gOfuh1FwssvDZ3nNF0uUggqT54h+XQo39l3xhh3TnKIjCdUGnP0XcmWCmEV2zmRH2rlgr6iboOxzGMH1bb8TBuJax9m3XxoROxaiOnrmzR7hz/Zw3zDPs6PFEiZI0bE5u2E7r1jA2H/y4LMEQ= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by IA0PR10MB7232.namprd10.prod.outlook.com (2603:10b6:208:406::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.35; Mon, 29 Apr 2024 21:23:45 +0000 Received: from MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c]) by MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c%4]) with mapi id 15.20.7519.030; Mon, 29 Apr 2024 21:23:45 +0000 From: Cupertino Miranda To: bpf@vger.kernel.org Cc: Cupertino Miranda , Eduard Zingerman , Andrii Nakryiko , Yonghong Song , Alexei Starovoitov , David Faust , Jose Marchesi , Elena Zannoni Subject: [PATCH bpf-next v4 5/7] bpf/verifier: relax MUL range computation check Date: Mon, 29 Apr 2024 22:22:48 +0100 Message-Id: <20240429212250.78420-6-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240429212250.78420-1-cupertino.miranda@oracle.com> References: <20240429212250.78420-1-cupertino.miranda@oracle.com> X-ClientProxiedBy: AM8P189CA0002.EURP189.PROD.OUTLOOK.COM (2603:10a6:20b:218::7) To MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB4382:EE_|IA0PR10MB7232:EE_ X-MS-Office365-Filtering-Correlation-Id: fe1889de-921c-4230-a0bb-08dc6892a70f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800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nekCwwPWM6FVdZuoeHKmqZMchjGLopjeq/gDhZimfRFhEHObg0UTQKUoT0foU0wV7D2en8hCvShy/yo508j2nZMEPpe099C0zS/KqF9UqCry6o4XRt2BeYys6j9wpdaRliaGzOp4YT3sSIrjLmqr0CJMufIK9kTcVCyq9sSMMGZxGvclrha9UDxdsYSCfgUEsA4CBzwyBmjHBUPCRkcMWo9rA6Abwh0V9KIJ2avRmWDPnbBb/i8dVv/8oNvB0mo3P7vNA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR10MB4382.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xWI8MBVvNnSXfFemERgM9qtzll1iBghtd9+3FdAlXrjsJ3HEXz4/S3PG0kMVSd43z6fSuGINiH2hnbb2eMkhOk6cYJ5PdL08TK7enRkY+iwWZeGbOq2tikJs+746fmepz29tiR7nWRALCWf+a+IJpjAw0CNNlM5Gz+Zw/zf/q5v3Xj7mngUo3AhI6p3oDIO+ZX7gVMOc+rROtV7i91x9YOvbq5lpQ/TBg5lsVgoFVPudQ+fDIi7pybukFa1QLBT38M1G+WFWYt3RPf0nXiAbL/JFVxYcC0tfOK5DWX2tUzHaVA9XdzemM505ix2gy6Itl/JYG/hUcgcfr4TiD7IPvAkz4+r99+ZxZeFahLX9lAYg+AkNlRkqfaqN4Ov9jqgVSnOBZcHR2xA6v2oXQflIf4FUKjjXI/F6W/BZJ67cB9BKdE6rrdBd6ji88R24ND9OXuFVANvDxHQceNoIHXMsFq5eHFDA3NowQBwTCPaSubkpOQxQjzLktJ+55wbhfrmSgjpjxkc1rkF4cL/s3rkzscpfYy7wNO3E3PUskUGSTCNLdY5aea4l3NQEcdLAkmX+AqwhPT7XpK687681MxCPpRlc3UhnalvYZdW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ount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: vJsxvPcyiqPScnSJ1ok71lwaDQSAuqFYm3jqgAToeTlJ5O++EKkySimfq1FIYtkbxEvPSx02OYyqC4UppvgO7Tb9BITJbqsRbp5Rbd7+BMSNobUHrqTgdjLs8awKUiFM5gdYGPUIp2J/Dd4GVCTvrFf1VS5NTSlaZU5UYfQEy7OYbyE7QpchHfGclKQOW5wRvFwG7bbVrMB845C1Z3LosTChpM+WlVF1ppSf7jeGSFJCow9ZeeSeK8ypgJxSixdLawMrOA+jnJKM4WVMbTu8ckNr+S19iH/5P5BUL57CtfOIdkPr4C09ge4kd5n3Ejb87cKSlcP4TICO8X5ZH63FYMCtHejDSG+y+t2eHCZniWPeFKH7xzIZ8E4QaIPigAlg0jtGA6+UD1FwxTo2MAmnZh32bVJ9mggr7Ck7+0rFHjTFauLdkRg7xjyff5aqHKqIItrOw4yRUKtp3YyZ1wgc1/dNHkytiihEk9dLFYYw0At2a9cu17D8GqJ3CkSzM3NGmQdBo46BUBxM5FPjFkJtqh/KiCSxEkEgBLUSFNr8vKyI2JP8bzai0wlvaW3ckpLP0HBlPalIvQfliZHH5IL0kv7kHOEfL8fLZjM1+rb03/A= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe1889de-921c-4230-a0bb-08dc6892a70f X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2024 21:23:45.8627 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: htu759adxGYFsYgu/mfMueIKmW4h0d0S3py2V7dJgIr2kQhJw1SGhXHH7NMPmQhmS/Xoeb9Ti2wu02jFXpl3uLnDxWs667WdPM+rcl7QwpM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB7232 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_18,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290141 X-Proofpoint-GUID: BMfyoPyDIipoleCBLdoyeuZsj5sNTQoR X-Proofpoint-ORIG-GUID: BMfyoPyDIipoleCBLdoyeuZsj5sNTQoR X-Patchwork-Delegate: bpf@iogearbox.net MUL instruction required that src_reg would be a known value (i.e. src_reg would be a const value). The condition in this case can be relaxed, since the range computation algorithm used in current code already supports a proper range computation for any valid range value on its operands. Signed-off-by: Cupertino Miranda Acked-by: Eduard Zingerman Acked-by: Andrii Nakryiko Cc: Yonghong Song Cc: Alexei Starovoitov Cc: David Faust Cc: Jose Marchesi Cc: Elena Zannoni Cc: Eduard Zingerman Cc: Andrii Nakryiko --- kernel/bpf/verifier.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 54aca9b377a4..b6344cead2e2 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -13746,12 +13746,8 @@ static bool is_safe_to_compute_dst_reg_range(struct bpf_insn *insn, case BPF_AND: case BPF_XOR: case BPF_OR: - return true; - - /* Compute range for the following only if the src_reg is const. - */ case BPF_MUL: - return src_is_const; + return true; /* Shift operators range is only computable if shift dimension operand * is a constant. Shifts greater than 31 or 63 are undefined. This From patchwork Mon Apr 29 21:22:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 13647755 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 AD4411836DD for ; Mon, 29 Apr 2024 21:23:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714425840; cv=fail; b=EaiadupCHb3JrYZMqLREYcrMo15xsGAEf1mVFUtnvEQH3jFCpmw3R0nr87s3kWMHuhLmI96pCx8HwP5GtATH0GyjWykMPUBaI4iXE3GSJM/ET2NuOP318zsmyXqas3hbTm/8VWE6Rt88RE9lPtiOQQZBwOHkAu4fd5lqe3Qu8Fk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714425840; c=relaxed/simple; bh=ISPL6Lg1ynMpnrXxgtitBcGsWJTgMwcCFb6xuQRBFvw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=Dxk68dZ+07nd6E1KcgSXGCYw4n4nKvfmlnqO387+Zp6vwcKORHqB0nyKOfl3UH+jzbEsHphLvhY/4Yl6T5Z1ejfSvIv+UDxm29Fh6Aac2glTnVnNXNxY4RbyqXoCtllMgYKbpNxblUTQzQ9ssW/1jx9GqOOFJN1+m/P5tkrdh1g= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=nz7KRttw; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=B/6BmsAr; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="nz7KRttw"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="B/6BmsAr" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TKFdeb013366; Mon, 29 Apr 2024 21:23:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=N1piF/u0s7OMc18qEZmRMNgXZ493eeKge3rzu1Dejxs=; b=nz7KRttwanCloYJuG4EN0Mr4wqw2nQE16ipk1GK5BdZwmJpm5aiuKvhEBJlmdzr4DEPx 9p9ZpzBL61jxgQOFotS45Jc2aCL5VyRTndmJfieQRZrPOCiCs2eUcNSd4VdFx4H4AME4 CB2Wl5zKOmmELU0rByRMAfzIjZ2Z30aTo0TK+K/2mmw7aji8TBgasQnX75bXFV0udGZc gKavmFxpG7Nxk+cTVcFVnKGrmknBR0IsHkmuzEfnL/8p4lbEeGyRCjL1i2tvAm2he4ty 4Xu12a9qebW7Uas1APH6w2ImkDGjzkDj87FNjubUH/lZIpIHfsOKIszj1zHK5zDgOzwE dQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrqy2urks-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 21:23:54 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TK3Uv1033171; Mon, 29 Apr 2024 21:23:53 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2041.outbound.protection.outlook.com [104.47.57.41]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6qyk7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 21:23:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mS/KJrkuqs3p4TkVlsDBJr6txmiyWfsjJdH07dshXiSfF5hjRdcRB5gKq59QBtjG1gUSMiOTezV9T/8uJxO5rITERmsQ9Yq84bv4xsEsTfeyhEmOcbT2XEIjfMm9kHsq3d0AKaDXJrxoI9uIcfJ5I2u/lLQghHJKL5/6Os0y+qkHbDPUF2WsnXF3JQFiOJeOWmzqD6lYdOoOc3pDnSO8h1ly12floj6qke6T/yJRtUvFF5TTys9LOsKNNpjAPcIcgWa3N5zMa3oI4taeY1dbLSA3cEy188jImPK7znA0hwGWaFsHmirSiv6d7+OMlu8qlUFi1wj1dD7Bc1vFKSblsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=N1piF/u0s7OMc18qEZmRMNgXZ493eeKge3rzu1Dejxs=; b=fAFfQETEwjq5zKfNSr/TrHcOYIYHZz9qpwALK3vqlrhV7yj9T5jbuNYm1qX7wXMln12w7rtRHSpMF5dIOin6AmHIt5YZrQo9LRjpc1+Bsb4FqqlLT476/TIp1CKOqJHrq2nmgC83cYXbGEUn86Rkvm66EqWQp8KMu5UX9hhFyiCpT0NHSjpYgNjbF+Lc2+o+lE3jz2HY8zkG+6fkhOoYdTOR0TjokFzH/cLlTY9627p3eoqepk7lYFDHrK8MstZ3M0YfWpxYNzfl/KsltQ6HTr4D74kcs5e3JrxlLLpk3qYZWO/HMIxOB+YB7Bz+r/da33t1AQfQ19O6f4877Oyu+g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N1piF/u0s7OMc18qEZmRMNgXZ493eeKge3rzu1Dejxs=; b=B/6BmsArFJQPWxxPKTQwDNsiVfm8uRf4VPoxqXMgTIgjHV1/C0+KduBKEwpNgOS53nZ+o5/5pNnaT23hI/UhCywx3Xa7fNLGN5DVh9zJt/9V8ckZPJrvVcXQ7xi5XhUO4q2V5jZwGtG/vuh/zVuFETGnahAKPf7xaF1seoW0el8= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by IA0PR10MB7232.namprd10.prod.outlook.com (2603:10b6:208:406::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.35; Mon, 29 Apr 2024 21:23:51 +0000 Received: from MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c]) by MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c%4]) with mapi id 15.20.7519.030; Mon, 29 Apr 2024 21:23:51 +0000 From: Cupertino Miranda To: bpf@vger.kernel.org Cc: Cupertino Miranda , Eduard Zingerman , Andrii Nakryiko , Yonghong Song , Alexei Starovoitov , David Faust , Jose Marchesi , Elena Zannoni Subject: [PATCH bpf-next v4 6/7] selftests/bpf: MUL range computation tests. Date: Mon, 29 Apr 2024 22:22:49 +0100 Message-Id: <20240429212250.78420-7-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240429212250.78420-1-cupertino.miranda@oracle.com> References: <20240429212250.78420-1-cupertino.miranda@oracle.com> X-ClientProxiedBy: AS4P191CA0050.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:657::26) To MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB4382:EE_|IA0PR10MB7232:EE_ X-MS-Office365-Filtering-Correlation-Id: f09fe679-030d-44d3-92eb-08dc6892aa4b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|366007; X-Microsoft-Antispam-Message-Info: jZUbgwi+UZDXWNPXz6lrWcbtjjGbxJqJ+vhbR5HFQALaBnb3260d9jQ8O9WlJXTQ38KUB64gZmFxuhUqG5sN0NUx0OxR/mI3Y1zOfb8aeByfjF2pPuyFEVSBTjhKhA8MJnPSD6xVyyWgu3O+RA14onkplkYx282yNGiI9FhbeoLQ9xNMCHUTNAoMdMmGidvxMg7E2obzCMcyDKmKACPKchBo6VBNJy27FWQy5WIMT08Cpcz1wlL8tH9iuVzCEb1hxp6pqHgrmxgYFj+/CyppVBVtdoR/4QsOYdfxFpcVZASmAzWgikD00pGDXOKr99MpRNBy+ONYOQpCeyW5xItm3Ej6buhTD5tjSDAO+FpRrKZP8VNjG6HYNcFrGeOuktGqXt13qJdq6+Km0+5i+93/oIkZ98yGIfHI4062eX67Q0W5/aR5QL/CuBchYJkADDUMv55Lcwsfm98IyVn0JP5cJ7LCW/Gk4sXXACSyOLQebcXv1MzxwRR1cWoC71hK00nz5n9e+bRIEEAndXxDzbngmQXDaqr1zqxq3dK+xkoRZkonyGk1YfXl2YXV1TAMpnAYq8eny3O5GQ+uohc2gOMcxJrPbnPe8BUJrnpjcSoCCVObA53jT7nBL9BGhK97Egc7eBZunWI8nt3mVMt23/9yv3cf773iDKnek5GPNWQ9cYzC4blntp4mIhG5ylMbDX/Ik/isD6VImMoq3gCvcocRPORtuV/+SJEL3L43Dr9L6BsFVmB19nUeiWvV8v+6NVRQe1tZYLfyvwwsHYTjtfdgqJutAeER2xOtSXFIleAC1/89W5XWErN7jkx0iKUJ8nj0DBkOcGrE80yNqvEMyFZCki7JbCfBrykqdhEjdAcWyr0A46xvZogKuXRDpchcDG4QU/MaUzBTx9VjQaTUfJ+k8dXWAXZ1H/jPUjabef+wSmNTJ7aG7QL8Vhhz6qd5FC3eot120qcSeydcQQ9R0iOYiIG+DXqBt/msmE0APSsXJrQjF36KdnWzPnnKQd6G4v9vage2LpswGWCtyPW6WOjwM0Ytx1LPmu0y9EKIYeuzFy3IHIBBQXaaQUB1/sR2BOU5Z0A3UL6MYSfpJaxmDUJIEumQfTeQuDfOLugyJLfZmCMFCpiZbHiq0xdI5zUH+6/aJPIr+/lcdceD8J2G8YChVsk2dA76ClohshTu0Lp4qw1gGJCAlZOxv/0Y3lCfpQy1JZakMWxc95SslnAVqeM95il3f0IVRl+6SjIvqa6Dv6LJOo8KN7ABP5o7rUisRf3TeBAIhXuvHPleuGZ9NdQhMw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR10MB4382.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: A3HOgPtVKED4Unze0wrWsh6MW/MAPhgBtD6bLsG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/J7dHJmfd7DRreKSf97WUxiQlypy0RE9HGOuOIGSDVFTh8uj0gTgdShilh2vZPF7JFle6uQl+/senZ/PCFWz1DOc4qo8uH0qWZyk+CkLS+VTPGHt803/FddvHV18isofr2KNyFwzByoBlJ93bBLRa4ZMH1NKKTViRFkgGNKHFg4G7o0C5QYDm9NjjnkxZvdJL3sHUWSKid9qFWleiIHC6yxMjf84JOlKCmefmByT0fLF3fx8/scrIKJMM9uf0st9R1QQubgc8UHPqMJKFr8jDWtY8fEl31XAy2wZ1Utc6B8VCj9V2CCOOi2lZEu2US7+Oz+Dk5rkyDiLlbcfvFqMexoJx9TJ/G5mMtR02UsC4jJ4DETxXboSCbhkzIfPG1Q4zcAvL7nGQK8h4hXYP8mD2WC13laxC5+T03AmOEd2gUd4hDv4S43kXgp4vz/12II2mjocIAE7qEDeWJNKyxt/hKIdDttEKCvy3zRenQFYNq3pTQOGREX5zleejuXhaitLFmoFNk= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Aa6fP2G/bPRTL2Am85s3czL/aZMNKVL5gwpw+XlMa2Ch0gBVmPqH5W0ArldDYzVoxneF6MwDXl2U6LjuVhN7bros4CDBYkSEcAMq92BT8lWUsZ9etC5mItFFOCjKeCVtqGKMQwWcS/r1ub16jsoWG40Nol0ru/0aHvc3znzksfd+ihNo+zamk/2OrIvFj70ixS3jOTK9rh+uLlYvdi9Dg68oB/BwQLYx2pHCp4Dji2uLEjKrIPuMne+eNOx5/iT4g14ZCPLbRRZc1bA7J+Cemn0ZX/4p2k3rB7Cmzs4FQnfzFqQV8iDavOMg1LgGG/1050qSSFlBjjOKI1PDhtGWemUjRue93s6+CuaHEOg4Bdbzaa9IpZJwQ910TvWWbsX3EojrvYkt/YvthWupiKvXaplWbS7C9ZXUodnh9TwP/+7tLNno3jzfBbGhyEDTobNN7ZqIJhP1TahFGRiDSSjyakSztSUFWPIeDLUcPouMcVlhq2x5oheK0LcDHby7ehsx1EknPo/tlvJqWUKbYZ4H7bSpviETNnqrVIt3mMEh2QmcGoqZaJ2dDgAbjrem6K3iZbZjfwDFWmWpi199suCoN7b1SRyz9YqE9NvjWycrSE0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f09fe679-030d-44d3-92eb-08dc6892aa4b X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2024 21:23:51.3027 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: OK7/7iLVpcRyNPMQ8GBQWczPB9TLVwn9j5pvgb2+xR0musgcrw99cnoXMdrIPzeX6KjoVhBDkpXS13hHXCdoGxWzP5C/zu8SE9UldHEe5s8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB7232 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_18,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 bulkscore=0 suspectscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290141 X-Proofpoint-ORIG-GUID: LAt9vYmWaNkUyIcGADmgMOxMW7WsDtii X-Proofpoint-GUID: LAt9vYmWaNkUyIcGADmgMOxMW7WsDtii X-Patchwork-Delegate: bpf@iogearbox.net Added a test for bound computation in MUL when non constant values are used and both registers have bounded ranges. Signed-off-by: Cupertino Miranda Acked-by: Eduard Zingerman Acked-by: Andrii Nakryiko Cc: Yonghong Song Cc: Alexei Starovoitov Cc: David Faust Cc: Jose Marchesi Cc: Elena Zannoni Cc: Eduard Zingerman Cc: Andrii Nakryiko --- .../selftests/bpf/progs/verifier_bounds.c | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/verifier_bounds.c b/tools/testing/selftests/bpf/progs/verifier_bounds.c index 7d570acf23ee..a0bb7fb40ea5 100644 --- a/tools/testing/selftests/bpf/progs/verifier_bounds.c +++ b/tools/testing/selftests/bpf/progs/verifier_bounds.c @@ -927,6 +927,27 @@ __naked void non_const_or_src_dst(void) : __clobber_all); } +SEC("socket") +__description("bounds check for non const mul regs") +__success __log_level(2) +__msg("5: (2f) r0 *= r6 ; R0_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=3825,var_off=(0x0; 0xfff))") +__naked void non_const_mul_regs(void) +{ + asm volatile (" \ + call %[bpf_get_prandom_u32]; \ + r6 = r0; \ + call %[bpf_get_prandom_u32]; \ + r6 &= 0xff; \ + r0 &= 0x0f; \ + r0 *= r6; \ + exit; \ +" : + : __imm(bpf_map_lookup_elem), + __imm_addr(map_hash_8b), + __imm(bpf_get_prandom_u32) + : __clobber_all); +} + SEC("socket") __description("bounds checks after 32-bit truncation. test 1") __success __failure_unpriv __msg_unpriv("R0 leaks addr") From patchwork Mon Apr 29 21:22:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 13647756 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 235BC1836C6 for ; Mon, 29 Apr 2024 21:24:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714425848; cv=fail; b=nFQ2vUECKrWuqqO1CXs0C1GluVaR300DkBITYHZhkrSzhXnEPtHfnOZNpymgiiYKT/oNpj6LDSNbFforkofKTeW3JxbAn5u0GWx5rVUVzokRF7tMV3FlRKKhwpHRKR9X77JqtYegROAu+6BVNA4n7+3hqwA9zss4PjaBrXkYUVU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714425848; c=relaxed/simple; bh=JKnYiEtRXy1wag8ftwtZ76Lj7M+XW1EeiAfnnrxopcA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=OMLwXHNateJWa19JxEYsDS5a+AeMJvmHsvnzBJ/fu/z/1pGUq+/NCeUA4vsBHVaCCnQiU4+qaG6CF/UUbh+xDdsLd8skdSE8rVuE0Os9jGtzEG5tSepsmrFu+hM2qiveIRlu9TMxGnDEMwAtxByiYUSrtMLdgFFG8b2IqomSr/M= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=g+5BjEG3; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=KP7VeF6i; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="g+5BjEG3"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="KP7VeF6i" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TKFdEM013364; Mon, 29 Apr 2024 21:24:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=SuMwQEFkgktoVleGnGBAQfF4beb2ozr9tuvdmo4lz8g=; b=g+5BjEG3JQvxeQ8OlHsVygQVSuwBBgqnYpoNh8iTLS/IJevnGEyhHs36QCHkTB2DBw2Z XXfkiAC67vtRX1EHETxjocxHbsYwjRQmrLz3BajP/3zP6YWMSORzaYfvg4NYO4+I/pH/ dLz5MCdfz1/pGHqblWsdmzTLMed6eUpouKwQQb6myAF4dTe4rXFUzrxpVALH0vECgULF 8ZjG4XKVzAErfjAi/c47pQ6c1qKYHF8HO0xXOIkkfI8SB6tb+j/vd0P38n+bto/a4356 PnPpxtlpQsX7SiR6iswXQZsLxMleWXVWH/0NdBfCcqbHgf4CENdKStTq7qEnOnrLIrYZ mw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrqy2urm4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 21:24:01 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TJwqst016741; Mon, 29 Apr 2024 21:24:00 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2100.outbound.protection.outlook.com [104.47.55.100]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqtcyuwu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 21:24:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W44/MJPRKXDA74DrUvUDg9IHK7we+g8WdAr2Zh1UvFys+I+6O/xKCC6rnEF1yPhcTzh3IK0hIqcNK0dJ+qu8hf9gZHspuauCTctAJlj9tUaSAhcfr3czH/N8Y0QG7vbX4yksw1uoaH2YzMTxQ795WaW3lJCsNpVxaHAURQP8Zw6pDSSUEJyJpv5VA/flIh+Tnc76477aO4Y8a2mQ7KHDZepc2Gu8ZT+TTXRz0edDmfM26sdQOhRiHnMrrlIsiabnKO4gJq0taxFnfCXAKQMpVxB3uYs4SVidba6nDzo2BlIeWRoDMYjmGgnVEDvTkB++o8irNq8H33LYmRRGe8GAxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SuMwQEFkgktoVleGnGBAQfF4beb2ozr9tuvdmo4lz8g=; b=ZR49UTQIT/jkTUG3IhsLJ2maQCtlJguXKCyWtq9aQjY3oKds1jm1hdNVy7KqwbDnRWW6t7rBJNd2jVRBXhboj3Gd+1U+yTOBxtsS8xVyG+5VUyh8WROhkdBXyUmqLlaOjvh2NIUcTQyxrihl32PfSiUoQ80RWH+n/46Q8eidijLQpJUji/ZheXeANOkfTW+XSCeXSlYonrN4B5KfGMjV8KGyyuaxo/5XA/Um2ECp7v6CEPsxWjcUbw6GKQKX/G+BySDTqeuD5mJeGfcRZgxhiu4a0XNWZNs8ZnFG8X+rHDW1KS6HkViL9/WMEGAuclsmEHeEoyUaUZgi98/puwdFIQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SuMwQEFkgktoVleGnGBAQfF4beb2ozr9tuvdmo4lz8g=; b=KP7VeF6ijRo+6XTOVQdgVyC4aymVhfwLcx+/PYmADs6saAA95ZPvtDOwbkIuzOh7VYIDgQdVHzcJLqW+QybcgRj9Nd6mSRqY3eljbmsihnSQTp7SaFEIwgRhJC86RZwhvWL8QVvE91JNOam8ZQqCiaNlIRCDnvYZI4Zc8TtOzN4= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by DM4PR10MB6864.namprd10.prod.outlook.com (2603:10b6:8:103::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.35; Mon, 29 Apr 2024 21:23:57 +0000 Received: from MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c]) by MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c%4]) with mapi id 15.20.7519.030; Mon, 29 Apr 2024 21:23:57 +0000 From: Cupertino Miranda To: bpf@vger.kernel.org Cc: Cupertino Miranda , Yonghong Song , Alexei Starovoitov , David Faust , Jose Marchesi , Elena Zannoni , Andrii Nakryiko , Eduard Zingerman Subject: [PATCH bpf-next v4 7/7] bpf/verifier: improve code after range computation recent changes. Date: Mon, 29 Apr 2024 22:22:50 +0100 Message-Id: <20240429212250.78420-8-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240429212250.78420-1-cupertino.miranda@oracle.com> References: <20240429212250.78420-1-cupertino.miranda@oracle.com> X-ClientProxiedBy: AS4P251CA0007.EURP251.PROD.OUTLOOK.COM (2603:10a6:20b:5d2::11) To MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB4382:EE_|DM4PR10MB6864:EE_ X-MS-Office365-Filtering-Correlation-Id: 4d29b180-56df-4e90-d27d-08dc6892ada9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|1800799015|366007; X-Microsoft-Antispam-Message-Info: s1816jFXnxwJS2J4mN/BVbTg1qbOOfOQsnqjQsGFeuQkPgn7XYH5xKrgctk6Yw4fTZiMojH9TM1OSNQH/Q/PQ8yHxncPBSTgDkpLTp1R5DR+l8FLrMJV+ySA8OcSJl0tNWE+jIRFlu78MwDxjYor2nUSI2Pv7ovegEyZA8V2TeYZoa/q67QtOvXINvAf/7+/+IV4K4mLY+o0TO1NGLuDe7CnpQticgN5JigcNfODL30tnUcn5gt1D3Wm+s3P97VmDDL52sRn+9Qk7JD3+Ly0yhd0jOCT2tvGa8mCeijlhhr4UhKlioJ8gghuxZLMrkeQkvx4rWETUtfqCskCtBDV9JI7N0zJX+GZR8JwNglDdaZJB80Z+vgrbLl/X9jsmwMPXzp1m8t8QCIvdMr5elamL/tDRS3WZHHa6IgPMesCyj6GrjQyapEaakvgpXg8jgi5poZdbC81KWIgFGqStb8Kjasxyk8H4qvjN86nh/mwTCMuArOXPNG6Q/bOGJi96Cm8OjCPpGZeiUdIa0UhXospHnmadZt0KK8DGVyQnN+tIzck7VHPO+NeeYVEWVsOGVUdy5QP205VT7l1NN3T838Ue4jNaxRseBSXHNJi0a8HnkWX0HuKM/1qVUyasY5Z8kcoyo0gErYHv9G6FtYMJMirXSB/5sRNyliViL7sF/YYNgroplyB9kW9rZep2N5navQ9OJJS2wmAow2EF4UgUBJleBjY4ZUR9mkz9w24nsZkBv5WMQBzn032DSTsfGV5nvgRf5xmNrRi1jCNg7kEf4dtEJyz8QpLNA1wZ3NzfsefqYfBrtV3OUbl6mQKWH3D+lnWFSKQwiNCy8CeXvRZpfgW4eDIFWEmFFIrgw8hvvKiHUavo7Bbot12ieI8IkJepqAn5uspU0pVbhasq6fICBB2ebeHRpMLDpCJqeBGwE+ROrD7BXFS3MlLNqJOfppfQ+DPht2SISbE3arSaY5Upg4dVMoNeavbvwrPpfWiuLlbaRjgrXULm1Jp+EOb6fIVRoHKeVH+WCnyWjOSORPP33tlF1yUMywTXMPixzS4uopqid5eM5gwt+454mXEo3Aan0Rvn9gaVSaxCdAz36LNzDNmWE3QEQv79+MwW7PzJMegF65YGxfqWBv5BIY6mADSVnvo6hS+Z86+M0AZ9rBi4b6ljWL2Jz7dQ8EtIj7oI7o+yFc/8fgOWs5rx2pi2X3A6YsXLV93/j5Cdpo9KvyFbrVdBVbBCgY6tB5IqIu9vxGRAKzibjNVVvYEHrdjP1+QU0VAaC9vQqYeJ7wK4cQLnvQ3+Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR10MB4382.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(1800799015)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cyd4iaqBNjVWYR7Q6Eidec6G152pmc+H+Ay6zF+N499iwPgD037Je0blotlsa5JyGqhBXQfWMowQxG0h/N8V3z3deXZLxNUH9WN737r0AHcespfVXVAUIZPGyNvtXdJbQr1O0j3M1WZjqcO5vWuz+0+nVn+JBrPT5zli4/6gTkpZepzG37Hh3Ec/Q0kGZXNFKL9zblUqAiGsWuYUU4f4S4K23g/MgW1jz8BXUtvulvrzZJqzaO4kyrvtmFNUsj8uTnOfYYutYVCIoOc9nvlbVEL5fy1fB7RubqZSXzbf/KILcbe4LCE/SSs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xa9OKehbpQ4j1eSp3TUDdzL+OIk6emMLOktvltXMvyNzc9JDtV5oNwernFt0nwSU1fYwVSGsDa7ZTLQn439U4zzv3CLhNUPY9vZO2N5pLbDvdiwt5lAVT3aYatDIc74ur+elqt+EoC/NBtfyhTUrGaq1BS8yGurRXn/6+bfD06adGJJxcQQa8xoeFOzWSn3UM8Dj+VZB2xrN/Fkd0I31YrjWgZ1G+rVuyfYkkak2lfM1wpMt9PkPBmJ/9HqDjOKxMM= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 2Si7uk2qmroETYl9HnswfIwLwAu6s/IkNeY5tfVPXAINDMmH/OObKJO7wwmZ6TleUuoLdb0hny1zyHrMZ86wOMR8f+tLWivw+JrNTFJK4i9/6fHrRaZLKBagrAz0MDk2HsSDTWmLaoP3cJ6ujSv3/OgnXXQM1p4sQXcHSTgRlsMlLlr9PbiCWpNIfAheDVylDTNqRhYwDR7xI0eqcA87peqmYO6qUbX+d7fsPDlF8OO+cTnKDv6PxrWQph4CtIJYaNKb+K7lE3aKWUTk9h1ZXrJVCNeDJAdRzYcu7ZayNvK/ewyehwyxHePAkx2/jLrj5kDwzTtH22e1EQIpInLsYI7Mcb7zu6oDfluldSOUOrjeTVqnEDL+iew0r9pMnj0wTbdo4RGZc6CsLUu142gSuiio6PbLn22p24UEhP4cSKxOJX34zAD8dXcU1qZN7fD/a6HtpwXbmnq7hPOSeBgxlJXB2SJQ0RdVqItq/swn4YSBuQ5GT9TYiqTmMMMPQF0IbLy5vKCVXt0lub8I6hqb7jfLex/tPX8+xlFATKtQdg7r1tnfqi8H6W8pEnwgBXbAI/cZJTq/YnF7BLBwlfg7ogPNKA4H/FXWiPnFSwPRzdY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4d29b180-56df-4e90-d27d-08dc6892ada9 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2024 21:23:56.9983 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4iLsa1lso4KvoZUsDkH+SbmzbX2pyW5DOY0XJsqVHxaNFdSo7FKF6Zt4N0jeOqzViQY8YqRPwO/RL90haH7dd+mtSolXo/dUORBxCIf7sCI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR10MB6864 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_18,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 phishscore=0 spamscore=0 bulkscore=0 suspectscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290141 X-Proofpoint-ORIG-GUID: dxKpD6EfpWog1UTIIlSXlXTpILrkFrF3 X-Proofpoint-GUID: dxKpD6EfpWog1UTIIlSXlXTpILrkFrF3 X-Patchwork-Delegate: bpf@iogearbox.net Recent changes in range computation had simplified code making some checks unnecessary. This patch improves the code taking in consideration those changes. Signed-off-by: Cupertino Miranda Cc: Yonghong Song Cc: Alexei Starovoitov Cc: David Faust Cc: Jose Marchesi Cc: Elena Zannoni Cc: Andrii Nakryiko Cc: Eduard Zingerman Acked-by: Eduard Zingerman --- kernel/bpf/verifier.c | 42 ++++++++++-------------------------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index b6344cead2e2..a6fd10b119ba 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -13695,33 +13695,19 @@ static void scalar_min_max_arsh(struct bpf_reg_state *dst_reg, __update_reg_bounds(dst_reg); } -static bool is_const_reg_and_valid(const struct bpf_reg_state *reg, bool alu32, - bool *valid) -{ - s64 smin_val = reg->smin_value; - s64 smax_val = reg->smax_value; - u64 umin_val = reg->umin_value; - u64 umax_val = reg->umax_value; - s32 s32_min_val = reg->s32_min_value; - s32 s32_max_val = reg->s32_max_value; - u32 u32_min_val = reg->u32_min_value; - u32 u32_max_val = reg->u32_max_value; - bool is_const = alu32 ? tnum_subreg_is_const(reg->var_off) : - tnum_is_const(reg->var_off); - +static bool is_valid_const_reg(const struct bpf_reg_state *reg, bool alu32) +{ if (alu32) { - if ((is_const && - (s32_min_val != s32_max_val || u32_min_val != u32_max_val)) || - s32_min_val > s32_max_val || u32_min_val > u32_max_val) - *valid = false; + if (tnum_subreg_is_const(reg->var_off)) + return reg->s32_min_value == reg->s32_max_value && + reg->u32_min_value == reg->u32_max_value; } else { - if ((is_const && - (smin_val != smax_val || umin_val != umax_val)) || - smin_val > smax_val || umin_val > umax_val) - *valid = false; + if (tnum_is_const(reg->var_off)) + return reg->smin_value == reg->smax_value && + reg->umin_value == reg->umax_value; } - return is_const; + return false; } static bool is_safe_to_compute_dst_reg_range(struct bpf_insn *insn, @@ -13729,16 +13715,8 @@ static bool is_safe_to_compute_dst_reg_range(struct bpf_insn *insn, { bool src_is_const; u64 insn_bitness = (BPF_CLASS(insn->code) == BPF_ALU64) ? 64 : 32; - bool valid_const = true; - src_is_const = is_const_reg_and_valid(src_reg, insn_bitness == 32, - &valid_const); - - /* Taint dst register if offset had invalid bounds - * derived from e.g. dead branches. - */ - if (valid_const == false) - return false; + src_is_const = is_valid_const_reg(src_reg, insn_bitness == 32); switch (BPF_OP(insn->code)) { case BPF_ADD: