From patchwork Thu Aug 12 17:00:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 496520 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 919D1C4338F for ; Thu, 12 Aug 2021 17:01:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 77BC860FBF for ; Thu, 12 Aug 2021 17:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234075AbhHLRBY (ORCPT ); Thu, 12 Aug 2021 13:01:24 -0400 Received: from mx0a-0064b401.pphosted.com ([205.220.166.238]:28498 "EHLO mx0a-0064b401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234029AbhHLRBX (ORCPT ); Thu, 12 Aug 2021 13:01:23 -0400 Received: from pps.filterd (m0250809.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 17CDv2US030865; Thu, 12 Aug 2021 10:00:58 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriver.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=PPS06212021; bh=HW3zyIzMBk8BnfH2Xt61qEbuIbIwq/12zyUjlDA6dXM=; b=hLGCYsVbvRj5MXJ9P7989k3BR/22kHxLH2dwheVSxwTXkqr6bSZVOz5PppWSQQtcCUfT jEGi3eGw86L8nZ1zjzac5niZIVcUvRsgQfNHBM9AnjvBJsIKTQ4PAvjBLxRhyhiZ+INV I3C+A+tEf4lWd1f/4RORm+8aKMBvH5Lxl115MusCFtYQVJYVXGllSQxzgGhE9+K2hwvg Xhzr3Z5fXy/QKL01lzLhlqooNtROWbEndZFiprTNTEnh6h5R4KORMEiAPWDu2y6cEJgc dv+uTpX08s5H19PUyWg+JjXPTWdKOlg+Y/YqlnBnYZh0W3WdmNo8Scc3Ifhu37EWVD+r xA== Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2170.outbound.protection.outlook.com [104.47.73.170]) by mx0a-0064b401.pphosted.com with ESMTP id 3ad4wug5b3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Aug 2021 10:00:58 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PSPKqWsEKufFKUgvk8xOWbwsKyn0FIjKQQTmcrx1yN647iTGQHHdR0LMR6du1TFF5FzPLYnBU6TnpysO8wgsmxHWs6neAKnOYdMVcIOJ3Ox2M9ma1jp4A5bSv3B/onvD+VyBpD7BzyN7f3gf7ikYbTWNZkxOyV5r3r79o9wIrJkt8nvag1zNhq8d4ecCXF/l4QGwu0OuC8hco/2MxDGVWxqmb/YcX60mq5jeJaPDlQdre+Nwhr5WASd2sKeuXLbhq4UvzgBjcN9zfSy/TcRiZ4Q6P5cUnJgpBJEjY8P/MlBZyjDUkZvETw73zTlE0jxnPDVGgHMERupj/ReUn/zv3Q== 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-SenderADCheck; bh=HW3zyIzMBk8BnfH2Xt61qEbuIbIwq/12zyUjlDA6dXM=; b=VPaI/tmQw3hme2tau6+qzGb/IBZ+zQFok//F/jnSEv36o43zxfTH8ByfWNZtDqcddW5jTremsgK/FKZlqv9dVn/l1dOcoqNjFaYwiCWkOqL5+0TAnOkBFplMkoEM5BDRkoG5AtwzRdwtGZF3AhzEdQAxGEm9+BO6sn8D13tHA4iDM4ymF+rgico2QUKbzemK5r4AxYH63hyWqJ58KqfyZXlSoBLw7HFSlW89kUgE+DsJPwuGDWrLU3V+0yCUUJYQf4BKz/pWdohh+wmSv0/RKY3g2ZGSKUw4FuB3b6E/n9Yw5tjuEdcZw4IEE3oYYff7037XLU+uFEt9vmLnItNxBw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=windriver.com; Received: from DM4PR11MB5327.namprd11.prod.outlook.com (2603:10b6:5:392::22) by DM4PR11MB5549.namprd11.prod.outlook.com (2603:10b6:5:388::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.14; Thu, 12 Aug 2021 17:00:57 +0000 Received: from DM4PR11MB5327.namprd11.prod.outlook.com ([fe80::ccb:2bce:6896:a0c3]) by DM4PR11MB5327.namprd11.prod.outlook.com ([fe80::ccb:2bce:6896:a0c3%9]) with mapi id 15.20.4415.018; Thu, 12 Aug 2021 17:00:57 +0000 From: Ovidiu Panait To: stable@vger.kernel.org Cc: bpf@vger.kernel.org Subject: [PATCH 4.19 1/4] bpf: Inherit expanded/patched seen count from old aux data Date: Thu, 12 Aug 2021 20:00:34 +0300 Message-Id: <20210812170037.2370387-2-ovidiu.panait@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210812170037.2370387-1-ovidiu.panait@windriver.com> References: <20210812170037.2370387-1-ovidiu.panait@windriver.com> X-ClientProxiedBy: VI1PR07CA0251.eurprd07.prod.outlook.com (2603:10a6:803:b4::18) To DM4PR11MB5327.namprd11.prod.outlook.com (2603:10b6:5:392::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from otp-linux03.wrs.com (46.97.150.20) by VI1PR07CA0251.eurprd07.prod.outlook.com (2603:10a6:803:b4::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.9 via Frontend Transport; Thu, 12 Aug 2021 17:00:56 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2799a577-291c-48db-0d6a-08d95db2c0ca X-MS-TrafficTypeDiagnostic: DM4PR11MB5549: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:843; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: f8Ox89vY7SELtYNHb5HfJsBJlYCRMnmXGhumQg7yY3XXKUIOJfUuM5JkczRNvervPcvfqy+rNvFIFLeTJsFTRDiOYawEoAMGZ6vUiOZT8jJtY3uQWNcniOeLkzETMEAOxRY4UVWUDO4frkyRiLiK+o9iANpRL0eE33hxGlLrmR+cZaGeS6N0ciwJQnjM4uPWplqP7dcQEhGB7/joXCefcmIpOqOV5g6vtUQ/hUc+5662YfsWPF6uR70l1a32ObDodCm6mcST1wZgXJOI+rOW/WdP7gLNDyHTL+psl8SXrm3TB8ux0MG9Xm8yuYLv15qQHBXHzXRevaInNogBj8i2Nee2VXIGkprjZ2s///FstfEgG9xoKiNT3LujSuO18FtBcUph0FLkp8ZcJ6Fz+wGc0X7ZjDub6jtsWjJYGGpwfdtM9ye/AkAm4a8bSuA6nt6owyMkzgkE+ISV3RY5HdGdd2y6JiklLJUGme4Zk7qbfLit9xTDn749zxlgpTvPsV12kN7GrEPDPrTaOn9mQmnravTaT7SDzOltV8fn845d3NpqnzwSOqyPg+IFdVDyVqJ0mQp1rglW+ZxAMgbr1fI1ZKb3jDj4RwILI45mflbxvt889LXmkhOoPw9I0w82N4EOgDxCiRT+rbCym5fi5+uPv0cI7fDozkX22c3FtnahGyKApCzpiIoBuB8hwy7+zJlHHaDin8752SSe8kQyuuxdHQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5327.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(39850400004)(396003)(346002)(366004)(136003)(6666004)(478600001)(66476007)(186003)(52116002)(66556008)(26005)(5660300002)(2906002)(2616005)(44832011)(956004)(6486002)(66946007)(6512007)(36756003)(450100002)(8936002)(6916009)(4326008)(38100700002)(38350700002)(86362001)(1076003)(6506007)(8676002)(83380400001)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YIke26tV06QfGA4ez5+EBGcybkOpzfYtj2nBGfXZcgWzxW06EbEVam5nGIU4Qv9fOI8L7sK2mPZ6b9XAWkzJVh9Pj39ELe7cxm3AtzMviMMN8HHofF7h1zDrjvAr35hs0MhB8qx9MM/N9tkoypc48X8zMKTe8DGp6m04WttsDtheNJdwgGYrj018f7T4WrFXj9SiAOIyq1z7xWhJ55NDuTWxAGX/7ev2AMdasq/YHqPNX+pE7wKa2j6rg3/uWeDFyE15fthhFW9SKWmMiQuv5Luomzy0UUT1eKlY7FGe5wO8WSfGQpmUzZmMfWTKBBPp2SOToS74d7timH2+sGnEwXOthx4MaQ1AhOzGgZU1BrVbuB94w4bkfJ0rXPa0Gdt+b1BmvBR+1vTl7cJpJV5VuV5Z8IDIz8xOT1COlZ21CpOtL2s1ecwI4mEcUbtKA6omvbScSezrZfcfeCBzK/xry25OSr6ztNQ6S1wVGEnSb2Zp02dnlTvTIpq5iP4Ic1vymUUGInT/FNRqwodBteMpAcz/MGdXkZoZQXPWtTLHBKQQa7LheSMf2vtCc7mJvedEreCwfs+a8KI8HmP2LhvpHQWvAbWEYo+jeNq3DxKl0T9cYv7qC1LjTuNCGRsfP2zP7YrEckdMAGWuiSr+wt+SZgLlpgq4YU6U0SNfXkvJsxQEWdQBSCLFynLsny837N7efVQxxY7gO7PE1DtWiprqe2jXhnju8xIqIa++p2dWBuVuSwpjUFaq0J2nzaBhnYOupsT/abtr/gXvcNUQevuSzmWXRr6rhRwxPtK53QcGPa0EkU+EregznDnT5eJr3sRum0yzBwPOkdtxdmTSpx4QnoZMEqFBPJieNiBLuaBy48+HMGLu/0uUbxoPq16N/vLXY41nU/W/BIzhu/LGehOBi+RJ5AN1cVSdObsxBIc9WZcPIrH1wuT6yhW2tlPLohVuhIyfZm1OoSAoX8yKzRB/NmwKx6uBWbMAHkOCVPRkY1oT3EgPFi/qjq0y9KHmKd1wuLbkRdW88Ff1VHo5Pz94gh6klhw0gJBJVDs3GTcZYsFALvMkxf+Jo9LtQfUcc6Di2N9PsJ/3YCM1W0+L6grWlqpc8NK53rSlpKcvIQhlTUOZcQqmkCJ3BkeEYxNHjPSnfjVYCab+nZFMgxRGVHCQIgFEe9O1wyDFPQHZIMCgiCwc/kCtHTxQjybLWc9s2ADpnrRdy1Ao7J8TvVThKl4qmYQEcLJ1anEAK8IO4MpvJpdJxiegUjKDFvx9BnKAT/JzFRK1TlPIMYm/eeNDQRonQG9W3ZHt85Gxe/njk2wtFl0Jm2NmpzSwLpBKrVre+PFo X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2799a577-291c-48db-0d6a-08d95db2c0ca X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5327.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2021 17:00:57.1118 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: TydoAuGZSawoUTns4eeAhT68OXA/sO/0pi0c7q9S6e3BK+QsVqeiAip+iWR25Zu9l3OISaU0sb90r4EFQM2mdxJaQJZteAdrMsCNzaBdEnI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB5549 X-Proofpoint-ORIG-GUID: Jt1CUo5zClFmh-ujh5zVVIIskqbVZ6ZX X-Proofpoint-GUID: Jt1CUo5zClFmh-ujh5zVVIIskqbVZ6ZX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1, Aquarius:18.0.790, Hydra:6.0.391, FMLib:17.0.607.475 definitions=2021-08-12_05,2021-08-12_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 priorityscore=1501 spamscore=0 bulkscore=0 phishscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108120111 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Daniel Borkmann commit d203b0fd863a2261e5d00b97f3d060c4c2a6db71 upstream. Instead of relying on current env->pass_cnt, use the seen count from the old aux data in adjust_insn_aux_data(), and expand it to the new range of patched instructions. This change is valid given we always expand 1:n with n>=1, so what applies to the old/original instruction needs to apply for the replacement as well. Not relying on env->pass_cnt is a prerequisite for a later change where we want to avoid marking an instruction seen when verified under speculative execution path. Signed-off-by: Daniel Borkmann Reviewed-by: John Fastabend Reviewed-by: Benedict Schlueter Reviewed-by: Piotr Krysiuk Acked-by: Alexei Starovoitov [OP: - declare old_data as bool instead of u32 (struct bpf_insn_aux_data.seen is bool in 5.4) - adjusted context for 4.19] Signed-off-by: Ovidiu Panait --- kernel/bpf/verifier.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 4ce032c4acd0..70cadee591f3 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -5690,6 +5690,7 @@ static int adjust_insn_aux_data(struct bpf_verifier_env *env, u32 prog_len, u32 off, u32 cnt) { struct bpf_insn_aux_data *new_data, *old_data = env->insn_aux_data; + bool old_seen = old_data[off].seen; int i; if (cnt == 1) @@ -5701,8 +5702,10 @@ static int adjust_insn_aux_data(struct bpf_verifier_env *env, u32 prog_len, memcpy(new_data, old_data, sizeof(struct bpf_insn_aux_data) * off); memcpy(new_data + off + cnt - 1, old_data + off, sizeof(struct bpf_insn_aux_data) * (prog_len - off - cnt + 1)); - for (i = off; i < off + cnt - 1; i++) - new_data[i].seen = true; + for (i = off; i < off + cnt - 1; i++) { + /* Expand insni[off]'s seen count to the patched range. */ + new_data[i].seen = old_seen; + } env->insn_aux_data = new_data; vfree(old_data); return 0; From patchwork Thu Aug 12 17:00:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 497092 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, SUBJ_AS_SEEN, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03381C432BE for ; Thu, 12 Aug 2021 17:01:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB8F06109D for ; Thu, 12 Aug 2021 17:01:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234128AbhHLRB0 (ORCPT ); Thu, 12 Aug 2021 13:01:26 -0400 Received: from mx0a-0064b401.pphosted.com ([205.220.166.238]:35290 "EHLO mx0a-0064b401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233901AbhHLRB0 (ORCPT ); Thu, 12 Aug 2021 13:01:26 -0400 Received: from pps.filterd (m0250809.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 17CFLX85028069; Thu, 12 Aug 2021 10:01:00 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriver.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=PPS06212021; bh=22JUZi+busK9gD1zI/M6JQ9ME3f19AzyGRuh9I3KKHU=; b=YtBuvkoLV2LldO/pWi/dxqU5oZHsnroScCcRmTIBOuciczSAuNls+nSTHYSJcDb4ITZH XF/rVYy8H7aUkzn3ic7BVVgy4aPIV1LU8Ju8tPjubb5K6tAcKil2t7572d1q2Sst4GYs DiAptGnqFwVBp7Hw4pw6EeXMh1YZsDKvlHNROIeF2vO/+spZa9eBtJ/4JSQ9OdUSyRb7 bmdUO8/HIH0ly07EaBZ0eSYBsXDMEV10jqu2jfdg6bi7YXkh+H9XNk1qEqVVsBwPBzvh 5UdUCXfzwbmf7yJ9bxB8fWSv+LFxz7EEXGJ2HNWslRYdvlBCxGit0zUofy08agpuZmba IQ== Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2176.outbound.protection.outlook.com [104.47.57.176]) by mx0a-0064b401.pphosted.com with ESMTP id 3ad4wug5ba-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Aug 2021 10:01:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TY0xaXAjjJgpgkDpObOUszzXEVV2eYSVnEmMqAf7qG7YTrV/Us2vDm5n+rWoUVQ6YMyA9wrFbwitPkoMlNPJEA4ycA51LVwf1GaQsyNRbuyK0Jo7HyIKEoKIdS7yRW1u12BpMdJRaudNUcL48fTb6cr2OggNMRqnSWLI7RMvTSMPTIAAjHyjPTGNw99uQAz7X+QQVgddqTTfBlPHt5k9qE8jGNRcBsO1uVB6VLebKOUh42EdeUtMwzIzfSby2+JQJo5fTaUgBsTkBBuxyzy10QOgxW3NbB/1eqpahwpJ1KjSYqpQDYY4JFdYaCzwQ/vxzYbgYvfZEGdTDX3wKwidPA== 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-SenderADCheck; bh=22JUZi+busK9gD1zI/M6JQ9ME3f19AzyGRuh9I3KKHU=; b=mONOvqdoU5JyM6KAmj+EDUlp1Rxe1nd+bd2A/6rEHeJURxZkW789G3IwwSry17nCyx/VAUJJgJlAOEprRJWqmZfWbY+mDfLdA6gEU5o2+jSOnsUXg8ccRcwB+/3gNBUTkKKIfGnrWLaxkCbIVP/qwgO85fZYmqqusWRQ0vHvTSfG3djCQxvaO/ra1anTeNxLzUV/nXw5olb1oi6SbyzZvV6rb7WfAH0rXRj5gdH3IyWEB1zfCS2FFtDnVtx+6g/WfcE8ElN0cpitBBA4w8ydMHuQeAD8MeB6tuuhqdIv0hotthp+AgOAczobyNJNElpqm9eeDWMsRlH/99V7c6Jh9A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=windriver.com; Received: from DM4PR11MB5327.namprd11.prod.outlook.com (2603:10b6:5:392::22) by DM5PR1101MB2121.namprd11.prod.outlook.com (2603:10b6:4:50::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.17; Thu, 12 Aug 2021 17:00:58 +0000 Received: from DM4PR11MB5327.namprd11.prod.outlook.com ([fe80::ccb:2bce:6896:a0c3]) by DM4PR11MB5327.namprd11.prod.outlook.com ([fe80::ccb:2bce:6896:a0c3%9]) with mapi id 15.20.4415.018; Thu, 12 Aug 2021 17:00:58 +0000 From: Ovidiu Panait To: stable@vger.kernel.org Cc: bpf@vger.kernel.org Subject: [PATCH 4.19 2/4] bpf: Do not mark insn as seen under speculative path verification Date: Thu, 12 Aug 2021 20:00:35 +0300 Message-Id: <20210812170037.2370387-3-ovidiu.panait@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210812170037.2370387-1-ovidiu.panait@windriver.com> References: <20210812170037.2370387-1-ovidiu.panait@windriver.com> X-ClientProxiedBy: VI1PR07CA0251.eurprd07.prod.outlook.com (2603:10a6:803:b4::18) To DM4PR11MB5327.namprd11.prod.outlook.com (2603:10b6:5:392::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from otp-linux03.wrs.com (46.97.150.20) by VI1PR07CA0251.eurprd07.prod.outlook.com (2603:10a6:803:b4::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.9 via Frontend Transport; Thu, 12 Aug 2021 17:00:57 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6b311455-bf97-4b57-2d27-08d95db2c16a X-MS-TrafficTypeDiagnostic: DM5PR1101MB2121: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2449; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hmOl0bugwdv3f6bEJLjN+tuaO7uvayO6ZxzORoNY86nam+0U/hyro13aptcNOWjV7boFVMkQ89rpfey0KRdnbDALunSSGHoKszqnKCfUGo8CUiDG1PDEGvA6RX2A8N2CeNER8otn5Gu4WX3SVZrsAa2apfRUHz+LmOASbE0G7OkCotux37UJAL6BhhvfnKpaZsAjwEosq1RywdcM/Cwe1RcCAgH3CL6UKgnFvmh1Mut2MstEk4c3x1k06f2aZ5arfQEFIOCI95FfKxiORhA2yoZBgBi4p/9vqHiGxiMLaKUo+lii4Z4RYHcNCB4ECt+AL7CkeKv7yZ2jEsntygSKg2eFcqGRa/WQpoWjNezarLrxF2c9UhNjkk66WDXiLhXAk4RuEu6jkP/mltNPovVMKU0Y3574WWLfBmRcLmKZXvkkI2A1M/2MPnfmfw/ffbtskMzxUvlMaErw1XlOUkh48Kx21Ayi4xN8ES+7uJXQExQyXC1N7wF1Zw9yNqn7Gic+Czsjcs4/W7z9v8lGOFvx21WB4JzOrhgo5ffOPnelNAft5C7UkWEfx5tJICb3fiip6tKc8rS7zho4Gj6jWNkhNbL7CJnIYnf3LWly1Q068T+6IA2bdH2BrBSxDpo5hrIK9lgwfCzr77N58cZeIEylDU9gqg3sKpwNjD7tAKWbkIIyr3hYroHSro5XpRFcRWuhwrz3gW+TaX2YfX8QGt7Zbw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5327.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(15650500001)(508600001)(6916009)(66556008)(66476007)(8676002)(4326008)(83380400001)(86362001)(66946007)(6486002)(38100700002)(38350700002)(956004)(186003)(8936002)(2906002)(6506007)(52116002)(6512007)(36756003)(5660300002)(6666004)(450100002)(316002)(1076003)(44832011)(26005)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: G3KDEMrVP94Bv/tmcUPUfs9b3/ghOUXLA7uFcWZOBK3YpWj0gqA5B5kRIMz8G2Bp8RbkaYfKSjHc7ZWsWCnNYyulfo/MCPXOxV23K/34XlW1brFpPdNQtGGatlD5v51VTIDvcWB8KWW/XSma5dsyUM/GHUBsaMdZ8xoSznTpi93CNwWidW3To/SK3gCoJrxWzl1Owm4n2+CPaA2e/xdp68pNOzlQPn10xo7NoDDlkJtdMvPcaWdJiCX1dW/VELPfehJ1F5Rjual1T7ONlSBwB2PW6ErEtLjaSPRao5wqr2z8sc91NxusxKqpcEg5P3w/1fIg/5BuxuWF7gIAF/7svDEjzsjSEfCS+MY9MJaZFUR6TvPS91FwoLTKVFciEjFP7FgIvJSIL/6Fvnionhj/r0peLYd0GdXPwxujIqPeVfDIbBMvMAyyVnWir9PwyKuAWPGIOBC3RvNaTyKqRAUUcNzgUqKoybJVUbp+qM7mt7LizIAHH8hr12puUFSSYPU0B51Is9dfu8C8yq6Bn0fLXEJvr5qAX3+gJHPJDcwlShaLkgFPn8ZNqXVOtS4MpKD5VklnsGwc3P2y4Tou2dYhsg/m+gtszbjWuhVpYBVkx/uRMVrfwRQCivbO8mzoJ8ZFRiDQtnf1Fwdb518XuLmLNLnT+6nxsiT2yZvzE+BFI1YqGwNEByP4y/3T4iN5Oj9JFNfYC7EjNvZJu89c/4WFFKSa+C/Jui3nudbfOAIRLKMjTqKsYYBYlmwK/Jg+W2KJLM41pS2FaieZgGFx94/U9+OfNLJpNFFMfGgHkMMfiMw5vHsmP6QN/W4vQ/wWoHjHT6fLvz4boEQ8viq5cfDzW3jviFV7d0WToCk7G2KI2NS42U+B4sqOLzc1f9eHz2DlXcTYLyGPbYYrE3/m1vrGEQcVQ2js69Udv1zbCz5cwTmPcuHHbXW1C8TTNHll5/pDVzZh2Imjkk8eHLFkeb7nf2R1uSfOEMUl9kzrjwQnIuZW3owOjI6akKWO0E8MVqWPUBYsl3clRt5ZTeaXPmNErqaEPL8l8M8/ZL0klgB5YSv0Ap6/S09EOBwNFpEbDA+JazUt/mWlpKEuJqC+ZaZWWR9OT761ZHuDpkocS+SI2B3SS6nOXXI3LWndBBU4TnVecBiRKvlQsoZo2Go0W+iXI/Za6eobT/beVFzMiMgW7QTqEWLiLpsIXLCs6Akh9C3dPu/w4x9MC1mPEBOXZPCpWW/7EfMAloAWnAR3RbIruKG+nEhAnpfqXyarP1ub/ZhcuS6HA/xNc4XUCcbIehynP5d/NVcy1N/XqzHTbGKyLdM06FM8D2o5IxhGwIUOkuHW X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b311455-bf97-4b57-2d27-08d95db2c16a X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5327.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2021 17:00:58.2578 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 87e2mpb/5Eig2tio2psOM0crknqL0tK1bNXGdc5ktCXVHgTnGcw+lqVwT03GkVf9USqEFq/vbOOSErytI89zmPZpMTFXr4sm603j/V4E4SE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1101MB2121 X-Proofpoint-ORIG-GUID: 07ERtHoRlrBhnL0FiM_kQkg1OZ7gkLNC X-Proofpoint-GUID: 07ERtHoRlrBhnL0FiM_kQkg1OZ7gkLNC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1, Aquarius:18.0.790, Hydra:6.0.391, FMLib:17.0.607.475 definitions=2021-08-12_05,2021-08-12_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 priorityscore=1501 spamscore=0 bulkscore=0 phishscore=0 adultscore=0 mlxlogscore=730 suspectscore=0 malwarescore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108120111 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Daniel Borkmann commit fe9a5ca7e370e613a9a75a13008a3845ea759d6e upstream. ... in such circumstances, we do not want to mark the instruction as seen given the goal is still to jmp-1 rewrite/sanitize dead code, if it is not reachable from the non-speculative path verification. We do however want to verify it for safety regardless. With the patch as-is all the insns that have been marked as seen before the patch will also be marked as seen after the patch (just with a potentially different non-zero count). An upcoming patch will also verify paths that are unreachable in the non-speculative domain, hence this extension is needed. Signed-off-by: Daniel Borkmann Reviewed-by: John Fastabend Reviewed-by: Benedict Schlueter Reviewed-by: Piotr Krysiuk Acked-by: Alexei Starovoitov [OP: - env->pass_cnt is not used in 4.19, so adjust sanitize_mark_insn_seen() to assign "true" instead - drop sanitize_insn_aux_data() comment changes, as the function is not present in 4.19] Signed-off-by: Ovidiu Panait --- kernel/bpf/verifier.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 70cadee591f3..566eeee5e334 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2901,6 +2901,19 @@ static int sanitize_ptr_alu(struct bpf_verifier_env *env, return !ret ? REASON_STACK : 0; } +static void sanitize_mark_insn_seen(struct bpf_verifier_env *env) +{ + struct bpf_verifier_state *vstate = env->cur_state; + + /* If we simulate paths under speculation, we don't update the + * insn as 'seen' such that when we verify unreachable paths in + * the non-speculative domain, sanitize_dead_code() can still + * rewrite/sanitize them. + */ + if (!vstate->speculative) + env->insn_aux_data[env->insn_idx].seen = true; +} + static int sanitize_err(struct bpf_verifier_env *env, const struct bpf_insn *insn, int reason, const struct bpf_reg_state *off_reg, @@ -5254,7 +5267,7 @@ static int do_check(struct bpf_verifier_env *env) } regs = cur_regs(env); - env->insn_aux_data[env->insn_idx].seen = true; + sanitize_mark_insn_seen(env); if (class == BPF_ALU || class == BPF_ALU64) { err = check_alu_op(env, insn); @@ -5472,7 +5485,7 @@ static int do_check(struct bpf_verifier_env *env) return err; env->insn_idx++; - env->insn_aux_data[env->insn_idx].seen = true; + sanitize_mark_insn_seen(env); } else { verbose(env, "invalid BPF_LD mode\n"); return -EINVAL; From patchwork Thu Aug 12 17:00:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 497091 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7F31C4320E for ; Thu, 12 Aug 2021 17:01:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A56A260F57 for ; Thu, 12 Aug 2021 17:01:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234158AbhHLRBe (ORCPT ); Thu, 12 Aug 2021 13:01:34 -0400 Received: from mx0b-0064b401.pphosted.com ([205.220.178.238]:27864 "EHLO mx0b-0064b401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234122AbhHLRBd (ORCPT ); Thu, 12 Aug 2021 13:01:33 -0400 Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 17CCk0Ki010817; Thu, 12 Aug 2021 17:01:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriver.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=PPS06212021; bh=8SX2RJnPWkuH/S9lNKQDu/SEjBtaWrphT62kmL0jXNg=; b=fb0QGKQsP84u8TScy43ZetLR/30O4Ci11HeFLeWQ6WMGjBa+6NPRYo7bXOmiZYADm6xl 1jXeshknq2ace26KPUN/BBRTRCvYzJqLOW+J+XOnYtRYv4AyTQKp1YtEGhORROS64ILh lgj2m40heqGqUsH4CYLepxyurE3RXuP6Pkzl+db7U5MEXRHDRazsfcvyK7P2RszAhtc4 HrybLWJ7QifOW9RxXzm63Zu5xexgM3qqi5/eHe6R6s1sYSRJ1t5EJyISbRd0HK7Yirt3 ZYZkE9W8vB//KpjUB6EGOj0SwdMZzTQY7yW8Lr9xXoTgnDZtLG8Th1dZVDJxWt9+M6ag gQ== Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2042.outbound.protection.outlook.com [104.47.57.42]) by mx0a-0064b401.pphosted.com with ESMTP id 3acsen0jxg-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Aug 2021 17:01:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E4zXZE0N/uEi8eebv1MWK4t7jbNO+jsw7ouRDCoVZ50ABf734abXBRaexG7nlfDpXWwsxslBqfG3lOb3htvwPFXH9aSpzsmoEEKLfGYtfYs0RrKg8PFta5cvBrsp860rh4OVCbhCGfSH/nWTClROuJcssCYpRH7Urn3+r08Z5G1xeqEiYOgyhFzSUSMzT9t3nz6+py/axKoWfCWHLMTwSDRCHuLWSFaUACC/b9K6OdPkytY1LBVp8jEtTtSpwO0/MEuKl2EzLNN6Eb0qjCAay1SntgvqcqVI1CMRk/s6dmv3kBPz9kAN5ujCio3NsThKfD5oVlPNyIc1OXbHXWDkFA== 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-SenderADCheck; bh=8SX2RJnPWkuH/S9lNKQDu/SEjBtaWrphT62kmL0jXNg=; b=bJ1yYA0dI1kt9+v8mPGdn5Rk1Pvpdbm7GCUAudRhmH4P6+4Qeaq52h0fjibApWkO4V9o3iYgNFpjgbAQj44rN4NiKfIGpBMLtwLR1Ka8di6I/wE2SfML9N6F9nxuuKTprlNi1THdnDv9UKIPuNXk4pQl9MUqTKhdMzQ5SuCw2uyVNdcOXO2cF7sX/KM+88PQkQNhl/QM+sr/rNxNf+H1uJP7h8d54VlQbdLH6VGfsmiptldvQW68ZHSZqzk1bJmdCy0+m3QQ99EUUU4QWetC7NHGgR2Bj0EfoTJ+/eeDOL1T7tMpnPxKes8SlY+9cW43O4ci/IEeQUaGh8TxLeMNLw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=windriver.com; Received: from DM4PR11MB5327.namprd11.prod.outlook.com (2603:10b6:5:392::22) by DM5PR11MB1593.namprd11.prod.outlook.com (2603:10b6:4:6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.17; Thu, 12 Aug 2021 17:00:59 +0000 Received: from DM4PR11MB5327.namprd11.prod.outlook.com ([fe80::ccb:2bce:6896:a0c3]) by DM4PR11MB5327.namprd11.prod.outlook.com ([fe80::ccb:2bce:6896:a0c3%9]) with mapi id 15.20.4415.018; Thu, 12 Aug 2021 17:00:59 +0000 From: Ovidiu Panait To: stable@vger.kernel.org Cc: bpf@vger.kernel.org Subject: [PATCH 4.19 3/4] bpf: Fix leakage under speculation on mispredicted branches Date: Thu, 12 Aug 2021 20:00:36 +0300 Message-Id: <20210812170037.2370387-4-ovidiu.panait@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210812170037.2370387-1-ovidiu.panait@windriver.com> References: <20210812170037.2370387-1-ovidiu.panait@windriver.com> X-ClientProxiedBy: VI1PR07CA0251.eurprd07.prod.outlook.com (2603:10a6:803:b4::18) To DM4PR11MB5327.namprd11.prod.outlook.com (2603:10b6:5:392::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from otp-linux03.wrs.com (46.97.150.20) by VI1PR07CA0251.eurprd07.prod.outlook.com (2603:10a6:803:b4::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.9 via Frontend Transport; Thu, 12 Aug 2021 17:00:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6a14d750-cef2-4c74-04b3-08d95db2c24b X-MS-TrafficTypeDiagnostic: DM5PR11MB1593: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AYQvHyxAF2uA2TRNHuWclaIslScJKNcrFayOMFEITwKqwa1SOBIco2+462br9O477OCSJ5Kdd8z4J91zN8MRZTzOpDtP7j550OwRKe+JFaRU+HC9IS755M+KPrO07ruIBjLE0SS2Wz7LTJKSuW69LQ/AVotK6THZiuz5pZb2pAbMMeOwVHzxy2OVQAOmrAHMywdHmMVL3GPwNxg87miGuJAQdRG/72Z/kP3ktCsHvjZ6gLWu1yG2u/Y8E39hSHcIfATr/EEQegY5ooAkuEphdOgGDA12Tnm0i3rm4cVBbbyOGKka6LVMGHXqUgDgkb4lM9LULfZbMtuH7JMvGyGxCFLBIfrrPfSvpoY1Qy3jZLMCFqjjXtsRWon05KYR4QCosTwy8UQGm+v6tOiwXqhqHgLVGQ0SNqpg2LNMSLkXhsmQGQmBUgp4dVgA5JKv2JWwnziPM+D7nWN6HnpzxJ8vhwu2Z9bsvG+eT//QtaEWq+JkP8hvca7yJMqQX9sV3J51kqiftSnTz5pefSeBRBrSdm7iA4+Fhuw/WKQeKuuBpabH3ZG+UZ8M63P6HRvZZP7TsNgEs0Fku1uukYtHwd0Pxdn/2ZOmJOHM71xML263t2bvt9tW/LkYXzAZSqynDEBeqCZeTzfDb2yW54sNiXCP2C3T0zaHHgPZrPbEXo7rT9iUT70rK3F6rcI8fTx4BzUO5GfCDuYzAsyaeXOfHqLZvg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5327.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(39850400004)(396003)(346002)(136003)(376002)(26005)(66476007)(66556008)(8676002)(44832011)(6666004)(316002)(86362001)(2616005)(8936002)(5660300002)(186003)(6506007)(52116002)(956004)(66946007)(6512007)(38100700002)(38350700002)(4326008)(450100002)(6916009)(83380400001)(6486002)(1076003)(36756003)(2906002)(478600001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EfU0JpKGw6OHJr6+a/4EwJ67jUk1HqAmzgWirVjX0zmhlFShuyZhMZlpn8YlcaN3mX86qZFdpJJAvoThzQ4TWyP5wCHO9497Rjxn/xFUTqPcjMbywNScsgtiD58Nv5FFnRPq1DMprZBh9MtbsNYp7hmU0AXvWMz9QgebpfAUra7T1K8bEWfn9scrLqcBHp+FcO9rkjhQhXG4Tcn5L9WfVMgysRNAh7SddZFz3xCXkbtCHgAOfU8iBXojgD6uawSSQCfk0v9w2Dnm7omeQxFQNdvjhYVILYJS0t4XHGKCZVGpMET4utjsF0a9W+J3XNkgXvmPJyfQkH/ni2EBbiXc/brTopQrtx9/ssbN6LyjmstNGVA5XQZT61dCQHdrgorGbepUdjX/bK9Vvql/CN+noZsnpqf3MYChklIVnwlDxYpTUrTEyOW5KFB/b8In3Zeek7kbB8XzVfdycUKDrbkvhSdnBek+j5oXqcCU/Bbfyv+Ci3p1/cOyZuynOycyD10gJOiVqWVPvrohvGBuJj+3Q18e1S6sBcQVp5K+e1nesOITJt+VGEvsM6e0Q4mHgj24pi0wYOKA+QTIFF5wSamM+NKxbpYYNf2TMQE942qPmXPNaLr4zD/NG6jU6ITrAp4GMSemky3yDb8IyYlU2Zi07W5PMGsmm2suF/+aqDOV/gZquHwXLX4L8NabQQrByYKcIbT8mTUq2qZOnuyWaSdgoDGeCJnWJh6QPxByqKXMaEqLCWYT6GcLq7yF9tYhvAisPbYZKXkmfT1x36rOa/wl1TKBzIyAPQyePxBe1Cjt2G0ECvMCXB57s1MfjYz5SYPRgCFkST9b3TfuroZsZMmMtPqeEFY4SbNiBRr7iAyyu4qHbB+TqH4XCPuJi3janO6P78o0LwWAMAyLN+e0cH0XlL+rZTMEg2D0qIe/NhzTokZFGgSzv5zXcfSc2ixYdImssSOtM6pNmntoAiHPLqfnCOhq7nbC6WUr+G0vY9ZVV8F/eEPOyTfFkgKhgXKMo8Wq7Bhq0nA0udgMgRka7nsM061oF5MSlrsxPS3MnF2wk4HUQxTHRI3G04cEXpslS48TtdgISNHQNlXlsU+rE227Wi5kvc5aKjBWZB4U1UH+D93DIRbj1YjUA3znzi0l10ypH6Ca9/SDrFKqTeFJlnktBk0Hr/9cyuA9Kitp2yR2WOkkVmpcTA3pl4e1kG4FXpdr3pb8IUgx9dXXDmXJY9YHcp42Dv97waL1QA2donrZCexWEuEnMdbYTwAJMAePIkjoaY9qH2G98SOFMTdpxaOo/UTvoZ3MjRYWW+6ThfBquA0ZSGU0WwSdeQMTTXpF8/i7 X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6a14d750-cef2-4c74-04b3-08d95db2c24b X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5327.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2021 17:00:59.6387 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mjEYh1+5kngX86Jj5vdUHN7MdYUGPsVDkVeo0Fr5oc8c2AYD8grRHmv3OtGC3z+vPGQOPzJjCObOd4Mt8iChsPgzTfbH/jg2HxeRWrCrl5c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR11MB1593 X-Proofpoint-GUID: V3cHWyzh-r08XuzA1OfLduljSXzdcIUs X-Proofpoint-ORIG-GUID: V3cHWyzh-r08XuzA1OfLduljSXzdcIUs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1, Aquarius:18.0.790, Hydra:6.0.391, FMLib:17.0.607.475 definitions=2021-08-12_05,2021-08-12_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 priorityscore=1501 lowpriorityscore=0 impostorscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 bulkscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108120111 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Daniel Borkmann commit 9183671af6dbf60a1219371d4ed73e23f43b49db upstream. The verifier only enumerates valid control-flow paths and skips paths that are unreachable in the non-speculative domain. And so it can miss issues under speculative execution on mispredicted branches. For example, a type confusion has been demonstrated with the following crafted program: // r0 = pointer to a map array entry // r6 = pointer to readable stack slot // r9 = scalar controlled by attacker 1: r0 = *(u64 *)(r0) // cache miss 2: if r0 != 0x0 goto line 4 3: r6 = r9 4: if r0 != 0x1 goto line 6 5: r9 = *(u8 *)(r6) 6: // leak r9 Since line 3 runs iff r0 == 0 and line 5 runs iff r0 == 1, the verifier concludes that the pointer dereference on line 5 is safe. But: if the attacker trains both the branches to fall-through, such that the following is speculatively executed ... r6 = r9 r9 = *(u8 *)(r6) // leak r9 ... then the program will dereference an attacker-controlled value and could leak its content under speculative execution via side-channel. This requires to mistrain the branch predictor, which can be rather tricky, because the branches are mutually exclusive. However such training can be done at congruent addresses in user space using different branches that are not mutually exclusive. That is, by training branches in user space ... A: if r0 != 0x0 goto line C B: ... C: if r0 != 0x0 goto line D D: ... ... such that addresses A and C collide to the same CPU branch prediction entries in the PHT (pattern history table) as those of the BPF program's lines 2 and 4, respectively. A non-privileged attacker could simply brute force such collisions in the PHT until observing the attack succeeding. Alternative methods to mistrain the branch predictor are also possible that avoid brute forcing the collisions in the PHT. A reliable attack has been demonstrated, for example, using the following crafted program: // r0 = pointer to a [control] map array entry // r7 = *(u64 *)(r0 + 0), training/attack phase // r8 = *(u64 *)(r0 + 8), oob address // [...] // r0 = pointer to a [data] map array entry 1: if r7 == 0x3 goto line 3 2: r8 = r0 // crafted sequence of conditional jumps to separate the conditional // branch in line 193 from the current execution flow 3: if r0 != 0x0 goto line 5 4: if r0 == 0x0 goto exit 5: if r0 != 0x0 goto line 7 6: if r0 == 0x0 goto exit [...] 187: if r0 != 0x0 goto line 189 188: if r0 == 0x0 goto exit // load any slowly-loaded value (due to cache miss in phase 3) ... 189: r3 = *(u64 *)(r0 + 0x1200) // ... and turn it into known zero for verifier, while preserving slowly- // loaded dependency when executing: 190: r3 &= 1 191: r3 &= 2 // speculatively bypassed phase dependency 192: r7 += r3 193: if r7 == 0x3 goto exit 194: r4 = *(u8 *)(r8 + 0) // leak r4 As can be seen, in training phase (phase != 0x3), the condition in line 1 turns into false and therefore r8 with the oob address is overridden with the valid map value address, which in line 194 we can read out without issues. However, in attack phase, line 2 is skipped, and due to the cache miss in line 189 where the map value is (zeroed and later) added to the phase register, the condition in line 193 takes the fall-through path due to prior branch predictor training, where under speculation, it'll load the byte at oob address r8 (unknown scalar type at that point) which could then be leaked via side-channel. One way to mitigate these is to 'branch off' an unreachable path, meaning, the current verification path keeps following the is_branch_taken() path and we push the other branch to the verification stack. Given this is unreachable from the non-speculative domain, this branch's vstate is explicitly marked as speculative. This is needed for two reasons: i) if this path is solely seen from speculative execution, then we later on still want the dead code elimination to kick in in order to sanitize these instructions with jmp-1s, and ii) to ensure that paths walked in the non-speculative domain are not pruned from earlier walks of paths walked in the speculative domain. Additionally, for robustness, we mark the registers which have been part of the conditional as unknown in the speculative path given there should be no assumptions made on their content. The fix in here mitigates type confusion attacks described earlier due to i) all code paths in the BPF program being explored and ii) existing verifier logic already ensuring that given memory access instruction references one specific data structure. An alternative to this fix that has also been looked at in this scope was to mark aux->alu_state at the jump instruction with a BPF_JMP_TAKEN state as well as direction encoding (always-goto, always-fallthrough, unknown), such that mixing of different always-* directions themselves as well as mixing of always-* with unknown directions would cause a program rejection by the verifier, e.g. programs with constructs like 'if ([...]) { x = 0; } else { x = 1; }' with subsequent 'if (x == 1) { [...] }'. For unprivileged, this would result in only single direction always-* taken paths, and unknown taken paths being allowed, such that the former could be patched from a conditional jump to an unconditional jump (ja). Compared to this approach here, it would have two downsides: i) valid programs that otherwise are not performing any pointer arithmetic, etc, would potentially be rejected/broken, and ii) we are required to turn off path pruning for unprivileged, where both can be avoided in this work through pushing the invalid branch to the verification stack. The issue was originally discovered by Adam and Ofek, and later independently discovered and reported as a result of Benedict and Piotr's research work. Fixes: b2157399cc98 ("bpf: prevent out-of-bounds speculation") Reported-by: Adam Morrison Reported-by: Ofek Kirzner Reported-by: Benedict Schlueter Reported-by: Piotr Krysiuk Signed-off-by: Daniel Borkmann Reviewed-by: John Fastabend Reviewed-by: Benedict Schlueter Reviewed-by: Piotr Krysiuk Acked-by: Alexei Starovoitov [OP: use allow_ptr_leaks instead of bypass_spec_v1] Signed-off-by: Ovidiu Panait --- kernel/bpf/verifier.c | 44 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 566eeee5e334..2bf83305e5ab 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2812,6 +2812,27 @@ struct bpf_sanitize_info { bool mask_to_left; }; +static struct bpf_verifier_state * +sanitize_speculative_path(struct bpf_verifier_env *env, + const struct bpf_insn *insn, + u32 next_idx, u32 curr_idx) +{ + struct bpf_verifier_state *branch; + struct bpf_reg_state *regs; + + branch = push_stack(env, next_idx, curr_idx, true); + if (branch && insn) { + regs = branch->frame[branch->curframe]->regs; + if (BPF_SRC(insn->code) == BPF_K) { + mark_reg_unknown(env, regs, insn->dst_reg); + } else if (BPF_SRC(insn->code) == BPF_X) { + mark_reg_unknown(env, regs, insn->dst_reg); + mark_reg_unknown(env, regs, insn->src_reg); + } + } + return branch; +} + static int sanitize_ptr_alu(struct bpf_verifier_env *env, struct bpf_insn *insn, const struct bpf_reg_state *ptr_reg, @@ -2895,7 +2916,8 @@ static int sanitize_ptr_alu(struct bpf_verifier_env *env, tmp = *dst_reg; *dst_reg = *ptr_reg; } - ret = push_stack(env, env->insn_idx + 1, env->insn_idx, true); + ret = sanitize_speculative_path(env, NULL, env->insn_idx + 1, + env->insn_idx); if (!ptr_is_dst_reg && ret) *dst_reg = tmp; return !ret ? REASON_STACK : 0; @@ -4288,14 +4310,28 @@ static int check_cond_jmp_op(struct bpf_verifier_env *env, tnum_is_const(src_reg->var_off)) pred = is_branch_taken(dst_reg, src_reg->var_off.value, opcode); + if (pred == 1) { - /* only follow the goto, ignore fall-through */ + /* Only follow the goto, ignore fall-through. If needed, push + * the fall-through branch for simulation under speculative + * execution. + */ + if (!env->allow_ptr_leaks && + !sanitize_speculative_path(env, insn, *insn_idx + 1, + *insn_idx)) + return -EFAULT; *insn_idx += insn->off; return 0; } else if (pred == 0) { - /* only follow fall-through branch, since - * that's where the program will go + /* Only follow the fall-through branch, since that's where the + * program will go. If needed, push the goto branch for + * simulation under speculative execution. */ + if (!env->allow_ptr_leaks && + !sanitize_speculative_path(env, insn, + *insn_idx + insn->off + 1, + *insn_idx)) + return -EFAULT; return 0; } From patchwork Thu Aug 12 17:00:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 496519 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F06BC4338F for ; Thu, 12 Aug 2021 17:01:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3FF5860527 for ; Thu, 12 Aug 2021 17:01:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233901AbhHLRBc (ORCPT ); Thu, 12 Aug 2021 13:01:32 -0400 Received: from mx0b-0064b401.pphosted.com ([205.220.178.238]:22248 "EHLO mx0b-0064b401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234122AbhHLRBc (ORCPT ); Thu, 12 Aug 2021 13:01:32 -0400 Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 17CCk0Kh010817; Thu, 12 Aug 2021 17:01:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriver.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=PPS06212021; bh=ZJ+xE3ltCqvAyyGfX6QgpOxb0QbQzX8L8UcwFrooW6k=; b=c6m37/KbYHuoTaQthp2SFdO9LliNn3XK38Fck/N6MD8KAvNJ6tMmBbZbgjbB7SVfbG2Q 7PA6Ik0p8s/y8ilSDrm41z/8o4HXyBBFRnJBN+PIVVDbi4Am0oenxqaqopwXDAQM3mK2 +Z49TNre/rpQBRWNfzFNPN36JiRQPIvCf29OKIiihnkuAkB4IF/jfRhBNkOVS1B1dFfA WaCdYun1Y2k39QmfRj1FjwhFzIdk0djRruZ6nSBv9AquE+CfDAb/i8PDIqhgun3spXaj lUnX0V0t/wBYksOLRvt0mMJOcK80tOfU6ZX9sdcLnj+ggvrZr5oLBHsml/fVztznxLZl xA== Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2042.outbound.protection.outlook.com [104.47.57.42]) by mx0a-0064b401.pphosted.com with ESMTP id 3acsen0jxg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Aug 2021 17:01:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AGkL3zKIg86gMmJNNzlOGebjVNaUhp8hv8eAcVT02+GaNR/SeeSh7yBPHuzjRBwYcjaiQ4d+5bSF9wJzb8QltWxuiLj8JhPN89BJ6CDgoOgHsXC3f0WKFF9pnhq4lOUdfuIoWY+NIs9F0YXjQVKSxbt9DatK1ueKRwgbgU8fogYddhGkVnyqqjOz/XxU4w3mERZ/IzCcrxEpPzBi7TxKgWcS3RULlK0Mm6I+YSH42LDcu/6S8u4SvOkgTROQYRBq6r5ItfPtXRIc/KLZM2oNXfuFMexsR5Eb2W7uq+Nc11xEru5oRarVB+3XeNGYqp2obwGSMZbpfNVNVxzgaSHUiw== 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-SenderADCheck; bh=ZJ+xE3ltCqvAyyGfX6QgpOxb0QbQzX8L8UcwFrooW6k=; b=Pl1S/ANMZlpd31QHtAVP6dhxuJpv1Ji7cEh9mkPJO1MQvK5RRTTXhdaEvg9ro/66NKTEXFE1MeIoN1YXM73Cb5vLBzD5OqOsK4iFEYpeIBbfc/H6ustUqL2lGVzlWh+Yn5tlvau9vKcX2VNrNesbXadkiOJQyiCmEFjaBXLdfFR1kW1gYmWckfDhd04RZHbPXLQqP86CCI2gmua09L+JOt4k6jN1UcP/7gh5qfDftX6bGFvPhJpAVbMZr6AbvXsG6BJCN61eifTfNdOAOB4ljFU7mq7th7GEhTjyJmHZhf1A8ikqrZ/fXqpQYmIHQER6U5WIiZssOjU2KbLjNamzkA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=windriver.com; Received: from DM4PR11MB5327.namprd11.prod.outlook.com (2603:10b6:5:392::22) by DM5PR11MB1593.namprd11.prod.outlook.com (2603:10b6:4:6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.17; Thu, 12 Aug 2021 17:01:00 +0000 Received: from DM4PR11MB5327.namprd11.prod.outlook.com ([fe80::ccb:2bce:6896:a0c3]) by DM4PR11MB5327.namprd11.prod.outlook.com ([fe80::ccb:2bce:6896:a0c3%9]) with mapi id 15.20.4415.018; Thu, 12 Aug 2021 17:01:00 +0000 From: Ovidiu Panait To: stable@vger.kernel.org Cc: bpf@vger.kernel.org Subject: [PATCH 4.19 4/4] bpf, selftests: Adjust few selftest outcomes wrt unreachable code Date: Thu, 12 Aug 2021 20:00:37 +0300 Message-Id: <20210812170037.2370387-5-ovidiu.panait@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210812170037.2370387-1-ovidiu.panait@windriver.com> References: <20210812170037.2370387-1-ovidiu.panait@windriver.com> X-ClientProxiedBy: VI1PR07CA0251.eurprd07.prod.outlook.com (2603:10a6:803:b4::18) To DM4PR11MB5327.namprd11.prod.outlook.com (2603:10b6:5:392::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from otp-linux03.wrs.com (46.97.150.20) by VI1PR07CA0251.eurprd07.prod.outlook.com (2603:10a6:803:b4::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.9 via Frontend Transport; Thu, 12 Aug 2021 17:00:59 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 295f124a-81d3-4267-e3e9-08d95db2c2f2 X-MS-TrafficTypeDiagnostic: DM5PR11MB1593: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UA4ciA12Q2efNJa99Taolkfawk/EeykANNHQNcji1vTYq4gQugFtSD8loB02mhW3gpsjkwWEAKI5Q74qwut3kAW7gsm+Gl294Z0TdvcYhedhvPgVPvZB8V4Ox/PfD/7caBMQPJeUrVgWpZ0CQmBUeh+kzu9/wI17+GBZsHR7fEg1nDEG4xtug4MwSjJ5O/2OgSOL3h0Q5/5o6QviK+i3m/fQhKiMjiZftnA+EA2CDVHfxBoXQlbVaMb+h/63aJoTBogFwmZjq7Xow7TSRn5jimXcIA4TUImpQHN2T/rX85m3zAp9x9MJaXPqqatz/+HOiihVpT2vn42s+NBgx40q5/EsYnyusjBiCbNLINM+3LJxlBP3/5+NfpLcB+RjD7Y01AGBNBIRKtbsWZtCaZ1eU1aws7dEZhDf6ifmTPcjV8bmt1+ezaazJBxNk/O3RR2BVhSHPNPId/eA6nNzE2M0Su1HlJqajNAsHeEqerg+00oFptjQgLAyga/m563QMrTO/rtQcfeyYhsBmmtC64EeaPTlUArdyYFA6zvI2geUuRJyQHjlN0V9LEj/JpfLasoB3TZoXgNBZ3ByaVqs1+CQLQ7jf/4P4upqSHhOfA5H2C0ZfkfIoSMgM7lOKwjgQAkFUWxZap3Qrw5Ycp+22iihS/RF4mn/qRjv3VUql4tzES1I7N2yL2wZFPIt4m/LuJ/V2K8tCI5degu4rzqcNbW2+g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5327.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(39850400004)(396003)(346002)(136003)(376002)(26005)(66476007)(66556008)(8676002)(44832011)(6666004)(316002)(86362001)(2616005)(8936002)(5660300002)(186003)(6506007)(52116002)(956004)(66946007)(6512007)(38100700002)(38350700002)(4326008)(450100002)(6916009)(83380400001)(6486002)(1076003)(36756003)(2906002)(478600001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fWHJlbgU33KlX9XwzjShqYPS08grP6OweIZtnf/MTM/Nqd07VHdl8X2WNhl7ilWdLQKYAIYTvQWQQZ/SWmv+e9txC+HrfAj+lYFuc9ouN2oX7ZXPZhQmUCz2ByE9NkCO6oD0zYf3r7VDkitnMRvNnxkN/6fN9s2AQqrhDh3oP4UtO7NOsGKdCCmpemeZi/elKQ3Cilq8K73sEk0o+ri7qZryGtosdQavM4OknJwkYZkepUsQa0N1386MMvngi2BnepZ2fVq+sXpWL51QJA5d4kGIlze2vRldGFwZPqZ6fy7GgzTrPFYjDw3YLF/tmfGwMfaLVgFhzzBBB6I3teug0EPx6yEI6RSbIQL+lU4aeDapzbeWGhR6/1LXXk3h7FTZnh9QXzXnB0zGBI9p7UIofTMIA6fBnYILACBKYzqtORM7E4G+m9B2YJsJmcJwsOVY4ZbDYtvxncNoBrmUn/BVIQ49lrzvXFQL5FAjNnZcI5jRuzdA0P33fBnfV6AT+boa4JjVkkeI6kRQsXUkHkWnYYifXBL318/FEYG/b1rg4TD3jR9IPCCqOFPcO84MedV7o9koTn9fS4FfUJ4e6ncovqmBUQk+dNT8Af2SUXd0vNK+VykiPMh7in9b+j3qBOk80cAtvpxdIpafip6ZS2kPdiUzDWdGwuUzPP8TmDk3GQ5Dtpq6rZmbbgiMUxLEyjtD29fCDvsFrrcGslcUXXGgNUwqUA3uOBxxiAr1qbCrDvL6keBqa3G69e7Kbi3cR3yvRR+IOcpzV1P4I7LevErVl6IPx7oxMwpeU8J7QFUrK/pTgFuQHQ1uIBBwzXxaiTuPJR9fRuycuzsbFwwNcw/3p4Urv5UQD4mQJORxM5YAIVrQiuZSLrQLyYxUnwEnuXEzpI5FN/eRyc9f+1HaloAT13zSTjvuvPHVjeSKrd+7vsKRdKEp9hJKB/QoV63OHxZhQTNbLrQovISXqmgWJTNfY8P1N/+BdYMDzcV0sJ/onDUl3nYGn5CiNEw8VwALUQijnL31s8ZjrHHH646ANJplUGYt/eGVv8M+fb19Xw6MC+JVChYchq/150eZowb0eeogRREsscP32IFZCY57mvtKWgbXGD2mPHgYP6ztlamhGet27mjJ1zr4jSfKDQdV8iJmP5BNycSN6qj6bMIxu/Oaq7n1ysjvVrL+fnK2K+SHph+myURnUibHXkTCMpMR1evg0foG5adI58/VE8YNUDNa9dmSdH3cSli1UiaPlmu8VtY8cbdtv6tvAcGGBaY2S4TyJmWMtroCWFDh39t/zukDlG54GkIqS+MMIiEDfD7Dv/zuP3Te/AE+ntk1qBXmmxE1 X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 295f124a-81d3-4267-e3e9-08d95db2c2f2 X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5327.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2021 17:01:00.7170 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dCbrGxgj/hcvZ4qswkN+MhNpaoRa1CORivCVeBMS8LTs+WhRO0vkFu5iqny/BQxfdOMTg6HTYuxrjl/ugWNiHEJc76GllGQoB2qNg8LMW/E= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR11MB1593 X-Proofpoint-GUID: PjNnaaqoB34DD1CrtjNMvCNOAZbjGJOc X-Proofpoint-ORIG-GUID: PjNnaaqoB34DD1CrtjNMvCNOAZbjGJOc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1, Aquarius:18.0.790, Hydra:6.0.391, FMLib:17.0.607.475 definitions=2021-08-12_05,2021-08-12_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 priorityscore=1501 lowpriorityscore=0 impostorscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 bulkscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108120111 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Daniel Borkmann commit 973377ffe8148180b2651825b92ae91988141b05 upstream. In almost all cases from test_verifier that have been changed in here, we've had an unreachable path with a load from a register which has an invalid address on purpose. This was basically to make sure that we never walk this path and to have the verifier complain if it would otherwise. Change it to match on the right error for unprivileged given we now test these paths under speculative execution. There's one case where we match on exact # of insns_processed. Due to the extra path, this will of course mismatch on unprivileged. Thus, restrict the test->insn_processed check to privileged-only. In one other case, we result in a 'pointer comparison prohibited' error. This is similarly due to verifying an 'invalid' branch where we end up with a value pointer on one side of the comparison. Signed-off-by: Daniel Borkmann Reviewed-by: John Fastabend Acked-by: Alexei Starovoitov [OP: ignore changes to tests that do not exist in 4.19] Signed-off-by: Ovidiu Panait --- tools/testing/selftests/bpf/test_verifier.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index b44324530948..c7d17781dbfe 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c @@ -2792,6 +2792,8 @@ static struct bpf_test tests[] = { BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_7, 0), BPF_EXIT_INSN(), }, + .errstr_unpriv = "R7 invalid mem access 'inv'", + .result_unpriv = REJECT, .result = ACCEPT, .retval = 0, },