From patchwork Wed Apr 17 12:23:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 13633261 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 BAB6713CF87 for ; Wed, 17 Apr 2024 12:24: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=1713356689; cv=fail; b=jbcRPDrGUsgDdCpRyuJTQ+69u1e+aJ9Hy3YUE3qAgEgUEB3jq3lWMH+Rnj5XCvS5DX+B5wGPo1qSU8LeSn3rctG8dIcebJtXoXmC4UWhLS26MpuJMSrfhsx87oAVK6mWr4zPeBmWaWGWQSdpOBVOVWmfbKfBXnpsv1D4QfoPH7Y= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713356689; c=relaxed/simple; bh=sqS6NlN3urOpe1HS8o9m+Eo9bfXMDLhcHcXCK+hY8g4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=kXE0I96YJ63Ir31Xvw9o0ip0vGAMrpy5JT51Hsp225GQYidtAJhntAyTUWU8PsbJwKhA2pwpRNBcHGOvFUzcUZE3DD0dKGqZnQ3MpmQvnyBn80KFZ+H6nk0C77q1amDPHXkB4TiZTcEeEtC7I0QBfuk5NiHS/V3UGakRkqr9rY0= 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=Lz9xqoRx; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=pSVKj4tk; 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="Lz9xqoRx"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="pSVKj4tk" Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43H8xP1A012466; Wed, 17 Apr 2024 12:24: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=7hvYT3YFKQ+wZz/3hnHgcWUambsRF6MDudWjPxNwMBo=; b=Lz9xqoRxL7FaoqDmfER6wbw6ekVrMFrVbNSIXmIEyCTx/QgND519aZ3g4ZyVEbJ5EiHB tit7SLqxe/ADhqNuUA+eWMa5Y++Z8zcdwZiwsxDseBbzPIoU7mTxh5La1Su0AN/ZDrmY yPtLripGwBFZLn76XGlNrlCE2SyARQaikhUabQXuRyA854sYN+ikLfi/9CQ0yNOUr8ja 0hNTQF4XBlg1pRL6ZoIyYW8M/MLw/dQXt9bWQ6gin8YNY+whea8x6wFFnmqnEfFAas/6 3ucMKnfyR+e0b90BTQ7UX8AYNoval/Vtb0EH1vXmsbv7xxbC5yqXg/iibG7Is0H/aYXJ 8A== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xfhxbqkbq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Apr 2024 12:24:43 +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 43HCMK65028673; Wed, 17 Apr 2024 12:24:42 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2168.outbound.protection.outlook.com [104.47.55.168]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xfgg8qp0d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Apr 2024 12:24:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O8L8/mipU8bGOBEugmnk43uxcxyVCg23NhYzWvtlZ25VOSjVFbuiis1QB+QP3LC+MtJz94td2p+coXVbjpo10xYNtrwFej2noFrqDOfOSHjzSgaXN1LerYVcF3wxSJZSA7ObrbFlJT8A7nmD2uvu4CqjWfULjNzSpcx9tmHKNcAlXqsqXa3Gy++cSQJcvIvKF6ys/Pe5ASFmpPHOI0m+74+g2YRILX8V1NBuOQXHkaLphCvT5joeqp0hr80c2/XfGyfnM1JTNeNwtwvkfItiwpaRtBxH3PIMYBu4OePmAH7zLLGPQRniNB1yyPpzHMGL1fymASq6OMM9aZKuMsvIrQ== 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=7hvYT3YFKQ+wZz/3hnHgcWUambsRF6MDudWjPxNwMBo=; b=PAaVhnzvYOlXGeuF5QbETj7/ymlw3FF4PrIWbCzdsfvrFbfrqelZcRGXHpzO2dPFZi12ZcKnMD/l8/uwnLumG7ZeHR8lV/JQFy5eGxSdLhzRF4qVtPnZKNcKjaB7/UJDf/6w1K4UiVj/KFdE90BpJMYh1LCXs5Xw0VPSVNLwdCzMzKvGehMsrK6EXtaihp/KJ9C7aQjcAlEwr8NC7+0i4quzp2gvakrUKQW/pAcKvqnLaYau81IbKCDp9TZLgHOP56TV8w7A8SOfPrP+pgPSpRJ2G9ceufBJrHZ2OT9JGvtP+4KGdMWJHlOzBlq9yxoJZ0AWBAb37M15GxUfOY9ifw== 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=7hvYT3YFKQ+wZz/3hnHgcWUambsRF6MDudWjPxNwMBo=; b=pSVKj4tkXGDdtQ5HehCY5milPYUK4lxmPceHwFZ3beJcsYPP07dj6P6SnDhxg6SS9u03VCqftLZ16DIawoI6voCpjWBLyIcNt8EmJeR0YfYaK7stcanGFZ/GaWJA01iIux6g8DZj1ustKfoU2jBKDUl9Hs01g6+JnnrmgX2UY8k= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by SA2PR10MB4745.namprd10.prod.outlook.com (2603:10b6:806:11b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.37; Wed, 17 Apr 2024 12:24: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.7472.037; Wed, 17 Apr 2024 12:24:40 +0000 From: Cupertino Miranda To: bpf@vger.kernel.org Cc: Cupertino Miranda , Yonghong Song , Alexei Starovoitov , David Faust , Elena Zannoni Subject: [PATCH bpf-next v2 1/5] bpf/verifier: refactor checks for range computation Date: Wed, 17 Apr 2024 13:23:37 +0100 Message-Id: <20240417122341.331524-2-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240417122341.331524-1-cupertino.miranda@oracle.com> References: <20240417122341.331524-1-cupertino.miranda@oracle.com> X-ClientProxiedBy: LO4P123CA0558.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:33b::14) 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_|SA2PR10MB4745:EE_ X-MS-Office365-Filtering-Correlation-Id: 95043995-4426-4a16-0aca-08dc5ed95a9e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IuM6djIcX1Nu60pRUVtzdWUnW+Dr658Jqa9+RmE7bLSyV3sYbXXWqPEE6AXkvQROUf288g78MNQczF/1pPPxDeEvQhngWP9ce+9BjbXvPR8ZMgI8412Bz7+m36ntEZ91qn+uKZBuVqDG9QAJVIfXbEajMUo2oFcxbUg/m7vZWNVHOZ/3vQwgQBmfiKZxgKfqvnJXI7zABSPDIkCNDNFvi6wA3Sk8zVm+3XCYDtNPWHNDeGS8MwZn1lNMM/QnoZhGvngRQFO0vx/adYWTcUNW1HECmuItCmEj1b8QptMK1BdwMa6CJCbcGis33h0yLGdUBikyYosD2zOoMl7YFsss/h/6MQFIvLvJnBmswIL/Ml6WlszwIMtlk5WsZ9ThiE+vSqh7nh+zBdAFvzCeyTHL73w6Q6O82ji/mUMcKKNUe5zPux8IqTiNPIutoubhNoQAgPtSeJN6tIMb2+54Dp+/ARyGVNFEf1CppHxaTpWZ4kRe517BZEU4wMZUoBSfH8w33pKzDpa/xpwuBtZb/RP6xTdR92f+qf5NIAvl0sDnzSyjAWi+CUJfLoTriswIDAsMH8WSobLW3kp7NWJVrSQZQ24mJeV3pIIiUwBG/sVvAhplB4HUaewbEnDjncKB/NmY8wkbgxQSxv40oANwt7VuLJ++o92eeeT5khiExNw+DbE= 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)(366007)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: teyETVYf5oLTCRPD59WS6q2yj8zAoD+tjIFjXlbUjw5C+GA2N4CaDKe21bvyuLALtare6dK0KJlWlsf66z69GDrLt6+hjzOq7HxeNdKXO8lhDbHnvI21ZVXYRxSYPxQd+Mi6bM+MsI22+TVjpdCatibHgQN56FiB9YXiaEWndY3sDBRgg96ixwpEoI8qMdeV70vo1rfRFuKBzS1GTCKzAIDaXS2dmc3MSvLZvsxXcJoHK/vZEPLb7hEi1AsEuTsi6IxH187AumvENM7xldRawlMrktqgeI/gQaKok/Gky8PIrimj5Ztw0+8Btf8Lmz+SlaUa/KeeLZKrvWQbbeYL9ZM2RV9k8jj3JLe+pTKqtZ6sLaCoUDioIZvAgENel1L0yZ807WMO4zZgI2Q/Xnk/O/C5JmzY587TwnDzuv/QsKfUWsnXbHjf8O3eqZNpYvXZEuNj+uHEELmsNzbXkf6RR1rBPwOT3kvU/+QbU/xAprTpj4gfIpYkU4GiF3UAHHjClZvNws861a1qMZGBlpUw/56XUDNuOFCXdnL85r38eb78fbIrRgf0qxNTbaPi57eeYc2dLIkVyk52mQQNH9Fs3wUDSFVKj31yhGmbNKjprO33wzqptDWWWgPdUZgHmefOE4U8U2P3XIQ611mh1C+x3plrbyiAaVzPSAkXAqTYMi2lSmsOiC1CAUjnxY4KJdnV8GmGY/3Tojp5YbzbUQjBtbreHHKBuR2OvbxhUjU+zqnT4g7VjkHmLoufWFhBEF9xlF9jLsiSLWOYbn276mCPmeGoxydfNNocxr8OgFDHUpNnQoWGg792G4xXbNjbo1wzOXorxJFq6JP9lsQrqDXPe0E+nRItQZf2qicOFyRxVZyeX4f4z/41RXuoNCIyCzMd1M7anZ7qj73UYk39YWpvupuPrstqxGNUQpql8WF84fGvmLzlwfP9ozAl/U1nl+MGunjdPO2C4uisPl9ryGJcASiI31PnRntA8J7ppx9L9fA1lgUFpasmIp/gHf+qjvCyi0G5a26BihPYy0glKrkTb0j8P/HFrtXv4PfBPv+yKGC5HD+s5Z9QxhhvXXlKm+WXWSpk3KSJNFuah82vqfua2i0oAlQGS4VquBtY9YGu06oLff4SCSGLG2pELaOaJlWM9UZgXjZQO80qSrf6Tmh66t+6N+VsAOZ1CVwOqikKniF/q8lG5hTn1/zrfssQA9R7lmST533Dg5KeYFJxY8TXhNnzMPBRWI5bZ46nDrOW3lRF1yS3mTrsgvILn/5qUux7HmgHb5zRFF3cKs+MXadF9bIL1bhaoxTKyGkbxovgmwCRjNFNifcuPWcGfB0+7X+xaJnPZlvzD6IS7/nq6kY3JiOGF9royt5XVAX0cct2Z815WuqTKih2TjTD1rXSc6Uscn2Vxwg/weLhXcCj6mpjh15zGgWhbKKp0ByKVlJIEkLYiFRy2GgVNRcpO34estXAB3TOxq0hM1solBXzhs7aqDchV9B1ioVRAHnInNxHfPUUR1OXv4QFHK1prZr1XZiN52fvOQtg5iJ8g5YlWb4uZPs9NNlU/XeilKNCnctcohdl4nL3hrL55pAP4AIEGzUlkrxwjp/ndSLDkyx5flvDeWn1mB/4iD5dECcsg71WLqk= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: wPh54I0JfizaYw51REBYvlNUM0+nbj44bauhoaBuiC8ipCASjGTBGPf+KrvaftIuw6X4onhtojzknNFCsKZCo3I0gZ8mloDagNp/MCvNIQsPi09t1za2ilSqoC9CpkHxY5o2cj3MMnHwNfTrRzdGPwDMq15LW93hcSNo384ChZ8Rx6LkoBudOz7sVDMANX+QSifztrct1qZ88odSCSU59WhPjRuAEQcTlcUS1Xx2YDd6C7rfh9ppc4HoG4UT2o/k0emEXkOqMe9dlMYZLDfrSJcLGYhb4ja9OOcIQ2S+QEGFGiInpKwqGpGDrobTUgcmmn6/yxgH7LqVKXDqqhmpxZNNv3ZGUmiyOuD45CpAusERTqfJpdmQFXQYeXiVnG6tVs/0HQiPR56C5UawEz7TXdkC8kLrZhECpYV+/OJRAeI+VCsR9pxM1gRyKG+7H7pv8IxXBxqgfQWYCQaEHo+/F/oIhB+GpOIqb2Wr0VPhas1QvaZiYOi59BtMwYqUnb+oFrXFGIvse9eC0VhuYOAFOu3ObPYiB5qK34PczrjalUsUvzJJvDpdymqSxd+qWo/yptyqKANLjR8DFpjwGK736iEFhbD7Ym+Z/y6LSsddUXc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 95043995-4426-4a16-0aca-08dc5ed95a9e X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2024 12:24:40.2478 (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: tPnq8boOS6Jlm4i2livRPG3+7n4rNcAYYTMu5PwYe/47VfPpCNz07j/8Oqhwu2uXIeM0c7OVJos2krx+rU4TAWlFZbL5P96k9S2M55aUCEg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4745 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-17_09,2024-04-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404170085 X-Proofpoint-ORIG-GUID: Nr9LZZOobUAqbWTkvoQLO7LN6bz_5yqq X-Proofpoint-GUID: Nr9LZZOobUAqbWTkvoQLO7LN6bz_5yqq 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 Cc: Yonghong Song Cc: Alexei Starovoitov Cc: David Faust Cc: Jose Marchesi --- kernel/bpf/verifier.c | 155 +++++++++++++++++++++++++----------------- 1 file changed, 92 insertions(+), 63 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 8e7b6072e3f4..0aa6580af7a2 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -13395,6 +13395,90 @@ static void scalar_min_max_arsh(struct bpf_reg_state *dst_reg, __update_reg_bounds(dst_reg); } +static bool is_const_reg_and_valid(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 known = alu32 ? tnum_subreg_is_const(reg.var_off) : + tnum_is_const(reg.var_off); + + if (alu32) { + if ((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) + *valid = false; + } else { + if ((known && + (smin_val != smax_val || umin_val != umax_val)) || + smin_val > smax_val || umin_val > umax_val) + *valid = false; + } + + return known; +} + +enum { + COMPUTABLE_RANGE = 1, + UNCOMPUTABLE_RANGE = 0, + UNDEFINED_BEHAVIOUR = -1, +}; + +static int is_safe_to_compute_dst_reg_range(struct bpf_insn *insn, + struct bpf_reg_state src_reg) +{ + bool src_known; + u64 insn_bitness = (BPF_CLASS(insn->code) == BPF_ALU64) ? 64 : 32; + bool alu32 = (BPF_CLASS(insn->code) != BPF_ALU64); + u8 opcode = BPF_OP(insn->code); + + bool valid_known = true; + src_known = is_const_reg_and_valid(src_reg, alu32, &valid_known); + + /* Taint dst register if offset had invalid bounds + * derived from e.g. dead branches. + */ + if (valid_known == false) + return UNCOMPUTABLE_RANGE; + + switch (opcode) { + case BPF_ADD: + case BPF_SUB: + case BPF_AND: + return COMPUTABLE_RANGE; + + /* Compute range for the following only if the src_reg is known. + */ + case BPF_XOR: + case BPF_OR: + case BPF_MUL: + return src_known ? COMPUTABLE_RANGE : UNCOMPUTABLE_RANGE; + + /* Shift operators range is only computable if shift dimension operand + * is known. Also, shifts greater than 31 or 63 are undefined. This + * includes shifts by a negative number. + */ + case BPF_LSH: + case BPF_RSH: + case BPF_ARSH: + if (src_reg.umax_value >= insn_bitness) + return UNDEFINED_BEHAVIOUR; + return src_known ? COMPUTABLE_RANGE : UNCOMPUTABLE_RANGE; + default: + break; + } + + return UNCOMPUTABLE_RANGE; +} + /* 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. @@ -13406,53 +13490,19 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env, { struct bpf_reg_state *regs = cur_regs(env); 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) { + int is_safe = is_safe_to_compute_dst_reg_range(insn, src_reg); + switch (is_safe) { + case UNCOMPUTABLE_RANGE: __mark_reg_unknown(env, dst_reg); return 0; + case UNDEFINED_BEHAVIOUR: + mark_reg_unknown(env, regs, insn->dst_reg); + return 0; + default: + break; } if (sanitize_needed(opcode)) { @@ -13507,39 +13557,18 @@ 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, regs, insn->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, regs, insn->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, regs, insn->dst_reg); - break; - } if (alu32) scalar32_min_max_arsh(dst_reg, &src_reg); else From patchwork Wed Apr 17 12:23:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 13633262 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 C53BF13D299 for ; Wed, 17 Apr 2024 12:24:51 +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=1713356693; cv=fail; b=mbmMfT1q1oWClV6vqTEagTmzmMvnAR4E2FrcNHfEveguS2L6Huwcq/gRnPEhFrXPD/9pQjAQu1244L/3KBNnRDzIi0Od1fbic+l1brcO26YRELgoKh72icQuZC3PRrzsMWLWPi5Qnw4V2lUTx2i7WTci+SW84ZysfKYErUaHxTg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713356693; c=relaxed/simple; bh=x6ZnOX4qWtwbBnhNC5I6v70woU+o0qBgY5YnyK2f6aw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=T8g4OVHscb/JDo5oNeL8fHHIh3VvF4reSGeAUruxIRxUwWUPM1hsKpyh7Qx76xzrZ43P5KyuLzwnNsuVTtWiDMcDCVu2oeg9vsh1c5NYLcSQtKnDMa1PdM0OqHCBwoQ0uTag7nzGV/b7nl4RFdF3VcUtkSO4WhzFx7gw8ulsAls= 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=KDWeDOdF; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=sCRDFZVD; 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="KDWeDOdF"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="sCRDFZVD" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43H8xURH021820; Wed, 17 Apr 2024 12:24:48 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=4PmDskNSHCtCsT5oacYQ0Me/0wAlI1YjtcoEVkh1Q58=; b=KDWeDOdFtG0BgKc9RqGhgg1/GYJa8Ecnfn9ITIRYME5OGcXTf2bKhw9hlriKo3vD0GER ohlJcBpgLVtFC2qk6PG/zrnpPmK3f8/sp9sCxJblRvX4A1ZZUawesPVTiXhEuQSnkRtQ Z+khp/dbT0SgKAPOYWWGaQ8n6PWPRfOdnbSXa96pkmZWErWnh+e08AXDVzhUw8aMJBEH K9FNm+mt6esUiMGGR1f2G/14E6kxQ1jXb4mONJP5fbZAehJWS2tjZAvk5Jd/2ytKUagw 78iprXDQOWhfEAYK9aqFkiWXknJMoOboDIvXDrX7JfqXA44IW63b6GHQYVcY16LYngg2 zA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xfgfffr3n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Apr 2024 12:24:47 +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 43HC4enV028851; Wed, 17 Apr 2024 12:24:46 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2169.outbound.protection.outlook.com [104.47.55.169]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xfgg8qp2b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Apr 2024 12:24:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c0+JtAovjAmCtHoacU+Y+uJiR1n1IvfI7zLDddS0EGKgnniitAh4ZeDMFIfMtFBrfB0KpMtU6cISt3mZh+0PzmJCQiQgHOtcxuhsCFcFMBqL4DsOTQz3AO+kYlMfNpyeJdJAqa1WOxCyzNQH+dEKl0D+jlqYLHllAh2dzKVg60vHooRyzy2SHxwwHfs5L5N6RbhQaQExJMRXZQQrKye1Du4THt/PmAz6d4HUgU3y2kLA7Dc0jz5vnCHGSJwWf5NmYru1awFiAuLhyFK7mitiuYIRszE9r7FZ4yriqcRzykllz0TwB6FtKIpOthgAHuOsK6boABh7N+79smwClSWI0g== 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=4PmDskNSHCtCsT5oacYQ0Me/0wAlI1YjtcoEVkh1Q58=; b=gyxOEGln6422LG0IGJ3Qn4YcGg9KoFI+nhe0yAUlxy2Xs+AoOsExWpuNU8GbS6iwa328NJCGUJd98nXMtitFKOFXeP4nBNeRadboCaGoGp33Npv1bZ+HkqrqF43nz5/JptInYAghh+MtYTiyrdlOzBMDYUCATvfIjsOTkReHyrvzG4rPCaQU8wFtFN4vs1fUKdRA4AvGFGegvrCmczYyhJkh/7SdRwsVjeks3YkElh8FZNsUQ6b/E6hV/Z2pyD0fgeGyZ2xnEsjtSvUn05F88BmRmjuOkv7QeuihXTpdmg6LsoCzDhAFb37IFKLxezg6XBXpFD0d+ghDXQ2AenbW/w== 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=4PmDskNSHCtCsT5oacYQ0Me/0wAlI1YjtcoEVkh1Q58=; b=sCRDFZVDAa6JwEPyAixf81Daf8708Ck0PA/8zRBpOUxxr+q7hseEJtPMlt1dCsNMU0p+PSfyFzOWXrLK1rPD6aDT8+KDlcFpEXNaOucgcx5Ap0+Y1UtfvYnU9DYU6uBrLnwgi7toASrhbuoqx+TeSxm6H8TVZxati7CQpWUn6NE= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by SA2PR10MB4745.namprd10.prod.outlook.com (2603:10b6:806:11b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.37; Wed, 17 Apr 2024 12:24:44 +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.7472.037; Wed, 17 Apr 2024 12:24:44 +0000 From: Cupertino Miranda To: bpf@vger.kernel.org Cc: Cupertino Miranda , Yonghong Song , Alexei Starovoitov , David Faust , Elena Zannoni Subject: [PATCH bpf-next v2 2/5] bpf/verifier: improve XOR and OR range computation Date: Wed, 17 Apr 2024 13:23:38 +0100 Message-Id: <20240417122341.331524-3-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240417122341.331524-1-cupertino.miranda@oracle.com> References: <20240417122341.331524-1-cupertino.miranda@oracle.com> X-ClientProxiedBy: LO4P123CA0335.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18c::16) 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_|SA2PR10MB4745:EE_ X-MS-Office365-Filtering-Correlation-Id: 2dcd3f52-b1f8-4fd5-beeb-08dc5ed95d59 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RI/GyoNMtz2QoGOrPex1IvKNTiA8A0bIdiorVjvBOXs2E5HKP0/61jDR/zCHk/f0YqBsZRuJ9zCT6xnFWc7m/B0BE1kppGtOo+Rj7ygPsdWZn5ryFSFaY8VRTUdax5F2Q5lBmMCd4fWs621CHGWhVZ786wgRB5Ac4ngvf2OjcBsKYAupTX35vGzHWlsyyBo3yUM+XWjHEf64ov1DtFuWBPbdJ5kgJUpocCyynApaGUavVS9+xOd7/kmCpM47AMqlWmGCjEDbNRGHWS9uQ9HOnU+3QGTfo5SWnah5eKYPauATLXL2MjdyoYIHqa+VH36w6HpLf+GJy7MTS1CUEOQhrVSUlzKhbNhbZxcTZjXjFMX+eSgiQaFlIZXBsJs1gJEjxmeqwAfHYSk1bXE4g0VRt/Hkn8NzqmJZ+KcQ0SZP+ts+ZnYAmlW6fEWY3P2s2bYqi9qLSi0gcQB+U6UopyNM4LjE+nAExhu7mw6tpkwp7vgRvBWmCyWSNo7ScCLs54eUg0o+ZfTa47O3senVWGLB71Y3BL0Fb4fRdCPtVLHHTXZVWZY8wsqTfSQUjOxXvIdJ6Li0UY0Dy5eBhFruhJ/cMNn0lR8Z2NLKQ+yezFH9ObdICHsUMXRKtoc84qiUfqM1Yz80zHSfX+9WFDVV58v5gLrGu25mUPgmMb+drmlsGqE= 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)(366007)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6ZH4i0StZ9ifg4igfGlUpVmRTRbBHB4tdOpkxYbYHOAImH8xJHq3qxTMjXnVfvT+WfrZy7zqd3Lj8KTNKB7Y782yl8lBV/4E9nIWA/YJCbuEY44qxfB/gssxF7FA6AoDPDuvHX8bvgFTubq4o0lSl4shoUDAHmHmyfEmPfy9pADZj2TLriv4OplUg/GsO7+FWFBJMzlqdcZQwXoq/vpL7AUBs1R5rzZcXc85n/yKTEXn2H86xQjsUKBU59QmnzpdxmXam1Wn9yDvo5a+4uxEpju0PqXFWuS6kBI8MCDgOx0HKMxDoRDm53PSnQjCKgsj6DGX8D/wvgJevPgZ28FoJdAFtDpzsPucbeCemV5Fq20TCvOIk23pEEqknK5JyBPuFplVwisA0yCKpEbEFX7V+dzc9RCMTAIUtyobi9wDHcYy1Ox86JUTbVU3/rmd1QTVe5E4h+Ay91KL6cuTLvRbM8MhLcAEpaXsGEPy9RyYAtFD5pOWTauYWkn3HlvTtNDkQmMAfeizVQ4Trcmj8wBNP7oPdrlUavW89hk1L0qh7RynKHeKlyPD05RfOj5PsyW1UCrG6Yl69eez8L11ppdc4h2jLgn1xffH9lbUB+DEOAhZlW+KM8wxcmFqITFhHSebvML754zNEJJEOrvL2ZTwGOfgNCA3mFFYc7g44Smnfkfsjzv5Fd6vc4QuHQtXQ27d7VPfMiLwT65E78SlZdHWBScsX16XDU7XPFQszv4ieRVrVkRN4KAT4+zl6GFz6ZC0rOk91Y206JJeOvXoQlqwqfr65ER13AJNaYR6C4kxxwu4ttuDhc6qeU1LgEGgPg99Wr9zZ11wJ/571SNI11tY28KY+1bdRRbIZqFXfL8HzKyCt1sPoEDiIO1+sUPuOrPFqsO01NhOE4Rz4EuP6ci8OtjALeoCJALGTwaYaePkJjB7ZFMwy+OSPWf5IqNxMD/o/XzmpvxB5vnhXpHkfoYhf2kqq33eGe5xs2N2hJqoiVQ6ciNfx7T4m+AAvi6GwSnJr6j3JtvKJCP96MoiFmRkH7EqajHUOA551tPpesaYI+mnm/4/KVhvAQHH3Ief6RLRAZRMx8lwJfp0N4SM5O7MTjFTUuqoh3VlOeFfTcE4q7wOIe6a0qvWYYzqXzAp3kkqLFD9z/OTW3WrtD8MyiEGMjZbyzmwmGa7PanOvrnVq4rKZHndR0fysibh8dPQy8O0If0LGp5mxZ+UOjdYMHsByEAxcHpoZYmsfuRGRKGv+DbDJzoWgal7eOHGfP+GJY87kxYNmhH4y9FuMsakkl6DLYRYz4cftsq8yRhzAwOxCivauaeJGOQbTWoub6bnufeptqOzuFcuQZIFpOjHsG91g97Mr2clhmVCuXLeekOYG/WHdynjw1+NulgbkLC/IvhpFqfhpi+Tb3hy5TxiaEZhKGCKwVhPKX6ovQ4MzQCp1sSXOr87E6uIdsFWAwnnBzo0KyksEEsLN1yVzQIjfI9gbnsH8gR94Gf6i20KdgAREqzIlEFQVrEVtuYKdb3vvTlTnLhZYILgPURqOmxX5M4Y3gbjeS2gtNsXNSYELRbBXK6ItmVcsVUPOMmILAmcy5JK/fHEhUDsscJymuPoO+y0Ttl+ib407R0ngGTMSPf1deA= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 1hhcXbY566VnjPOYAht3hvZT3DKHhtxli8EhRydH75g85HsidKAAkLIRWURgIt4sYu936QZBUmrL3L0iKIfXgxHcMFTJ9PnXG+7aG+f+1NeJCStUYSXraE5RhHrxRGZA/UEbECkT7ce78yk9aCg7Npy8gF5I4quz3GQv1jo3wlDgzvoNtZxjfYTRgvgrQlOckEejYBj/wWJSvqdyMqjvQdY6TuK/wP2M6gxZgOdZTXtmyYLCoid22XzMnje94kFJrViXSTL8DHWTXLwnMG5k59/y8O0Jj+2Fp8ZSh1dRUsewxRtjB01J3bSXb/rsqdVVO17aXQBqTHV6208tvtKk7Na11097tmkJIrcvYBdoYoVU1JGH8ca0P9gsBKcFfTSs4iAK0mrloVFsNJoQgvv3GgfoCZ1tr43SLtPxrbUOlrbQz0p3lHQYIVI/wL8EQPgwJAiIWtH8c0CVL+tQ6LzvNWkgvYvpAAW73dXPDuuD4P21VrRcVq7wG79t9yHx7lAFiipSaMADr/kFj8ulex8+ajZNs7mVZvKrN22PaFM5VnLqXnkrZmJnkx5Y9C7vJLHuF2koM1vsewpm2PYGLvMyuv6OylmgtpmQfq975DyeM34= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2dcd3f52-b1f8-4fd5-beeb-08dc5ed95d59 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2024 12:24:44.8268 (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: PC2ZDvzIEIFSfnma5RoWXYg0LLsOiZwd+IL0GaRva6vwCaGEdMdJBANHCndjU6Y/UyKbJtoboCDnKXXdsTvLSJRoMUscIC7NEqLW9LaDLfE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4745 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-17_09,2024-04-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404170085 X-Proofpoint-ORIG-GUID: 0SuJQQQ7b3yVeKhxx9mjMMDSAud4pB7y X-Proofpoint-GUID: 0SuJQQQ7b3yVeKhxx9mjMMDSAud4pB7y 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. Signed-off-by: Cupertino Miranda Cc: Alexei Starovoitov Cc: David Faust Cc: Jose Marchesi Acked-by: Eduard Zingerman --- 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 0aa6580af7a2..f410eb027e25 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -13453,12 +13453,12 @@ static int 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 COMPUTABLE_RANGE; /* Compute range for the following only if the src_reg is known. */ - case BPF_XOR: - case BPF_OR: case BPF_MUL: return src_known ? COMPUTABLE_RANGE : UNCOMPUTABLE_RANGE; From patchwork Wed Apr 17 12:23:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 13633265 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 1941A13C8FD for ; Wed, 17 Apr 2024 12:25:10 +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=1713356711; cv=fail; b=QFdXRjAj+CGGtG4jWhS1gLKNFknYo7A08rSfmKupVl7u/f71N5Pyyi2b2E54AH0AAEQQ02YTCjw3N9+eB9FuGteuleLZ1kr13ddMbeAc2tPm33zt4GWhzhq44LslIB/s5Mgv5tY6XGA3l162hsbbT1vCDYwwVIGMNawmYu+G3q4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713356711; c=relaxed/simple; bh=UORXqqI4e/NJ5pHUO+5rCM/XYV7/ungTVN3Fzghi4w4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=g8t/XZjtkEonvwaSxa/b+gq60oC/Pw+XOO2sRo6F7X6XiRUK2winnZzb3lowt0OwzM41Z83oqqYfbzSi6pKkoiEu+Exp7ogEOQlukUQPn6/Mzp478PwIt7lNkMIpwAjbExdBOhmSHL45stxKwi7lL9QpLrfzOlqOrSWsN9CtUmA= 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=BvDz1FhY; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=ROcDDov5; 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="BvDz1FhY"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="ROcDDov5" Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43H8xNq4012432; Wed, 17 Apr 2024 12:25:07 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=snbHceJIm2uz8WCnWA1utUsetMzMrt3xYh6lhLnaTEs=; b=BvDz1FhYGkvmiZYTPilXtszkX8oCHgzfCcXaVT2iGEwhvnkC7fPy1ysLXkz14cMpjnTy RjnTdfOgdtuvQewO16xXR5LHCKsWYCDAR+1svXtsd3aSPaMqt4DKLgEe2tX/5ZjP0x4h K1qVtmksQ5ceQ1+IUOAoraGW3MMr/aL/1yXm+fSq722rkPHSwKOjnx26Jx13EYkBWSyP O3ZzxdPEaXAUvobcS0SCjHRe54sxolzl6xNqWGPnAqQRok0csdybxbX3LOJ4VK7+iQky 2aT8nFl95XSGlOqkNKAjohOFZbPqi4sgyXTIW5WKM8syV4B9K/FZN8rppnoPSmANp5Tb IQ== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xfhxbqkc8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Apr 2024 12:25:06 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43HC1OXD014453; Wed, 17 Apr 2024 12:24:51 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2168.outbound.protection.outlook.com [104.47.55.168]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3xfggf09r4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Apr 2024 12:24:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oBlcp99wWvVNI8NbkMY8Tu6VRuDOLpOjsLit9DwJX15uRvytAWQNRqEUKMUo6of0FWMFtJap6XYlR2klUSYn+O0+LJKhZ6Gm/R+pKf6pfRctFxTkRR1FVeEFy8HJ16bJEv3qLghwzkgSG5i8eN2lyWm5f5Bk+THjeBQbkYFTHLBHPtwKA0cg1iKQ1fdXsEZZgEtINETNpWgZ6Cghh7/DBjVFdnBp9467BxOHoy/JoTXLnyMVvqED3g99LEQ+3ZFI0EFbEQeCaQkP9AzIu6w15NwyO3si1AgwEMgsPjvEJrdBiGOkpPyuDIA3MwMDdRsXy4VlWfw1IWqYfOOb5RBm0Q== 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=snbHceJIm2uz8WCnWA1utUsetMzMrt3xYh6lhLnaTEs=; b=Jvc1Djli4TkthUZclrjZAtOT+FRkQeNBsoczm/ezybK/0ZFBdsnigYlEs+f4FR9J00232v8BXa5JJxXRiHa7QvywtpzOrPSHMvxhMJrFYT4wcEFbkYKvw/380nHBWPROY3vqjKbg2aBoFryfpAGbzZipiBLNrhy/+VWAPSU+Sd9IIqrJJG1Nh97BFamVoi1iKdWA5OlOhJAaG8mDu1m+0ABdv7mFBBAeMY220UAslXVURSaBJqYMdWC2tLbDXw7q+y1hqOZ4L4MTTv/yeRxPJMJdbxRdeQwLpC7qrSAoznF4W069mDChwVgq3YcfMMCOG/WFl/3GGQiucO1IJSoQJQ== 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=snbHceJIm2uz8WCnWA1utUsetMzMrt3xYh6lhLnaTEs=; b=ROcDDov52NJm8/ZFACUpqCsKtoIuTpYR+uog8bo9wt0WlqMWtgHL4ZWfhrb0IGawcmJgL8ueyqbBRGKQhTnw4LHXvJJ8A/l9io2+180rA3zDYRFmMF6WhnwtHNkg978m/Wsljn0f0do+REt1ozU9gvsBA9xUF0Rji/DBTdvghP8= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by SA2PR10MB4745.namprd10.prod.outlook.com (2603:10b6:806:11b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.37; Wed, 17 Apr 2024 12:24:49 +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.7472.037; Wed, 17 Apr 2024 12:24:49 +0000 From: Cupertino Miranda To: bpf@vger.kernel.org Cc: Cupertino Miranda , Yonghong Song , Alexei Starovoitov , David Faust , Elena Zannoni Subject: [PATCH bpf-next v2 3/5] selftests/bpf: XOR and OR range computation tests. Date: Wed, 17 Apr 2024 13:23:39 +0100 Message-Id: <20240417122341.331524-4-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240417122341.331524-1-cupertino.miranda@oracle.com> References: <20240417122341.331524-1-cupertino.miranda@oracle.com> X-ClientProxiedBy: LO2P265CA0088.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8::28) 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_|SA2PR10MB4745:EE_ X-MS-Office365-Filtering-Correlation-Id: 8ba79a86-7cd6-403a-fb93-08dc5ed96047 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HGaLyxWAUzpTv56xQk+nG/i0bsGYDKKdOeZfh+73ydzv1ka4f4Eoo2fDNyyVNDXoqGgs9bvYSaidx8E5v1AYV4KSfSvu1sCA3t4jC27IBsPX27+9F7X6v3nw06g3KKNJQUTl0SLOKKo0+JUoj+snHyXS+QRfBxvTK+UgbYNSq9O67iDOAjesTQc9aUPUS9K1hNcuckPbw2zPtpzF2WxDqRW6FbTz8BMCALsPUBnZ/UMYCgHUBtZcfeWGLHiJ4nd8JUkZdTo0IKEaA2bVeYHOKAV058OYNwUuSJgpG1IbUQU7ExJKmbZRpvi8wFivfeseMc18FotEasm5267gt4nIuiaTjwM9/LZ+E4EXRRhP6z9MTu7RZcPDVm85uoCvYzDI5suKb5onS8EJ/JWz388iSaAenb20LuGG+dPNmSmJx48TiNLmBRupsSkErHXSz4GSIHgdAA+x7OXziOu+OGfKQEeNIDSgW+pPye2jw9h6cXWiSBA+q0wmG1cVB5WyF2D3EojwyeNoUE5/GYjFoCJKv+1ebKOy87KlKEpGXLvBC2d0aTQ6fHmj20nn54wDVbjDXKu8/efrUPSOnTO8SPoF/V5bFt5UhAERnolooT/2i8mK4RQzPkoKnmPW466i4DIbBdiXpJSrPCdDY3B2oTK2ERrvQW6fRWik2ir1RdFP7rI= 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)(366007)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: puO4ZE92hwxb/xCBEEkqXxPQamkp++mM7XYu7G8ClcZ2ugfGnFC5XwTZObuPc7KQ3VtM9385vrc/SevT0BEw7hdotWmIqj4IhAJBjB3p2PUUlybcu0qxkIAU4DWu5c6v7ZWfYAmPEqWy5SJ/ibzJf7GjvgD6TGgCHJgjo1ajQ19voFIV+XBb6szlEZJTHwZR1s/Uo7zYlBNlL0OgeRwy4wOmH7JInMeoIty5LJzTOzRBfMyq/SUYs9QBj5TE87ioz2oROmrzEzxCTlrngWemmWqfbhVQh5OzDymrVpH4fJ3sTsdaA1r4iS44q1GC4I/etKgSbuAwXtuRPMHtJex/i+7w3LhtyeLLuWsoGNPIpcAZmMn9PnOHRyItPAm7uXjHocVQX6T2Z7Ce488tHnvutloWcxOo1GUnUNme/g6GU755UeJjEHqtV11SdTn3WQEjjhFWhgA6arF1iRqngrwZgjB3l7+KyBXKBPkFDW3TsrQBaWo8t2KKi5Hc3ywCIrWF7sHUB04sQvc7kccOSFlfc0XVzXByfLMxAWO01Nukbd6xnraGCsZnVAaZgUp3ueLSlKKWpfpry3z/QiTd8LhM4VbxdS+LOILFa8pNXSCQ9bCV/fc84MeuwFUnrLAWAG+RjValDHcTdc7eqvSTiVVjKJ43wYPTHiRGk3TBpuKyTrd9e2JmKs7LBxld24VlbWpASer2bhxkQOc3joQ6wKinYRYv4qliMmbiOdkrlYKuvOq49jXroCN2JluSRcnDGKYnpzqT07ZLuG2kFEaFsjrLwbsWdmRRARv0WPQmqvSwULjziotVFp5oXaq4JPllCPh2gVYnehdR6QSZHDgN6+R5FDz8v/+alYp35BQwjbJyaqstlq3ifnbRGDM2jdzhnAtyHZkGo6nCNgwY5pyHG1cOkbaIMB4yb3tBTQ3YjFOlWPdAQRLiHlV+nt3WIhAQZgReWKj8Iil8TWY+z/w0/pSXhcyTQbvw3J+i1aTrd6NrvKZ6Nsf3op/w6u3QdEM61Np7AG+Dqa26agSDTwZPRGh5QNqqK92lThAuxVqKd4UOVjSDOqvBXC/7onwLD8eNyKryBh1uS2h5/Jum8nAfS7QyyLN3Blc4LfkxLVrSiC7SCmEIW1QT7kJNSpLCQd7cfQXIoLfYOIavex4bdebvYrfY4U12WYpjNpC8IYCjBwRL9MwNGLEkTmuQQ8L1TIfnQ6RiygHdu0a/AR0LWwwtB4jtlnqyGzA+1DKVEdc2l7dnYpFdR2HPgEXqHnAEVCLjdwrJK8576V65Pwiddv4vLvMlC4xso53oASw0wK/9O+s8pi+a6FXiHwcw147ezmUVHBnjdjkZZBhi79l9ZYD/3poLm1swWQM4nNszk9CKxdl61wc8NjferFRArkmMVyGfCxk8kjY6xA2HDH4ate9/YwWPemgd9UA2bbcRD4bPUURtYuFYb9ruAf6XxG2NA7Xlfj3Mi9VxkgERkd6J2ZXHEofJhO/+YoxHiF3qEnG5sfutTBMr8B58U+Vwta/hGvSvNHOpv66KrgXgd/y90VxLwQzNIm9ZI3+PnZRl6fInNYpvZJ0hmJMugXt6k7fFyeVksEITBDGvta9GeNfIJ+Y1CEFyW35kALS5089urvAmtR0Xkdw= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: QaOkpedBs31Jz9WOxb4AY5OQkzbsmyfRI4HUrZeZozq+BI5E3gTSKih/5nFZ/47d9gsS9GENvl4uSB4HaG+3W/PL38DPOWznjVJ4PoOOQVASZxatMG044+X1PygwAz+NV767gq8NhvI01zNSh0r9qyuqdM0FgWjSOF8UfFtxJBSiBfgIN7g4/JRSGISWcXVer6zQlZv5PwnHWdqHrtTim9Jy11xZM0XuNjqLHtHO+PuDLcnjObEfT/26bMa9ayrvFuX+/AsRIEqoYNmyMX9XMT0T0LTKit+vZKL5nKrh9o5uVpLktF3dIBHHhiEzIoN+GoAjF3KxSh3hJi3yPPff8BT4T2uQWKdsgxhBdutGeaN3k8AjjACN2B6XMr0sJhMP1J0YsMPhDrRaDClfWKHVC06QH974IVyqO83xoEIv9Dgd9iAG/aGl09rr9SM9/Cv7qbzn1Y3G6DCJHRXu3RD8U8vCU935193Cpa95i5uvX4aCLUL+k7srs24diXR01Xzdldqj6gDpp2Iz5djyzvfntpANtjTCfLO9khbnsc29heFBExH5gcDkvmk4524717PPmJOjSU+fkZukvOVlvkiWt6tXbcltN8Facy1LyLdUrNw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8ba79a86-7cd6-403a-fb93-08dc5ed96047 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2024 12:24:49.7577 (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: ZZkWrqwcfoUiQp31B8ApM+xfzYHYPHu43GYEvSdHaGC6wQWTttJRvCB26PUqrMEhlB35dGYBaax+gNgaST5ensam4p+NpOuef2GoijSA2Uw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4745 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-17_09,2024-04-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 bulkscore=0 spamscore=0 malwarescore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404170085 X-Proofpoint-ORIG-GUID: ZD_5BS9Dut8NfF8iaQ03kel7r2IiNKDK X-Proofpoint-GUID: ZD_5BS9Dut8NfF8iaQ03kel7r2IiNKDK X-Patchwork-Delegate: bpf@iogearbox.net Signed-off-by: Cupertino Miranda Cc: Yonghong Song Cc: Alexei Starovoitov Cc: David Faust Cc: Jose Marchesi --- .../selftests/bpf/progs/verifier_bounds.c | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/verifier_bounds.c b/tools/testing/selftests/bpf/progs/verifier_bounds.c index ec430b71730b..e3c867d48664 100644 --- a/tools/testing/selftests/bpf/progs/verifier_bounds.c +++ b/tools/testing/selftests/bpf/progs/verifier_bounds.c @@ -885,6 +885,70 @@ l1_%=: r0 = 0; \ : __clobber_all); } +SEC("socket") +__description("bounds check for reg32 <= 1, 0 xor (0,1)") +__success __failure_unpriv +__msg_unpriv("R0 min value is outside of the allowed memory range") +__retval(0) +__naked void t_0_xor_01(void) +{ + asm volatile (" \ + call %[bpf_get_prandom_u32]; \ + r6 = r0; \ + r1 = 0; \ + *(u64*)(r10 - 8) = r1; \ + r2 = r10; \ + r2 += -8; \ + r1 = %[map_hash_8b] ll; \ + call %[bpf_map_lookup_elem]; \ + if r0 != 0 goto l0_%=; \ + exit; \ +l0_%=: w1 = 0; \ + r6 >>= 63; \ + w1 ^= w6; \ + if w1 <= 1 goto l1_%=; \ + r0 = *(u64*)(r0 + 8); \ +l1_%=: r0 = 0; \ + exit; \ +" : + : __imm(bpf_map_lookup_elem), + __imm_addr(map_hash_8b), + __imm(bpf_get_prandom_u32) + : __clobber_all); +} + +SEC("socket") +__description("bounds check for reg32 <= 1, 0 or (0,1)") +__success __failure_unpriv +__msg_unpriv("R0 min value is outside of the allowed memory range") +__retval(0) +__naked void t_0_or_01(void) +{ + asm volatile (" \ + call %[bpf_get_prandom_u32]; \ + r6 = r0; \ + r1 = 0; \ + *(u64*)(r10 - 8) = r1; \ + r2 = r10; \ + r2 += -8; \ + r1 = %[map_hash_8b] ll; \ + call %[bpf_map_lookup_elem]; \ + if r0 != 0 goto l0_%=; \ + exit; \ +l0_%=: w1 = 0; \ + r6 >>= 63; \ + w1 |= w6; \ + if w1 <= 1 goto l1_%=; \ + r0 = *(u64*)(r0 + 8); \ +l1_%=: r0 = 0; \ + 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 Wed Apr 17 12:23:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 13633263 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 C63B013D2AB for ; Wed, 17 Apr 2024 12:25:00 +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=1713356702; cv=fail; b=kNXPU/7FPW915EZH5NZGwoPLI2gPPULjamt1ws1vo0CufUQXUbNdJZ+mruTBoa+MDFX62QSwkhbw2d7L1ouvZsJHWUMXJRacg4l5+pm6MjDOTWuZ/z7VNzzyoYVGztiTcX/a0qWrtGrjeeaGpJ/qTHl+2DfI6vgfvXnZmJ1n2JU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713356702; c=relaxed/simple; bh=LNNEcxMgiofbuj90IxDJO8EQX+GGPtMdpIUAINiLb94=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=j4CMtNUFtgmwyhMJH6fbS3BM5mXUiGDTHc/a6B0QZ8+PP/BszrDnlFo+PlCnYUjTAoAl5kDbDJ/O37ty/TPzZkWE4uxKwTfPFB8mS7Q1ZebVkyYCVysdd/HPYHn+aa60xDrA/h7SxSK/sTQ7bhx0iFtIA2oypJlCXGJY1uJhmIw= 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=cWGCEKMv; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=DrA5imPI; 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="cWGCEKMv"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="DrA5imPI" 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 43H8xpfl021226; Wed, 17 Apr 2024 12:24:57 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=PaxhIippKWAtkkfsm/cyuIt4IQv0QNaDCkzcdbf35Xg=; b=cWGCEKMvSi5j0uXnkPCPq/hId2fnE4Yno35T9UGQEGaNQfQJBXZ0ipnRNaV1I7mUhNK7 K41oG9knV9wadVo3ago6a5C7tKUiLwSbS+XEXkjiT/ULi8fxpq0WKRDTFWZq+V7Bq+43 kcKxyYn/evUQQ7bke7i3ioEPqoM2X5TUB1VztjxOZs8hAsUFOEipIaR2Xn72rR+GiNoL IAOhD6zRQtlD+hGsrTpUgY36EkMKlUWnJBwnPo1bOI8SqCI2zP3bbmKoDmTuGavr+m/U lQOy3ERoK3fJikZ0tf0QVC8KjOWv6C9Fuw50d72iG5EfFJUI0WiQbdEXIuyeA5Fuip8W Ng== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xfgycqq8v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Apr 2024 12:24:57 +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 43HCFmNp021707; Wed, 17 Apr 2024 12:24:55 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2169.outbound.protection.outlook.com [104.47.55.169]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3xfggf188q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Apr 2024 12:24:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dkz9kq+cY+2oq2BW/YyUqsGjZZ+zb66otUophNu0Amr6fU+msYGSjXUCg1Zzgbx7DiqigeJhSTWJDY/pacULWWIkOfXvkMBPxl52Ptk3VgUNqQZP26xDYILtAUD5VLFEkc/XNa2Y5BvEI2Qef5DMPeGK3rFzY1N0ZZG2RMvxB6iOEmkT4WLlcyMfEqNQeYCUg8NdJgsQZVlNw1iv0b6jKWJi4IvWmCRmFAbyiu3rtmdlIU25QQU1rbrcjNbpOqYG3+yRZbII9Jw6Zyg3dNu0YTZlGwrnqqmsBWJ1kOV03IamYKiNXqZ4H3O+Q29g9SQ44IQ8SgRTZJcOwet3ApXJEw== 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=PaxhIippKWAtkkfsm/cyuIt4IQv0QNaDCkzcdbf35Xg=; b=giawJ83BD/FcwlPHegoo42Ncgr3mrORViTEGRAlTuYSLc3CX8ZN9nGrNnpYdisdM+o+n0vzIrJ81qyaqbSB0xKv5Ud8bOxqKSVUDl0IONksOREOpSq2bTLfmzdRO6JrGtOShbZTK9q2O4DyuuOgxtPsfFqmUc/UrqKR3Oyb0umUnSfKDbJ6ZaAKnPYVnLj92WmvI3/dlNZhZBkDRK7+xIkhkgAj+BAlG+7YJOZxstrRiAn9BDTTZxnvsPIQeNEtTUIqeeLx/Xa5dzFfLDD9asv9z2YYBKuSJnyOekyZK1dKSvXsw1spyisMMNNn401rGPewySA3//Xen5/9rnTvkeQ== 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=PaxhIippKWAtkkfsm/cyuIt4IQv0QNaDCkzcdbf35Xg=; b=DrA5imPI9OQyVwXOj8pcVNP4p/Skzs8OMh2ynV66ClPnOonT0eLFxJiQxf7RhE+aI0KPiFJTbZo0wj/mLWxVTTPunsjQ/L7CjhPJv2Z7FkLKGKzM5gnruoe1a2qxas8W4v8baOeuoNaWYWH5v9NPCSW63747ENMEhpKJFg+9/5U= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by SA2PR10MB4745.namprd10.prod.outlook.com (2603:10b6:806:11b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.37; Wed, 17 Apr 2024 12:24:54 +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.7472.037; Wed, 17 Apr 2024 12:24:54 +0000 From: Cupertino Miranda To: bpf@vger.kernel.org Cc: Cupertino Miranda , Yonghong Song , Alexei Starovoitov , David Faust , Elena Zannoni Subject: [PATCH bpf-next v2 4/5] bpf/verifier: relax MUL range computation check Date: Wed, 17 Apr 2024 13:23:40 +0100 Message-Id: <20240417122341.331524-5-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240417122341.331524-1-cupertino.miranda@oracle.com> References: <20240417122341.331524-1-cupertino.miranda@oracle.com> X-ClientProxiedBy: LO4P265CA0076.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2bd::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_|SA2PR10MB4745:EE_ X-MS-Office365-Filtering-Correlation-Id: 10c336d7-b058-436f-cbbf-08dc5ed962e9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uHAQPxqfP9wImsCJtvjgOH80OlDKypFYjC/ZbEwiC7VAPdilRBaq9GAYXhF5kii+9ezm85P5SQLWG4mjF3ixsJYyW4grTDlhbPKtiQBPkMb00nLG2d0rVcelPFUVhlZsxbToSdunicVkDBJMu0e2pF3gL2RU67ngk2cWmpVSGS2fBQiWKe9mEgGiiQZLjCnPCUukoFecUu0uxkT7+z2SKRm8P1cEQ0kzFY6N9USsY9DP3+80hWtUxbr3L1lkvq8+YCJDtfrcofOIx3tWqIOLJfNY3JxHij8sqTDNpnvgnVPkQzwYdOGuDkNoxw5TWbZeatvBNLwPto2ij8lXOBW4juqisL2qWHeBD45Qgzh9LBqrIX94q+p9u6MsGu1w8yuZpLOYtQd0aL6q7g2iTrvF3GriATPbaqcGE66sSRRmOsE9cCqnFucZZFFhA+BX9/YGe1kpC7rJ4BXID/CB4C6ux6POiX6hzHrcpj3ftj5SwcOmID1PFlhAElwsat1rb+nZMb2SaaWrBuPHNY2WI+lwbxchQ/SYX+z4gyAOmer8EJ0DIExCt6woIcByVdTRL/Ya2GMD69EB2BPp2GfWJVLqBwl4nKlS+n9J+TFE+kW0mQGuIOj8YrZw3qVAKNNeBX3yjWc+AHKwaOBRJUt66+xum03z5TIne64YOR2Q8gm0WT4= 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)(366007)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Qv0EXT1CcLxEYFjrAq7AjDRiyY630Mf9lcKPlS3U5rY19d9BKInz7Yza+ffOx0bvB6ZDr5u5tQ7fIQKK6gu0k1++4Qr8LpnIPjfNW1Hzr3Dk3Q9GFRSrR/9uK8AJVU4zEp0o1LmsHzReXlrFrn20qUQH5qofA8Siypn0nmq81NGgcU4W2QXTgPEpaBb/iArQGq1EyaLHnA8JPs0obxG1XbbaGdZ7JpppmZnyx0jcOD4A8MNKC9pZMKdz+Jikn56J0Ym3zN3+oMDUA1lolwvOkwP7ok6vn5rm/fD9bap/O5i/pWEn5vbgXkFyJ6rcDUlU8roddWyGWhJQ1bchfyn7uADoMvnE3mj3Ycx9ISkFQDWriY78UAKe1o/1oiZMMN2so4jjem3GIrEPq7RD805NY+dB+ILHB7h+GD3xYMSqp+yKgOfgYYa+3Qyg7BbQj8/bGXDF1M3cyrqPVdm4p37geyIDLt2G8nnJh41AprWh0/iZ3YnHH9kbqq0x9zdOWfzMhoM6+LuK9sFaZcr3LtC+yd3QXP6+SE/iPJBwYjhJV2vkhdcR3RuRIuTR6rvYw324jSkIFb8wrU4VrHgsMb3Xd0R3gjQ2nXkxneKwbSNCDBBzcJUszciMogVHnEFaK/SbJ8HR3LPl12GZWs6udFPFr/ySxmrZwyS/Hjr/ol1oDIwct+Z6jvZDHOU26Ked/GtJBhns/6kbepL8WLZB/T3GjVB7ndq9jzO//P71z7/JqmJiIU4zLBQU91UDpX0WxeaQuV8q4J+tH3ixsE7gc/4IBzWXYRJpouldgfBlPmOceU+6VgMUcpTWSJJ94wvuhZ+2jGlKuwixmENKBixyvpdxnV6Tl9waVnMwjMSulMm3uLVYP2T3aUvxfhY3Cf19fu0+ZPtx4snMRR/s05vDsQ5glD0ID0lDVU7i504CB8lxFsgbLxBP6mT3/TYU/deFLz/yNdAkyx35BquGt9WKITH0CszDyNIVh6wjMavTjhfzyn0D7yXWTV8pVfeT92p+OY0BmftgGpp02EwUecisl/jxsLl9kwyuLfJ6JfkiVS4Bh9l78DpquuiiT4mzBq3g/jgl+Epe+Nocnj5zwhkNYcaZMRwFQs76aHd021DYGj1oYRgZL87WJPXyNC8ddLC/6nTpTzTPLqTdFWNDWsZd5nDg2ckkAKmgkehHkdUQcLymJCwKMAGqKLc+QmiKg407ymW8Y4mCnRqoIRiNVL5yUrC2FEOkFaVz1hgOxffJco9ETuUFgW+MCOl17l1faM93zURuVCwohqW6LLpUqifEz9gcQNbyc14zeK1CeVjwbbQq8YxUXVBcy5hLn7uRJoHpLYTp788dv0bRuEiSa2p/s9h9raR1ZVy7K5XJa61DDlVfrG+UThqCJ/45mKqVyMbgB94baJqiSnhHzpl/eCIGG6HVBp2FxErWSUy/Wn6Qn6VXWmeFXWho8k/uoMdvOM9kDcpeIT4FDbVAUZgEMJs0Hp0+G1KsWVbRHa6poEKxL6/nqbscvwr4PAbbZphiN2zCDxpPBJmjLja/ymAiG3GE72fyneWCvZNe4/QPtLz6saCvL+6eip3NNLq02vGz/CiCn0juRLEW9MzdGdPL8UKyiFHuL6Di56aYh6T3hzRy21D2Sjs= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: n50+bMLE682tapO3tpnvaML6NVFh8e7sRdNi8OensY3j9e69b18jI+LmFYFCDKmbDtZOPsUkjN1zKm0FNQHhs6w+QyAjHsSLFAvTMaynw94eJ9nNcIBA3j126N5KlCjJEmtO+xghDy01LgZBb5ZGB6+gfDrq2Pq8K70itTZxv6GGP5UW9RFR7nCQz9uUKMK3ecDZxAeViUmqijq1m/c+urptPcab2KFhzrcLHhj/DmVxeodZ8qPadXO71tfTSfQZsNIgkk9kbZOJ0QPUn8lziSh6UU0c1Pj2B486popMIBnmDvGv66qHmlvEC8kOBP5RcLSE9WtlYwkWTxfj4ZkOmgf84l0wKkmjqSetV7RLi77wW9MHs8yCKvTKgar3qFWJuliM1E6K4aDf98DXZk0RpzgrLAlRKyvXiQszihWc2V1cxz+XlnKaAw3QCbnlpsTLtUrQo5XsTJ4K+Qu8XK4KJHbUH1hTAtwPEgEVb5bh/rIVvNupAmncMHtm5w+HT49GYIf0vuwuM0f78KH4yKNfAyt+udad4GOiq+T3RpW+wGrRvCSK+ekTdq8mMSfZwJMMAs+HKm72SPPmbmXIIbiXDshYLeISNLcJbLF/lmuROZg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 10c336d7-b058-436f-cbbf-08dc5ed962e9 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2024 12:24:54.3389 (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: r7FM3t9smnuL03t2uKgD+hM2BYnUWJz2VcnZcwL8qi91Q3hq1UY2tqBY/dc9eDDYFD4ckhdnpYy+MVSBHcLnPvaEVGoDm6n/W6MJkdOZx0I= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4745 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-17_09,2024-04-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 phishscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404170085 X-Proofpoint-ORIG-GUID: uDl4TPgnrBlt0H0AWfHtP_WUignamxiq X-Proofpoint-GUID: uDl4TPgnrBlt0H0AWfHtP_WUignamxiq 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 multiplication is a cummutative operator and the range computation is still valid if at least one of its registers is known. Signed-off-by: Cupertino Miranda Cc: Yonghong Song Cc: Alexei Starovoitov Cc: David Faust Cc: Jose Marchesi --- kernel/bpf/verifier.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index f410eb027e25..185ea7f19a79 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -13433,20 +13433,23 @@ enum { }; static int is_safe_to_compute_dst_reg_range(struct bpf_insn *insn, + struct bpf_reg_state dst_reg, struct bpf_reg_state src_reg) { - bool src_known; + bool src_known, dst_known; u64 insn_bitness = (BPF_CLASS(insn->code) == BPF_ALU64) ? 64 : 32; bool alu32 = (BPF_CLASS(insn->code) != BPF_ALU64); u8 opcode = BPF_OP(insn->code); - bool valid_known = true; - src_known = is_const_reg_and_valid(src_reg, alu32, &valid_known); + bool valid_known_src = true; + bool valid_known_dst = true; + src_known = is_const_reg_and_valid(src_reg, alu32, &valid_known_src); + dst_known = is_const_reg_and_valid(dst_reg, alu32, &valid_known_dst); /* Taint dst register if offset had invalid bounds * derived from e.g. dead branches. */ - if (valid_known == false) + if (valid_known_src == false) return UNCOMPUTABLE_RANGE; switch (opcode) { @@ -13457,10 +13460,12 @@ static int is_safe_to_compute_dst_reg_range(struct bpf_insn *insn, case BPF_OR: return COMPUTABLE_RANGE; - /* Compute range for the following only if the src_reg is known. + /* Compute range for MUL if at least one of its registers is known. */ case BPF_MUL: - return src_known ? COMPUTABLE_RANGE : UNCOMPUTABLE_RANGE; + if (src_known || (dst_known && valid_known_dst)) + return COMPUTABLE_RANGE; + break; /* Shift operators range is only computable if shift dimension operand * is known. Also, shifts greater than 31 or 63 are undefined. This @@ -13493,7 +13498,7 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env, bool alu32 = (BPF_CLASS(insn->code) != BPF_ALU64); int ret; - int is_safe = is_safe_to_compute_dst_reg_range(insn, src_reg); + int is_safe = is_safe_to_compute_dst_reg_range(insn, *dst_reg, src_reg); switch (is_safe) { case UNCOMPUTABLE_RANGE: __mark_reg_unknown(env, dst_reg); From patchwork Wed Apr 17 12:23:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 13633264 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 061A413D2A9 for ; Wed, 17 Apr 2024 12:25:08 +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=1713356710; cv=fail; b=ZhaTTomMMbeOKpb19GuxhQ/1whtp3v7D5lJnXZiesQdM7MmKckB3dt/7Ru+IK9bLc6vAryNucRpGFYNnGhckWFjxTeob+JXPQ91OnihsL+OdyGvAyYz4WK340W8bXXXLfaK5spBTj2KZX7GgqKfAXjTStirA+7Nuz/M9ja8WhbY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713356710; c=relaxed/simple; bh=t9hvWIRk4QrBQzObM75b5AAbNGcp35KYhYuvqHm6G3w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=gpzTykSOjPjVQ0+yK6sByLlMZDwEfoTUx6TLK54iDYzNdleB01uHT7uEeK2OWCmBWdC2akYinyf0Y5btfZBjaXf+u+TG7dvSlFU9lTZrG43yiOR0tD51H5bG66oBsm23oZw3RAA3G6okBd/UwO0u5gubbHI5TF0vECPBXo3nliA= 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=gKFCBeZs; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=zDwlsq9x; 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="gKFCBeZs"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="zDwlsq9x" 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 43H8xpfp021226; Wed, 17 Apr 2024 12:25:05 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=3pcUD+mjEVXKWyVD+rHTzowUNSQwSSjAzzzoWUI0+34=; b=gKFCBeZsX5JMAbpMe8Kvrz8TUkGfRv8NPtq5u1IdjkVFlHewJbVTCQZd53Y6T/FVVdQA roCVtzhHOdiNoPgUwYiiJFL74oieaEONDE+YvARAud/TnVkJRO7+UHqAR0yHaqeb9oAy lTXMyWKYYa4p+/cpgbirQTRjZVpjcLq/6MC6is5TY4TcpVQzKV1kzvVxAoXxkVQBelPM tzKOdEssekXnTyaGcp939znUjIVHUmg2rNLPAnRLzxQSZy/QSsT4ZlR2ublX7k2bz+Rn /MT+YgpKCl5ZkmdsXonapYxKiCOOzDVgZ/+sR2ff8dknKGO930hU+Rx070HRo3F2d17Z NA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xfgycqq9r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Apr 2024 12:25:05 +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 43HC9N2Q012472; Wed, 17 Apr 2024 12:25:05 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2169.outbound.protection.outlook.com [104.47.55.169]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xgkwgs8b4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Apr 2024 12:25:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yj4MH0SPsQ2eBGUN14e6zNawOlyawMF74CYByjYjqPdyo58LZCIGIBOk3ptUc4KorFG6gPyB/Iu7EQUIL579eVmxtCI/CsY4Tp/n5l6H+oxLWt3sKq9NpA5UYeM0WYjZemgqPupCChZJU7DYua02dBafO8mN3UJr0i3WAGzld2v57ih2YooWbKLfQ8NLVM0ObAspXStnrauUNlW4oyr6GTFHtP57NW+dHhKU0OuvPznEB9stJcT5txZkW2So8QBSNOR85Fbmmr31090hOl7N9INihSBV56WswP7aknLNZDsr8f5QIFt6Cktx5ZMikwG2zfuOoF5Jvflk3Duu2+DiUw== 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=3pcUD+mjEVXKWyVD+rHTzowUNSQwSSjAzzzoWUI0+34=; b=C3/E4glnyLX55bhtEFeByHrZo4fzDLzbY9Ycx/0y0qWxNxn4y+Jx0sE0i4gGhuIRRZ32I0ArzT+Ot+XEj5byOa5dPvc8aIK/yorhY30m9EW0DII6vE9wnlTkl+bBT8Rzfuk5MIDnAHRGxtyO7n7ApVwTAH7H8BqrVTR2cME4RZc/MLHJXw8cg9Dm3ls12ob0qhpLmF1ha7VBiQkLrXkXQsJvzqfs3icwPu9LBu3ckINQXpjNNFBM/ENohvJAgUzp4taA/rVaGyEKH3GCV81BHBq0pGViKnE96jsMlVu2Jz5Rl0dg/mBBCAuKcXgnU9zOtY4VuiuLhtSKNQBj3KSAGg== 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=3pcUD+mjEVXKWyVD+rHTzowUNSQwSSjAzzzoWUI0+34=; b=zDwlsq9xp6QJj6rHdQZti3Ly7AHxzd1WPdgSG8LhIrGQ96sON/c95DUSemb9BTlTClQSchayV/r3ma4zVUzPO8ymNXb/bKk5tXgzLser96nzQX0R1wlQCsVdbET77jg/QeGzytzslvwK7PAi5obJcQCAhFfYeJlrjxxLTn0rN78= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by SA2PR10MB4745.namprd10.prod.outlook.com (2603:10b6:806:11b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.37; Wed, 17 Apr 2024 12:25:02 +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.7472.037; Wed, 17 Apr 2024 12:25:02 +0000 From: Cupertino Miranda To: bpf@vger.kernel.org Cc: Cupertino Miranda , Yonghong Song , Alexei Starovoitov , David Faust , Elena Zannoni Subject: [PATCH bpf-next v2 5/5] selftests/bpf: MUL range computation tests. Date: Wed, 17 Apr 2024 13:23:41 +0100 Message-Id: <20240417122341.331524-6-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240417122341.331524-1-cupertino.miranda@oracle.com> References: <20240417122341.331524-1-cupertino.miranda@oracle.com> X-ClientProxiedBy: SG3P274CA0002.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:be::14) 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_|SA2PR10MB4745:EE_ X-MS-Office365-Filtering-Correlation-Id: 40e4c5ff-f4ca-4eef-153e-08dc5ed96806 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: huSOipQVtBKloPtqxpnnZgdtKoVWzeZlajhyd6shfSg2JB8xwoN7l5UwNec2FvdccqMjGJtsAKYzLlMpqWACeJHExAPFbaCCRKh0Ia/RBn/sZxx10W7O/Le1virMLn9A6DAu8nZbi1QM7n5PiwvJmXNFSwNjd1/TcPL4Rl6HK62KTHJwkPGgzEBAoli7EZ/hYWfG78cGVnOWbP8d88pJJqD201B5oNPtnvEh9Ue9l6rPVaXZkVcfoUA1TpVlW0kPgn6kmU7D1AchZat1TOH3wXStrM17aI+bmymlVZE4AoAdm1OnkwIKGh4IA0TYoKooHaUhEVnuCh79EOnp+nmqJTMZvxUjc4tkwXHewe2Txj7JOZc7EDqiLimQXmycBpzlSl6gU1HAgBoblWXxlcQcuQA48whaE82KwpNAISDoM7aagpWXUAC1ZKpDsXxIUCKlRpgE952+KHMDX73Nb4W9YtBfAwyss59E0YwI6qTza3xDGb7SCDumcfV1tGS4o5ZmhS/Jsz0gYF9TDjQv360HNlZ/gyWutLNf7YN9FUsUXopIlKIeRNH74sf3AyYVdtNsgWkP/CWMnjkn4GaWd6QPXLwKqcNlcE7F6rThuTqrsXBvfZFXhxzLNO2r0ycGnGql9jkAqRtB8WzQUV/CQqri+HcRez5OBoSbIEXnPjjwALw= 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)(366007)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ejuWnPYA6aYYy8NwLMFAwou+FsM2Qer5ZPUNADyDgjvTglbgHJ/9OjoyKfP8JXuoEHIKngARLXbU4FtNgA/uBdqAe2sf+NwyIE/jiV+r25mMuslisR83M2s1j/wGN1V1CcoNNYGPphych9y4Itg4DYxQ4oz+StOcUuBAtFiDmAWddHkEhCxLxiXLF5vHTuOLjGlyhzsSmy2x+KiUvgEud5jnCbYhXYlg9B92qE4dU1ac2B6SJytYeVkvsOddwCHXlB/aKEo9iT7ae+h27drZfALErHfiniVwbW8wap73uhbfiLcna+BlkkI1/PbCLuXPE+HMtPPkrqtgSb+mNbIZe9ybTjuvDd88alHx8xE8z2hqrafTZ4bNfj0gXMaMBAVZf7XKZD6Gec7eXyV+AixxOA7e0YCqv1raLTShs/Iy3fy6Qki84xqllcYEscH1/vP+1Lntvxw6vUxRFrK6am12LdpnM0CWI32nFAeF4bnuYeF6nDysY/4Fo+p7i57Xv2WIL+r61RPTluyRyPb7g104Wam/LDzbPBF4osgpm9zmsrV++2vj9GOw9qdXVSQESLlIQMo6GTJqOmizFnnt5FhSWRWlzeGpMDdVSI5OZ7fXVIrQDU2M+SdBKb5k9u6GxK3bn0z9WIsz2dpIO3reUjVLr+IX5LLFx7LSll4c4/c8Nk2R62z2vJGBT33mxaDZJUftHEifWbEirkHAhr1EsVQ0YWHJbriZYb6zX3dQydOQtkDxLeh2O37wa9sC10Cc+TbnFyMQ57I5BSp5EnywBNa1hwboaUuYwyhu1EVEGJ64dXJOoHq/O8uHe1LbGqUlOxI5WsDwX+cw+uPj+1jC9OO6nFSY1NFzDYqNw0x2rlrkF+hI4gl2iU/XJmKXf3K8D/zXmnBDIqryPShTS6CUeNtiW0nyS2Whndj1OyHANof1AFvvfnmFLbctpHoM1RwUK2ENtcBqZ9mnA6lYsPc8iiPPHQ6S0K3H9/GE/AF2Vki952YnI0UbgqK1GQwKJ/aNjc6sWyhAYd+KsbqXkKt7kh88cplTut111asfqFg8At1eoHllZ5yTQWJYGCftw4fD9Vx2AfLSj/ec337/+OD50V4H4jVlFfOiSomF31ueM/X3S0gzVoR9NDtogZxA8biGxVPp1/J80lUBMWlv3XXz8ggykJSU5ubOzAkKF9mLJjM/JSjB6x17nSEw9pGXOKsFVSqJ1hBxeJHQTqKK8k4oRLERPw5ydInKDvSFr96uqHXO19xdsE21TtwNs6e7pT1qOFd2n9QvgSlzYWT2s06pK+O4xSiPWIzxp34F9pY0ilO8g5tgqE7Eh9DvxZPb/Y4LdV6kvyUo8C+DD2s78D/87xfuiwkbC2+SaDJcKLH093+BlcnmhWopvFSrQfC/D+5KMvmxa7Qq1yI1rfSdQdqescSEoZlOcQaNjzOfakp/enqxxRFdBN47AWywNifLN7a5ZAFu6aijGBRhUSLLXaZ9qmRfATen5ZOF/0uUqLJyJ5lzk7cvEsKX5i9nOCjdriOggBb0trXZMkIVfwiA0FkbVh6kTu9AX6t5auUsFjxvQxnaHXMChXq2cwS4wpU5xmN9rOk1kYnnvmsivFn1BO33tc+N/XbsAnvqykuKVBqpooshtq0= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: fS8OO3iGCkqNXRg6ZSxGz6R90idtd4j6GsgL52q0dWKJMbJk9oELczzKWJSdUs2D23rND/9Aafsvd+gMCLDXjCYrwvIr35+QdWOIS6uJ5/pjqxA+yEuEVN0ruyHlOge+okMYU1qpj9C85Ll9FYSv/V2DpSPXR3452JWbyzct88IZsBjniSkU0T7a8gZ7D7jnt+RPFrWiPQNv/WWbPCK1wf832SIUyMfejdQy2upsATmE27zEfi3svKf+bu6nvjqR3ASWgEq+v58NOyb36Vv7Y0QuXd3U4xBNq4DTE51UtaUoiCK/tjYpjBADnhZ6ZchcjaihhYWD0baezqfoCQRIjNmLil3rI//tdzB/ufSMR7AoXtC1mOJGJoCyMgbZoCgaDoGHkOJNsJNbNPR9Y6Ffjlpx2JWAGsl2CatHm12g1+J0HJgeigYafPA613HfqvqtywM3cAG0a2wXYdZF0nYcaw0RTkqwG/sFTIIwPeCLoGLJnz7gMeZwZFWRD6QWt+L0Jbmj5CCRlXWhhVm5UtUe6mX/9/JMMKcmXT+XbqiKBzGDw5NCNpHYw8ko4IpQoY9WBHv+Lsrgk5nkMh9RlnyQfFfDbPj/hcLO7iRHQSi8q10= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 40e4c5ff-f4ca-4eef-153e-08dc5ed96806 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2024 12:25:02.6813 (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: /61QoMKpUH5Gc34na7QslodmdzmNWwGh0wzxTFKtM3L4k8W7ap9ytZI7Nnk9B2IeTJU3fiadreSQnPhu7njYEmsvvGdFiYvcnM32uThAbKA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4745 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-17_09,2024-04-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 phishscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404170085 X-Proofpoint-ORIG-GUID: mUgXK6zGxG_kDvFcDvkLvGuiG7mlvnQK X-Proofpoint-GUID: mUgXK6zGxG_kDvFcDvkLvGuiG7mlvnQK X-Patchwork-Delegate: bpf@iogearbox.net Signed-off-by: Cupertino Miranda Cc: Yonghong Song Cc: Alexei Starovoitov Cc: David Faust Cc: Jose Marchesi --- .../selftests/bpf/progs/verifier_bounds.c | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/verifier_bounds.c b/tools/testing/selftests/bpf/progs/verifier_bounds.c index e3c867d48664..719e247114f5 100644 --- a/tools/testing/selftests/bpf/progs/verifier_bounds.c +++ b/tools/testing/selftests/bpf/progs/verifier_bounds.c @@ -949,6 +949,105 @@ l1_%=: r0 = 0; \ : __clobber_all); } +SEC("socket") +__description("bounds check for reg32 <= 9, 3 mul (0,3)") +__success __failure_unpriv +__msg_unpriv("R0 min value is outside of the allowed memory range") +__retval(0) +__naked void reg32_3_mul_reg_01(void) +{ + asm volatile (" \ + call %[bpf_get_prandom_u32]; \ + r6 = r0; \ + r1 = 0; \ + *(u64*)(r10 - 8) = r1; \ + r2 = r10; \ + r2 += -8; \ + r1 = %[map_hash_8b] ll; \ + call %[bpf_map_lookup_elem]; \ + if r0 != 0 goto l0_%=; \ + exit; \ +l0_%=: w1 = 3; \ + r6 >>= 62; \ + w1 *= w6; \ + if w1 <= 9 goto l1_%=; \ + r0 = *(u64*)(r0 + 8); \ +l1_%=: r0 = 0; \ + exit; \ +" : + : __imm(bpf_map_lookup_elem), + __imm_addr(map_hash_8b), + __imm(bpf_get_prandom_u32) + : __clobber_all); +} + +SEC("socket") +__description("bounds check for reg32 <= 9, (0,3) mul 3") +__success __failure_unpriv +__msg_unpriv("R0 min value is outside of the allowed memory range") +__retval(0) +__naked void reg32_13_mul_reg_3(void) +{ + asm volatile (" \ + call %[bpf_get_prandom_u32]; \ + r6 = r0; \ + r1 = 0; \ + *(u64*)(r10 - 8) = r1; \ + r2 = r10; \ + r2 += -8; \ + r1 = %[map_hash_8b] ll; \ + call %[bpf_map_lookup_elem]; \ + if r0 != 0 goto l0_%=; \ + exit; \ +l0_%=: w1 = 3; \ + r6 >>= 62; \ + w6 *= w1; \ + if w6 <= 9 goto l1_%=; \ + r0 = *(u64*)(r0 + 8); \ +l1_%=: r0 = 0; \ + exit; \ +" : + : __imm(bpf_map_lookup_elem), + __imm_addr(map_hash_8b), + __imm(bpf_get_prandom_u32) + : __clobber_all); +} + +SEC("socket") +__description("bounds check for reg32 >= 6 && reg32 <= 15, (2,5) mul 3") +__success __failure_unpriv +__msg_unpriv("R0 min value is outside of the allowed memory range") +__retval(0) +__naked void reg32_25_mul_reg_3(void) +{ + asm volatile (" \ + call %[bpf_get_prandom_u32]; \ + r6 = r0; \ + r1 = 0; \ + *(u64*)(r10 - 8) = r1; \ + r2 = r10; \ + r2 += -8; \ + r1 = %[map_hash_8b] ll; \ + call %[bpf_map_lookup_elem]; \ + if r0 != 0 goto l0_%=; \ + exit; \ +l0_%=: w1 = 3; \ + r6 >>= 62; \ + r6 += 2; \ + w6 *= w1; \ + if w6 > 15 goto l1_%=; \ + if w6 < 6 goto l1_%=; \ + r0 = 0; \ + exit; \ +l1_%=: r0 = *(u64*)(r0 + 8); \ + 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")