From patchwork Thu May 27 17:37:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 449453 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=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, 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 33B8DC4708A for ; Thu, 27 May 2021 17:38:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 13E94610A5 for ; Thu, 27 May 2021 17:38:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234882AbhE0RkQ (ORCPT ); Thu, 27 May 2021 13:40:16 -0400 Received: from mx0b-0064b401.pphosted.com ([205.220.178.238]:36702 "EHLO mx0b-0064b401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234478AbhE0RkP (ORCPT ); Thu, 27 May 2021 13:40:15 -0400 Received: from pps.filterd (m0250812.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14RHXKjl026033; Thu, 27 May 2021 17:38:25 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2043.outbound.protection.outlook.com [104.47.51.43]) by mx0a-0064b401.pphosted.com with ESMTP id 38tfbh81bt-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 May 2021 17:38:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W08D63ft5gu+WerWuYXQvaSBoBAVhNbDrquYKzZXsohr9xXS73t5s+nMFsBgsLMp14x3DSXE956rHnWvFLA3PZXTeMf53jdVkK398jJknlVnVUcUfFwGsPDUh0zR8fJmtRq+NBukLAcQ9XMzebs4Ficd0gFtCSEOnl4Utzi6fsjLzvTTPl+g5yD7VAH4mo5jm3AeMY39TXY2WrEqfjHedCTEoh3mtGqGRtwPF/PHa7yLTTo6yNLRv4i9rh0e1SPs72xbEDHjoaa8j3YwJ59vCMM1fqva1tsxJL6Sh8pxXXsqxkn6U5cEGxeN7bIKDQQrEzBAAWGqbZq6HtRNQWS5Ig== 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=j0bby5SxKYX4E606Iza3GDlGax7ytfNFUgUtXvYvMLo=; b=VDzTQ2+kWu5yndWE+JqGxbuEm9f/CKIJVzdWst+duslCtp9Elz1rD4hzrrU8j3sw80t0qORoheNJf/SQZkGTzo+yidHZrITw14NlwDWPRb8OGNf3zCvMlZ6uRYttwCVId3eSRnVvsiLc9ECU3FUCAHTPSaq/ov9JEH5PiwwbTaf5Kclt1Hq0I1B7m6NGuhpWOMED18hTaJiBFyLC8NSoVAuJiZyVUFbzyhgSWHvFub6VxNCvuyN2EltmfH1owSMDXNhBai5pfw9bz7+MfennX7Ru0jRMqwKzP1sW3eUP3A4gJAbVrfU925NwAsHrQ/irTvu8z7xyotX1yTsKldqn3Q== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=j0bby5SxKYX4E606Iza3GDlGax7ytfNFUgUtXvYvMLo=; b=OHMNTUO22OSl3kJnNM/L5vRzwfqBiaCxcu+704s9TQFPk2Bu7UsLdEF1tg1ujHAOAdyJyvgVe3+8UBjsMFkGw05APWAQj5tkRjsOeQ/dYDC08cwaYDStyHznmwn8QCfrC2Z3le4IM5R7JMG6y5HBXNOn9a2WcM/xVjHjQE7krus= 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 BN6PR11MB1956.namprd11.prod.outlook.com (2603:10b6:404:104::19) by BN6PR1101MB2162.namprd11.prod.outlook.com (2603:10b6:405:50::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.27; Thu, 27 May 2021 17:38:22 +0000 Received: from BN6PR11MB1956.namprd11.prod.outlook.com ([fe80::f100:256b:e0af:7d33]) by BN6PR11MB1956.namprd11.prod.outlook.com ([fe80::f100:256b:e0af:7d33%3]) with mapi id 15.20.4173.024; Thu, 27 May 2021 17:38:22 +0000 From: Ovidiu Panait To: stable@vger.kernel.org Cc: fllinden@amazon.com, bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, yhs@fb.com, john.fastabend@gmail.com, samjonas@amazon.com Subject: [PATCH 4.19 01/12] bpf: fix up selftests after backports were fixed Date: Thu, 27 May 2021 20:37:21 +0300 Message-Id: <20210527173732.20860-2-ovidiu.panait@windriver.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210527173732.20860-1-ovidiu.panait@windriver.com> References: <20210527173732.20860-1-ovidiu.panait@windriver.com> X-Originating-IP: [46.97.150.20] X-ClientProxiedBy: VI1P189CA0013.EURP189.PROD.OUTLOOK.COM (2603:10a6:802:2a::26) To BN6PR11MB1956.namprd11.prod.outlook.com (2603:10b6:404:104::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from otp-linux01.wrs.com (46.97.150.20) by VI1P189CA0013.EURP189.PROD.OUTLOOK.COM (2603:10a6:802:2a::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20 via Frontend Transport; Thu, 27 May 2021 17:38:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f15092bd-a8f8-4791-93f5-08d92136394e X-MS-TrafficTypeDiagnostic: BN6PR1101MB2162: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1148; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: skmp+qbX8Zzp/uL4fETD2MRPx0yA61oF+clIhPGlX7GclndykUN6yC7hNIyVb5dpVPjbYG2pVTEJ9+2XtAz5ZqF1vrU5tcWgpjCZhf8NGD340KFIOS5XeODm9zuOqxMw1wSeiTVjy7zwKMUo0ok61WtCnF0FyKLCfVELMH+zntnFEqNdbKR1l9DzRvt1NtXm0PA/AGA6YZzN5dFbfXyRsgIRdZSxDQzSEuhG95jW8IzHqZaUgVylKM9sLELLdYtD+X9I9/eAsKfKjd0ngHP7QuPmaw2c4vh4d/vWEaLioUOVoqaNVo7x05WK6ACq0knMauVzWM8170agVDHej2xakly++e8p04P0672DK0MebaKCSQKi6uaB+RTwnWgYIIxd2vIB1qHnAL1Ysp7Bsq0SlgKXqk1/dg/67RW19zh33oBWopRwS+tYu9/GHAeVQowoe0aACNnLsmTOV8VphrFIO+/VcOOq4lpj1LCCYGosPe3xmLAjCeR4wxQGN18pg3VqYKTBz94nj3Pk80jOsM57S6vEdorTggnv6HLRUcDYQ68GzCFIL/PrtQ4L9KAQCYE0joya4+UTucUTLw87Idv6S44cwq7ATA45LbHfyMRFwy6+JfQ+fxDoUCtW1ALvxddk4amXxsk8AcQ+UyRZO337zFb79bHPYYU6pZhheiGDS8A= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN6PR11MB1956.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(39850400004)(136003)(396003)(346002)(66556008)(86362001)(8676002)(36756003)(6916009)(26005)(83380400001)(4326008)(5660300002)(316002)(8936002)(66476007)(52116002)(6506007)(6512007)(478600001)(956004)(38350700002)(2616005)(66946007)(6486002)(186003)(44832011)(1076003)(38100700002)(16526019)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: lJV4R8Dc24UEYZrt+HPH9oJw7/ts0nFJQ0dPEhCPmYKW9kpSzYV31Upk17lfeNwszsqHDJo/Z+KE8y+ZGkQhANYfqTRP80qpkCzbfpbUYMbzQNSMPanhmShOMowNQXe/ppnY2Hl2AYoiraHJTTSplrnjU7d2TaadhgnirjTrKhNWt9wFZJMT9jEux9qXiso6+Z48NBJD/1CL+plMgPYf/teU9bPNJPIJVqO40XwfyGdmD0BHRgWK4j4RPcITprx11shqDMnewL4M6LHC49+IdmgComQJSTbNQhUjB5w5TwA9f9aHZcjBWvUHNsWVWKfODwKhZC16j3pVwv6e+fc5VpRAmCU0KPkoi6Zi0/zPmxYC8L7DEm8YGawh9AfOsqW8gpogmEXIP6Yp5wnaEJXoPBnlVvcLEPGDwCIijLuwmXGn6YCkcfpDKFUDbUwDKFFmWLNPSYxd/LkNrP1CMK7GfCbLu+GPV1RjWYa4glRZtnWlzFnyUd58dwzinEwyuJGPKCOgs073/1GirLM/8llqyEKowrafzeFf0URcq+o+as7iUttMU+8aLOYL9eEDMW6v/R++JV1WYZLdxiDbKgmWUAUPEneSN937Ymx46aKT59VI7ETfSlyZr6D2A7e+vUJpx8kR/gYgAK2ZPqu+3hxDzGgTTmGYYMuMQY0aKkvKM4V3+eykyWyGIQqmYmiXfqrF/eboBsAjNq/b6QQG/YWVzo5s2PW/tUsBqq2Jq2qwCXL96CwQhOMDwULAuD9XFNO53gUDp+d8+uSFv8bksglNqaE6kaIIhure1G86xWY3E0xmfa06K6uyvc5nqElVRlP5cFbCt768fIpgCHnh7sE7fPREqFo7v6VurPwDqFgp+KhxM3oc4JH4mqLdNHrvUCslUN1Q1mFalwgkx/UGMRw4ITPdAr3VBAzdKOzAtQq+Q2m8KhDGKaoNkcveD0IwGXyPQ/YHw3mG1DPXTkSuW/rYy0Ua/kyL00d+R/IDoDpYkTm4lmxxdXqPFotIPmYpixkfjnIZcA7iTskbvpfW+ctkxILxGL5W3eRH9iRNX+Ra9t8fPpudCQrIlNbUzurJI3FJn21n6u/fSHwU16U0cgPIzDZ1kp/e8b9AbI+QntCyiQUzhPEQrqyvErNyhOkXtF2gDUhGuJ78fvAOP845qhS5oJusVmP9BZ3sqre8MVe9CyS2T5UuHyDp9MwoMwyw479teNdVwuc/QHOyFQChGg1euUy1LXUKPKTc0w9Z5oIu95HP7yirTH0OOyjhWccXVOP6GHFnv9dg+n7RM2qZ/DaXjsaupCF8oRbWmQOKvP6/G7nRsh96dPQ6exsrG2yUaZM4 X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: f15092bd-a8f8-4791-93f5-08d92136394e X-MS-Exchange-CrossTenant-AuthSource: BN6PR11MB1956.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2021 17:38:22.4696 (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: LocyWn+8vABrld3Mtw+XAHY5k+h9RPdh1jcvgPEZ2kk8r7BkF4vY6lI1ZUKEbP4YJfazeqqVF4MwnTCiL5HdH7Gh72/ISx+YVMKJSDorlGY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1101MB2162 X-Proofpoint-ORIG-GUID: HBGJiTS-FD1nW_ZJBonFuTXNte8qh_-0 X-Proofpoint-GUID: HBGJiTS-FD1nW_ZJBonFuTXNte8qh_-0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-05-27_09:2021-05-27,2021-05-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=985 malwarescore=0 adultscore=0 spamscore=0 clxscore=1015 mlxscore=0 suspectscore=0 impostorscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105270113 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org After the backport of the changes to fix CVE 2019-7308, the selftests also need to be fixed up, as was done originally in mainline 80c9b2fae87b ("bpf: add various test cases to selftests"). This is a backport of upstream commit 80c9b2fae87b ("bpf: add various test cases to selftests") adapted to 4.19 in order to fix the selftests that began to fail after CVE-2019-7308 fixes. Suggested-by: Frank van der Linden Signed-off-by: Ovidiu Panait --- tools/testing/selftests/bpf/test_verifier.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index 9db5a7378f40..fef1c9e3c4b8 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c @@ -2448,6 +2448,7 @@ static struct bpf_test tests[] = { }, .result = REJECT, .errstr = "invalid stack off=-79992 size=8", + .errstr_unpriv = "R1 stack pointer arithmetic goes out of range", }, { "PTR_TO_STACK store/load - out of bounds high", @@ -2844,6 +2845,8 @@ static struct bpf_test tests[] = { BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, -8), BPF_EXIT_INSN(), }, + .errstr_unpriv = "R1 stack pointer arithmetic goes out of range", + .result_unpriv = REJECT, .result = ACCEPT, }, { @@ -7457,6 +7460,7 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", + .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7481,6 +7485,7 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", + .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7507,6 +7512,7 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", + .errstr_unpriv = "R8 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7532,6 +7538,7 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", + .errstr_unpriv = "R8 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7580,6 +7587,7 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", + .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7651,6 +7659,7 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", + .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7702,6 +7711,7 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", + .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7729,6 +7739,7 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", + .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7755,6 +7766,7 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", + .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7784,6 +7796,7 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", + .errstr_unpriv = "R7 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7814,6 +7827,7 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 4 }, .errstr = "R0 invalid mem access 'inv'", + .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7842,6 +7856,7 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", + .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, .result_unpriv = REJECT, }, @@ -7894,6 +7909,7 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "R0 min value is negative, either use unsigned index or do a if (index >=0) check.", + .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -8266,6 +8282,7 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "pointer offset 1073741822", + .errstr_unpriv = "R0 pointer arithmetic of map value goes out of range", .result = REJECT }, { @@ -8287,6 +8304,7 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "pointer offset -1073741822", + .errstr_unpriv = "R0 pointer arithmetic of map value goes out of range", .result = REJECT }, { @@ -8458,6 +8476,7 @@ static struct bpf_test tests[] = { BPF_EXIT_INSN() }, .errstr = "fp pointer offset 1073741822", + .errstr_unpriv = "R1 stack pointer arithmetic goes out of range", .result = REJECT }, { From patchwork Thu May 27 17:37:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 449452 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=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, 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 2B586C4708D for ; Thu, 27 May 2021 17:38:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1396F613C9 for ; Thu, 27 May 2021 17:38:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234594AbhE0RkS (ORCPT ); Thu, 27 May 2021 13:40:18 -0400 Received: from mx0b-0064b401.pphosted.com ([205.220.178.238]:39326 "EHLO mx0b-0064b401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234993AbhE0RkR (ORCPT ); Thu, 27 May 2021 13:40:17 -0400 Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14RHX824001042; Thu, 27 May 2021 17:38:29 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2040.outbound.protection.outlook.com [104.47.51.40]) by mx0a-0064b401.pphosted.com with ESMTP id 38ss3vs2pa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 May 2021 17:38:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qm/0D8jtcS94B0eBwWtSknvTwpGF9FCXD3oG/TvkviKK9EqfK724zKXCd7OJ6Mp1lSXMr81Pp9sMoIvtkUAenJi544SwhOdzXfR7KRqjrQagfbX9z3UXvGA8VwfmPXYH3ZrdjawSr+Kafmu8rD5iOukRETFckqNxzV6AAnbBpRO6BcMnDz1YhTLOE7oQIOFVX09xk+2YcVGvDtN42q8E/m+xp3eAcvERpFpxoQcpRbdvoASOuiRtODuXvHIBXXV/kIZ2Nm/4lKbywpSZSE361zbL45MF0I2pZBZmZ52CSk9S9+dFXDFlEM9yHYF1jp1Z6SkHmRQmQIg6Y3jg8T1UwA== 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=As597d2iE9g0Vbbn1Aql6UOGayyPdCiCXtOknTT2X7g=; b=GZmyZ7cc/y15eGT+KiwDU68GeIpRF8FdwPVZjwTh+rcQx6L+zDU7giddmc4P8isFygQqqa+Gug/cFRvLFWiTQinEnKrqt+81sm04C6ASLacklUzT97HUenVoArG/M43gauONKs5BVJjKNmPHx9/Jd07XHj5P/imBSHWY3m4Prg+aZwvwxzA2pyrfgTSeDzotbQig9vXc4tRG0zRTURqQHXpzYJXioChNbdin4qfEo6+M2ZqQclEB7bUdo5ykn6qWS3CDOlFg4ZYC3BqLkK7PE6SyIZwswcAfYPiAnSZtsKLM1nLuu/AmlAZNtsTam6rF0pzTBfZ9KcwKZiXB3bB4XA== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=As597d2iE9g0Vbbn1Aql6UOGayyPdCiCXtOknTT2X7g=; b=iVTcUK3Gczg+qpd/htrViUhmdIAMvGtO+wzCtBjDmlehnduv2M9rw6bCohEkgEs/uB60HzHsrgMDulXbV839233wwnuVQI+pyRcBIg2Vl4O1PGm2iFUGeKMHEvDvPvSS8oE6Tzn63q6gMO0e4oZ4ayQZ0KXido0jC7Rvo+ZCICo= 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 BN6PR11MB1956.namprd11.prod.outlook.com (2603:10b6:404:104::19) by BN6PR1101MB2162.namprd11.prod.outlook.com (2603:10b6:405:50::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.27; Thu, 27 May 2021 17:38:28 +0000 Received: from BN6PR11MB1956.namprd11.prod.outlook.com ([fe80::f100:256b:e0af:7d33]) by BN6PR11MB1956.namprd11.prod.outlook.com ([fe80::f100:256b:e0af:7d33%3]) with mapi id 15.20.4173.024; Thu, 27 May 2021 17:38:28 +0000 From: Ovidiu Panait To: stable@vger.kernel.org Cc: fllinden@amazon.com, bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, yhs@fb.com, john.fastabend@gmail.com, samjonas@amazon.com Subject: [PATCH 4.19 04/12] selftests/bpf: add selftest part of "bpf: improve verifier branch analysis" Date: Thu, 27 May 2021 20:37:24 +0300 Message-Id: <20210527173732.20860-5-ovidiu.panait@windriver.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210527173732.20860-1-ovidiu.panait@windriver.com> References: <20210527173732.20860-1-ovidiu.panait@windriver.com> X-Originating-IP: [46.97.150.20] X-ClientProxiedBy: VI1P189CA0013.EURP189.PROD.OUTLOOK.COM (2603:10a6:802:2a::26) To BN6PR11MB1956.namprd11.prod.outlook.com (2603:10b6:404:104::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from otp-linux01.wrs.com (46.97.150.20) by VI1P189CA0013.EURP189.PROD.OUTLOOK.COM (2603:10a6:802:2a::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20 via Frontend Transport; Thu, 27 May 2021 17:38:26 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 98eab8e9-b78b-4c68-8e7a-08d921363ca2 X-MS-TrafficTypeDiagnostic: BN6PR1101MB2162: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:128; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7K9gXK5E7eKhdoWSGjth6qPYF9yqYqQAVXCbQHV1RjC27bgzqjzs0tiaXFqd2hvLFnhOvXAwc4OlSq9kDM9kahTxTK/jPp9eJfSCUddl9w7GDn2kVeHanwMICYL1H+Yx0YMTn8Zb/jeFXWmyxuu/My+2USya1S8WFCwcnP19GXD1JuixGLm2CSNBMtrYUkQ+2jDmzOF5MgTNC/dFFYT0zTS1e8ZbuvPgofCgYEwn0mZSr5n8e0+qxUXZoCGilUe7kKZsNCGP6FG8TtokFTVzN94rZmUly917+g0NxOOgRzu+SoGXDasZJ4KMlA2MDAfJaMNqv5S8loInYN3mC9uXBQfpMcUVhSsFgo4IJrfs2cbMBi3oGDvgX7ltC3tb5ByUWsAx2V89CYw5c/0b2vWzY34px4LE9oAW3urBfhzmDVQkm7JQcZ5Qta+SRJBXa18yrXn+6XYXrrC1fjcB12H/tw2CXmxOiU1tUTHMK6cRyoQdj215AO9/7cPuJjSwCb/DVH/3rJaRjRxY+4Z+B6v5eTt3VWf5Y4WNLmU2w61YeVYMnCOF802+qW+TC6SDtij1kV5rr4w1+S8Q7yWM3qD0aYiYbwAPe43R/e+HSo3EWgMEinYafgIb9afO9/Ikz61DET6b7Zro08ki3BHwNjH/CQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN6PR11MB1956.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(39850400004)(136003)(396003)(346002)(66556008)(86362001)(8676002)(36756003)(6916009)(26005)(83380400001)(4326008)(5660300002)(316002)(8936002)(66476007)(52116002)(6506007)(6512007)(478600001)(956004)(38350700002)(2616005)(66946007)(6486002)(186003)(44832011)(1076003)(38100700002)(16526019)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: DZMMyEvIAK8FedgW8EkNaLX/qEJtajoA6jzUHhu1X15p+14QEQ/dhaBHi88SG4A7AJ2ZzHmgx8gils8j+9XfZdJ0I3YDJ6hGlIAUvmNsKJiB1jR2HOupnUQDUzo8bvRcW1vmbMHgTf4b0HX6PU+0AcldK9eyVo5RLN2kz943AxLszmesU6JLWdFl30xU1sclsJqAqZxmRhzzd7xmRTgqAQQxsNfhvjRKc6u66wZTaMCaLq+Ea5j9v0dgj4ytUOfBUv7n66l5Mclms7Ggi0VTCOexH7G3yHcNWCKqCN0Ws3QGq1mlXWR5UThR1DcCUuVN/9gD+AMvSzN+DCD2gZw3/U8fmEguIdhgHaFQI4VM+cEbMBrGrHAv/KilCpyAe8xIGJO/rM2Cz6Gs8+8Bu2OzHwzJavMcBqXIuGywhi8yc6oajeUtKG40QxXefCDspADHR7v9EkoTp9srWJUe+rM518dExguG1U83/cuqD9mMlvXF9fHmZqVTZUN1xATuoYvJI2J/11iXVax2FoMHo6JbX9LEMSVu4jj2d0V2p7yYUJCO9TxnOBB3T0R8hv2nxNxShMxSGQ+jJBLjW6vC2mPnnlqvYy/zfvSFJRxrewu9JVrIgFwWJgi62t+uU39BPOzi36Hp1lzhHer6kLUUz0OPTYZXwP8MIpSWyiL0kiBeIHVr3R7C//HSOOmBJaWvAV9Azap22q4igvzAdhqkJ8XOzlHATz9Fuqe3mouizz2dNT7mJtsDjlm5pLFBMcoiecoDN4Tx3NaOfUUG+5jMpfv6LIfvPC204ke/u4hGs/PsgTCwNdKf5WtqzxRZ1LUupgcLS2W5BbAw917Pq55JIq3V7uSzL9z15oW2Td+zXHVkTuxkJgiXMn5V8FRaPIOerRO8ItBeJTBO0eovIFQtcXy0Nwn5C+0evfa9AoCf1kV0eoydDG2TsbWQ0xzYkpcN6EENW0Pax/nDgr7Nxm76efLB4Ch+mxuaQSWDr3cZpbYcRGhqwIJ7hkK8eeZMjRGR8YCL5OmR+e0DiCzCkFNafaR1s17mjEOxzTPuYaMYspTAwaPK4wt+CcTyYenU2V4atFLnwnEt7wfQUhugxzrcKQqjCAuDfGtR53GKhJiJIaQBa2cxu7kXS4clHH7S+dhVTmW8l2JexsHN6UX7TwIVnEIELKr7gPCkrnKpBoLJTOyKmqrRE83JYQqtSbMFKXfciavRbATNeDjZFL5GfrVf6VxrOWpV+/ZcNS0hI1Q1WlPahNhII5RJyGSa1q7Li3DnsdOOBA7abTh6Bp2ehfUPZTpDE7e06F3s4AM217IuIFmFUZp/+LhdAyegMirsOZG1HZ0m X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 98eab8e9-b78b-4c68-8e7a-08d921363ca2 X-MS-Exchange-CrossTenant-AuthSource: BN6PR11MB1956.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2021 17:38:28.0402 (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: NvGylh5lrmc5AhtCGmWsJX+vAKf06HOdzAUKwpXDP5YLA76T9vLsIKOPF8lXHDCuAYA6+FW3dM39OiUeDAzlLWe5Us+57CX9yBZFwtjZeGw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1101MB2162 X-Proofpoint-GUID: mAG1R1LQIf12C2Rztbu7oo8LeGkHkk_u X-Proofpoint-ORIG-GUID: mAG1R1LQIf12C2Rztbu7oo8LeGkHkk_u X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-05-27_09:2021-05-27,2021-05-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 adultscore=0 impostorscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105270113 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Backport the missing selftest part of commit 7da6cd690c43 ("bpf: improve verifier branch analysis") in order to fix the following test_verifier failures: ... Unexpected success to load! 0: (b7) r0 = 0 1: (75) if r0 s>= 0x0 goto pc+1 3: (95) exit processed 3 insns (limit 131072), stack depth 0 Unexpected success to load! 0: (b7) r0 = 0 1: (75) if r0 s>= 0x0 goto pc+1 3: (95) exit processed 3 insns (limit 131072), stack depth 0 ... The changesets apply with a minor context difference. Fixes: 7da6cd690c43 ("bpf: improve verifier branch analysis") Signed-off-by: Ovidiu Panait --- tools/testing/selftests/bpf/test_verifier.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index fdc093f29818..a34552aadc12 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c @@ -7867,7 +7867,7 @@ static struct bpf_test tests[] = { BPF_JMP_IMM(BPF_JA, 0, 0, -7), }, .fixup_map1 = { 4 }, - .errstr = "R0 invalid mem access 'inv'", + .errstr = "unbounded min value", .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, }, @@ -9850,7 +9850,7 @@ static struct bpf_test tests[] = { "check deducing bounds from const, 5", .insns = { BPF_MOV64_IMM(BPF_REG_0, 0), - BPF_JMP_IMM(BPF_JSGE, BPF_REG_0, 0, 1), + BPF_JMP_IMM(BPF_JSGE, BPF_REG_0, 1, 1), BPF_ALU64_REG(BPF_SUB, BPF_REG_0, BPF_REG_1), BPF_EXIT_INSN(), }, From patchwork Thu May 27 17:37:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 449450 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=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, 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 C4052C4708C for ; Thu, 27 May 2021 17:38:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A658F613BE for ; Thu, 27 May 2021 17:38:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235246AbhE0RkW (ORCPT ); Thu, 27 May 2021 13:40:22 -0400 Received: from mx0b-0064b401.pphosted.com ([205.220.178.238]:44036 "EHLO mx0b-0064b401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235115AbhE0RkV (ORCPT ); Thu, 27 May 2021 13:40:21 -0400 Received: from pps.filterd (m0250812.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14RHXKjn026033; Thu, 27 May 2021 17:38:33 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2048.outbound.protection.outlook.com [104.47.51.48]) by mx0a-0064b401.pphosted.com with ESMTP id 38tfbh81bx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 May 2021 17:38:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f9ZUQjAb0ih1hhGUQAUlVXsB/7LHu+YYyCoiGQaTJFu4zwi0gwso3+yXa5PFA/GhKYSDAp0effnbn6APwMZevFF6wEjoO4qOz8MDKIiLBrO3+WVwdtcEGvr7VoSMNmSi37qCvjsSS5PrbMGSz8NNP5WYbRCLMHMX+DA22pZ4c34dPKsVj15lP3yV54BawVEs8vCJ4PuZueaphpTORFn1brqSiwtsxhT6YcacsxPz77yMWORBV+riEAWjvsYn8q5udKboUBLbzH3oJtAAI+z7En9SO1gXuNcx2xlWBUfDcP60KJ3vdh2d+guASUAn/VUHxvkhw0xTpgu2PT+RrEHzyA== 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=YH7N7ascT3mSxquf9afBJ3d6TXAPiM8v6/dUIgma1XA=; b=g2M2SRPi2wJAp3SBtAZkuSU/hNFodeQtxEx9sjubpAjIgmYJIa7cZQUvli9jAX3zTXf+HiyQojMZB0IS8k/HayaLRqMe4PxctvFOTI6tjUgxR8BfPsjen5gBerYq6Dq5Kcp3/P+d5tgVzXh67dHnZuCIXyTJtIhoZsfYijzOLeZl1ubE7kLpOstviC49/UTWBIZV6fpNVfF7FD8D+u2qMiHVfvXLWlyYzXc7L/Z401tVbj6bQgKsFgwTdzeVLO6AWmXdQckoUojuGNEMHR1FVfw7TzpYa0lAobnnc4sG+XSssD+lWoYzv2cBvkIjFR1cI4nVjlsoLASidlaBI/rm0g== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YH7N7ascT3mSxquf9afBJ3d6TXAPiM8v6/dUIgma1XA=; b=Q4QHiCpbULRVULJuv4oeyRhfXCVxVGvRahQHj1TQwvRIn4u+cAedce94zy/S8cSSwvHgG0jFv+Kmyib6AmWnLrviSGMYI2zNtINCZmpVNu3ivt+wT+sfXCRCMPYb4ZpBl9pJbTHtEmiYxxvk+C0dc1NcmoTSRyaw0ARpobtWu2U= 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 BN6PR11MB1956.namprd11.prod.outlook.com (2603:10b6:404:104::19) by BN6PR1101MB2162.namprd11.prod.outlook.com (2603:10b6:405:50::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.27; Thu, 27 May 2021 17:38:32 +0000 Received: from BN6PR11MB1956.namprd11.prod.outlook.com ([fe80::f100:256b:e0af:7d33]) by BN6PR11MB1956.namprd11.prod.outlook.com ([fe80::f100:256b:e0af:7d33%3]) with mapi id 15.20.4173.024; Thu, 27 May 2021 17:38:32 +0000 From: Ovidiu Panait To: stable@vger.kernel.org Cc: fllinden@amazon.com, bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, yhs@fb.com, john.fastabend@gmail.com, samjonas@amazon.com Subject: [PATCH 4.19 06/12] bpf: Ensure off_reg has no mixed signed bounds for all types Date: Thu, 27 May 2021 20:37:26 +0300 Message-Id: <20210527173732.20860-7-ovidiu.panait@windriver.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210527173732.20860-1-ovidiu.panait@windriver.com> References: <20210527173732.20860-1-ovidiu.panait@windriver.com> X-Originating-IP: [46.97.150.20] X-ClientProxiedBy: VI1P189CA0013.EURP189.PROD.OUTLOOK.COM (2603:10a6:802:2a::26) To BN6PR11MB1956.namprd11.prod.outlook.com (2603:10b6:404:104::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from otp-linux01.wrs.com (46.97.150.20) by VI1P189CA0013.EURP189.PROD.OUTLOOK.COM (2603:10a6:802:2a::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20 via Frontend Transport; Thu, 27 May 2021 17:38:30 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 71bca934-4c93-47a5-7d9f-08d921363ee0 X-MS-TrafficTypeDiagnostic: BN6PR1101MB2162: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: M+5amRRD+wJAMEvwxxclOCrT90U8Zess3ib8XxUCZ7Fce4ytfEbIKo5sEjDBP7YWw0UKPp1v4CeotPouirhHnubQcq4DA3QdnK+wVqELsCop5j2uVEr8NKvobDISSawNtmuz2tVxzVrcI2g/IRLf+ejOJFoJ/uZpSKqR3suMnyeDMA6R3nPdgQSmWhoi/pWdoPQeJzeoqI8BKGWfDWIU2PHlV62Hr/o5bvny18q9h0Od7kMsljlGBNec6ZbE5prbsphLIyka1zPV3sD+PSaNPJNvlcLpINQGsJ3tIMbssSeLBO5SQzUxTloqbJeKWy/6OYv+NBcSM4fAl/BJ+/oOhJqp8//Yzkswes2VGmcdj9n3GHyMW4aUYlHiniTy9ZcOHfcZjf0aA95QT+rPvYt6eChyHupLzMrzBSO5mFcPuM54gAJ7cdBxVr24GOkL22+cwm86801LuqtqWhsoI5qJkLJGKTeTy6W0FwP/ZMrEZyyVXnVvGvsZNHbCaNar3SzGKb1wDonq0zQ21CehTH2dikNpdESdru89r3EIwDqDHPG8gS8ZMIw+PxDDaZ/rqhAdurTM4ad6MgmNm2tnE13mISBG4H6d7TkpwxccN2N+Fq9GC9S/yrwn+N9YuBlBSX6EmOQAYI4EGrDMzzCb0bNEQYLnuR7YAzoruP+kGzgShDI= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN6PR11MB1956.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(39850400004)(136003)(396003)(346002)(66556008)(86362001)(8676002)(36756003)(6916009)(26005)(83380400001)(4326008)(5660300002)(316002)(8936002)(6666004)(66476007)(52116002)(6506007)(6512007)(478600001)(956004)(38350700002)(2616005)(66946007)(6486002)(186003)(44832011)(1076003)(38100700002)(16526019)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: a/Q20X8PQJIHlJqt9ViIsI01Hs9KSXydeLBqh1BsikbiymEnWJxX+9eVgMox6xKf/N46cDaB/HxmzM7Z5o9vVxEBi7y9N0H/SGR8fXJqplSv095ExLW2wSHZjgTypjCeBDNjvVxljSmMWmnOYxQ7IzaBWfb/84cokTu9pr00j58Xmsvj54XSlOGeqeFN2VKunV7524127Ck/R7Qf0qi3F4B+zxE8lBippcbD4SrZy1+V8dr0aq+k1MxL3UJFOni+qhwIxvKDUySaXTVWSKDMXB8rNtEdQ21r3BDoRRohpdZmxoNomEf3YjrIbQ+tWrNkyHGJ3Lm/amRTp2xRpWBEaxt7tgS/1zkocz9qIytSrSVhsYtMWiumSbvU3wr810VXDKjg9Bqja5mAWM1ciala9HcIfcwTOd/I0rTwfr/i27SKOx9/47wT/sigsAUvGqgPBfTzhZTb9mxGJZmVeCfsUE4b34l5nh6PamxDn/TanDV6Kkc/EBgZovyNDn429rc0Wdh25LhbSSpkZoRCxLOrVmyrucngUviGJBntTSwflL34Aatt+QSxo+v78VWAdAT5MXWf/BOJPgKPDrCUHNunB+eN/yxiK7FYuHgZcpJVOm/Be8PT9fzxe3GrzbHhv3vjZQxIWlTywHktHoU05KmGxukk11L5h/AvSriGqCI5gVIquXDRsUmb+jCySrdAFkVm5i7zhFUEE5QzNBqGa6UFAc9sUkSGWx2bPGv/Sae/f/R/Xa5KBIbn4i9qXvUyb4ym4ye5XdRzuh74NRfurvvoNP4abZDegQ6DwVIFveUpYMxai8L9YSWYht13xThhY7GJ/wzct3J0Xs48p1kCyjfUGC2q7xZ+cP9Yd4GyrRW1M2dSu+4ORxgxep6kGVjB7p+7W1uvVMO1WbhyK+K2xmpcDmxDnyNq/LPJ0sAybdLnUwU5WsSREzrU2DFyjwzPThftI/hKQkCixgyyvNugYjKGmEq/4c9mR2AaFetG5EXAnuVYBbuylXKemZm+A6rhp4IPLI04z7/O35CBWlrtc77dQrK2TnfpvepYrARIQKUbOvKkDWlTr7N+/X7N3Nf18rieGCX4IW7AaDIwWW8RmSJDXvm+7HoQXVszvyDZXpn1jdGI4H1bEs3R2gpK70BM+C81/X70KvuaRVawo/rGPrHsEkSklQMcshZq54ClglosCb/BV3RQFk6PT+Qlv4G4VkLw8IszEQIZuMfQL6UVAAVhbAqIQbNd3yAjyVsKUbPbVRlA41x4yK58293+9hiRqzxXWDJe8SqSMJwOAUhFBVL4DWEG7x4HW1yrT8asmbit6APQuceECGEZNM/9NUCEm9fA X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 71bca934-4c93-47a5-7d9f-08d921363ee0 X-MS-Exchange-CrossTenant-AuthSource: BN6PR11MB1956.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2021 17:38:31.8425 (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: SEh20vdv8JAVpiKneiMuvM85Y7UZEgoxclFSwMXeQrykgYVbpvbQhtFqnpyuSdK6xCn/pVwmUH4rp+q9s7H9KagpnHdpcRgUAtRa0ccBMBI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1101MB2162 X-Proofpoint-ORIG-GUID: S_bThrzegktHAeL9yEs_uxn7gBUnOFJy X-Proofpoint-GUID: S_bThrzegktHAeL9yEs_uxn7gBUnOFJy X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-05-27_09:2021-05-27,2021-05-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 spamscore=0 clxscore=1015 mlxscore=0 suspectscore=0 impostorscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105270113 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Daniel Borkmann commit 24c109bb1537c12c02aeed2d51a347b4d6a9b76e upstream. The mixed signed bounds check really belongs into retrieve_ptr_limit() instead of outside of it in adjust_ptr_min_max_vals(). The reason is that this check is not tied to PTR_TO_MAP_VALUE only, but to all pointer types that we handle in retrieve_ptr_limit() and given errors from the latter propagate back to adjust_ptr_min_max_vals() and lead to rejection of the program, it's a better place to reside to avoid anything slipping through for future types. The reason why we must reject such off_reg is that we otherwise would not be able to derive a mask, see details in 9d7eceede769 ("bpf: restrict unknown scalars of mixed signed bounds for unprivileged"). Signed-off-by: Daniel Borkmann Reviewed-by: John Fastabend Acked-by: Alexei Starovoitov [fllinden@amazon.com: backport to 5.4] Signed-off-by: Frank van der Linden Signed-off-by: Greg Kroah-Hartman [OP: backport to 4.19] Signed-off-by: Ovidiu Panait --- kernel/bpf/verifier.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 5e0646efac6d..b260bcc7215f 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2730,12 +2730,18 @@ static struct bpf_insn_aux_data *cur_aux(struct bpf_verifier_env *env) } static int retrieve_ptr_limit(const struct bpf_reg_state *ptr_reg, - u32 *ptr_limit, u8 opcode, bool off_is_neg) + const struct bpf_reg_state *off_reg, + u32 *ptr_limit, u8 opcode) { + bool off_is_neg = off_reg->smin_value < 0; bool mask_to_left = (opcode == BPF_ADD && off_is_neg) || (opcode == BPF_SUB && !off_is_neg); u32 off, max; + if (!tnum_is_const(off_reg->var_off) && + (off_reg->smin_value < 0) != (off_reg->smax_value < 0)) + return -EACCES; + switch (ptr_reg->type) { case PTR_TO_STACK: /* Offset 0 is out-of-bounds, but acceptable start for the @@ -2826,7 +2832,7 @@ static int sanitize_ptr_alu(struct bpf_verifier_env *env, alu_state |= ptr_is_dst_reg ? BPF_ALU_SANITIZE_SRC : BPF_ALU_SANITIZE_DST; - err = retrieve_ptr_limit(ptr_reg, &alu_limit, opcode, off_is_neg); + err = retrieve_ptr_limit(ptr_reg, off_reg, &alu_limit, opcode); if (err < 0) return err; @@ -2871,8 +2877,8 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env, smin_ptr = ptr_reg->smin_value, smax_ptr = ptr_reg->smax_value; u64 umin_val = off_reg->umin_value, umax_val = off_reg->umax_value, umin_ptr = ptr_reg->umin_value, umax_ptr = ptr_reg->umax_value; - u32 dst = insn->dst_reg, src = insn->src_reg; u8 opcode = BPF_OP(insn->code); + u32 dst = insn->dst_reg; int ret; dst_reg = ®s[dst]; @@ -2909,12 +2915,6 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env, dst); return -EACCES; } - if (ptr_reg->type == PTR_TO_MAP_VALUE && - !env->allow_ptr_leaks && !known && (smin_val < 0) != (smax_val < 0)) { - verbose(env, "R%d has unknown scalar with mixed signed bounds, pointer arithmetic with it prohibited for !root\n", - off_reg == dst_reg ? dst : src); - return -EACCES; - } /* In case of 'scalar += pointer', dst_reg inherits pointer type and id. * The id may be overwritten later if we create a new variable offset. From patchwork Thu May 27 17:37:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 449451 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=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, 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 6AA3BC4708B for ; Thu, 27 May 2021 17:38:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 516AF613C9 for ; Thu, 27 May 2021 17:38:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235168AbhE0RkV (ORCPT ); Thu, 27 May 2021 13:40:21 -0400 Received: from mx0b-0064b401.pphosted.com ([205.220.178.238]:43416 "EHLO mx0b-0064b401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234993AbhE0RkV (ORCPT ); Thu, 27 May 2021 13:40:21 -0400 Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14RHYLcp002811; Thu, 27 May 2021 17:38:35 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2043.outbound.protection.outlook.com [104.47.51.43]) by mx0a-0064b401.pphosted.com with ESMTP id 38ss3vs2pc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 May 2021 17:38:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=huWDhGyT+M1BbUSig4sasnjaKdWAqtNhly9c7rt5v1s88DL4//8pn2hI+a9hkwl+AavluBxKOR3d3K0RZR2tOCrRH13ImkvRavYhm4YNDHzPNxTyYfpa7ZhoNwA7khViJnl1JAdJrUyzV6YTXoAkOkCT+sXOc6WKfhrifEEH4C4bmbxzmqm84PONOFMEeW+bptBubI8OPOG3g4sPGb6zkM7jr2vTcRIWwplTwRe47BJpvw/wcmm7/Ea1OGTGtqNYrR3rvw9hkcoUcDi4ocVPxKjjPHyLSoSTUJ7cD1IIuhSoElhkjVg1sGwzXg5C4Mq26HSbqLp5k52vaEkxQJI6ug== 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=q6z1PdUgU1fapwbrqA9OmI9Fv9O7dDsi+A9ru3voJ+s=; b=l07iqtYblYSOSBC2hPzPY0oiDJgxSkDH4KnnY0eR4o+u1qdu18Q7MAJ8gF1+iS/b68TiyowVx87ocnzeiwROhWThzy6gHcYduJaIjofyZoAD4YIz8pnBwWcDyqu9Q7h3NpG9vnNe+uVwnPvlP2SB/Vfvvbj/AB//1qfGm4erYERG7ayTTDYwVZCXqYl+44ZDyaoMiDNr6FNts3hvSX7Cbu0Rt5+8V13PYhrduoVbZp1nwPhjN805nv6cKxGtum8ON6P6DmG9n8p/AmWdAq8bC5yvoScrGr33hkbL7eZSxO5aPJc2PCysKAGzSijVUc7mpa1sabMnNkiAc+3sb0KHiw== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=q6z1PdUgU1fapwbrqA9OmI9Fv9O7dDsi+A9ru3voJ+s=; b=UAFTujr6+qGL/RR0iTs+G0g596tbilHd/zTKlkEpwOUa5r/GRZNOYGosK2FOPXiHVsaa1rjo23jr5S7MLIO3bM8zu1kDCaqMXLqyZBjprt09PGeWxbefChaNBCYt49yXNvwOpS+ZIAFZoqiqV5ECIQOmjfm93+ifGRRLl6z+ZI0= 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 BN6PR11MB1956.namprd11.prod.outlook.com (2603:10b6:404:104::19) by BN6PR1101MB2162.namprd11.prod.outlook.com (2603:10b6:405:50::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.27; Thu, 27 May 2021 17:38:33 +0000 Received: from BN6PR11MB1956.namprd11.prod.outlook.com ([fe80::f100:256b:e0af:7d33]) by BN6PR11MB1956.namprd11.prod.outlook.com ([fe80::f100:256b:e0af:7d33%3]) with mapi id 15.20.4173.024; Thu, 27 May 2021 17:38:33 +0000 From: Ovidiu Panait To: stable@vger.kernel.org Cc: fllinden@amazon.com, bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, yhs@fb.com, john.fastabend@gmail.com, samjonas@amazon.com Subject: [PATCH 4.19 07/12] bpf: Rework ptr_limit into alu_limit and add common error path Date: Thu, 27 May 2021 20:37:27 +0300 Message-Id: <20210527173732.20860-8-ovidiu.panait@windriver.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210527173732.20860-1-ovidiu.panait@windriver.com> References: <20210527173732.20860-1-ovidiu.panait@windriver.com> X-Originating-IP: [46.97.150.20] X-ClientProxiedBy: VI1P189CA0013.EURP189.PROD.OUTLOOK.COM (2603:10a6:802:2a::26) To BN6PR11MB1956.namprd11.prod.outlook.com (2603:10b6:404:104::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from otp-linux01.wrs.com (46.97.150.20) by VI1P189CA0013.EURP189.PROD.OUTLOOK.COM (2603:10a6:802:2a::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20 via Frontend Transport; Thu, 27 May 2021 17:38:32 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f045a226-a667-47f8-775e-08d921363ffe X-MS-TrafficTypeDiagnostic: BN6PR1101MB2162: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:400; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yMt4/j9x7vrgGo7eska7PCdCmD021pTMBR670SIm6+SZVd1rKeMgaZH5Cc4L9LhDHQ+e7ZWW8iUI38/wfwpIwlwzPPok8kygINSAAQT4P3bB4pf7Yl5Wrrz9V/z43p7XrYU4DJPTuiNKaAzbeqyhcwvCL7xfCd2vxIYq9W+y3iB91MON/+WuxBgSe07/dCQ1RMEp8R8hsvzCI42q/HStFOsx65NIiPrdu953mAQP70eD58RJCNbbrcWIuw/oGV4eue5he6/r5fka437WRV9kdCWJK5CPIlTAOvLK0C/2xIRb5uHEItBeFYCbWbTHaOphcs9kvPAkYZMjH3HG0Cf/t4BR9PzK1988RjrtJFDrzT0wZvZBxx8UHRtKiD1gkIzrMi2WAftR1UKozfw9hROXtS6cs7/V0MFMnou40tJ4epHlPVMr546GVGwG7UNetjbD6SKv9tEZJ1wvecqAnpHJfDqGKtgMRcH6kIszfIZKDBXk4QdRDj2G9FNDNIqmmSuKVZXYONx/TONhIYLDfbDoFOGHt1JK5fAHwntzT+z+E7n26sV2+t/+vbj82IdQe3PtXqONWK/Z7N1qHyIAUluwytzMC56ksv/Um1twSBLyo8T307nfLf/7ZINl45+ImdNW+smzOCPq12gT+ZxdZzbmUYCbOdZVonFEr1aB9+En8Ig= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN6PR11MB1956.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(39850400004)(136003)(396003)(346002)(66556008)(86362001)(8676002)(36756003)(6916009)(26005)(83380400001)(4326008)(5660300002)(316002)(8936002)(6666004)(66476007)(52116002)(6506007)(6512007)(478600001)(956004)(38350700002)(2616005)(66946007)(6486002)(186003)(44832011)(1076003)(38100700002)(16526019)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 7OTxyEkD8ZXuXlRjTUFsHCbbtCuBWC83FF9YqSvxWQV1Rp7HSwFVSzRKKZFfcvIDWI6auwd25x0jUDpoT0PoLLWGd8LQg63J5Umw0tIjK7LN7MRXYboNX8nG8MuyQKoDddf5mYd9xg6RvXksAv1jDmwWhV/60mbrKnxIoLhKHei6UQ5xIucbAATjucH7TZb4Qbo5CWu/Lrxi2qHuLG4Nu2/cHIdPAmxp7tXyM+4B2j5aItGcJJC/062QKDTQZtfKI2A+FRV+lvzvdBnNWETtO+fOcAn+oqSf32+6+yphjerBfKkuK0rrT0G0qaicvIM6a19WsffYuMlnwW7EwvFnJrwdNOYeBQIwlKOGk6WC6bI+bPa6qKzWwXCtLCXa9wUeBqcWUzUz0T9Z9Lb2ITtjLZyB4u2vt9Dg+zpc+00GzYNTDQyaoXLKR8oyBiGS1o9O2cvRhDVkAbN0WzqmXMjoCQePbIqK5IStaYKNuDckK4kg1S1TqzDOdVZqGNGOhxl2rZmFxOV38Hwp8u0ATmz5Wo6QvIJqnbC5hR8Rz/kZmVIdefzaB+PA8dlFtgkjjxB0c9iUjgM3zHxZtqA1Qdmzg/RY6MyFbTmLxOo7PVDBv/xKIpY2Fe2R8gOcpu3u0JMPXNbPKUuz9tcjnDzOpAtXJMxJ2/ev6LeGbJQnFlLIcvW1EHHNxq7dtV5ZqLZIhTrN4qRnewDL5J5qqGFGXjUy/ReRWVKCI1dORUAWQNdZgsK5AWzukX+l+zhe1HjO7v0TUD9gAwr8N6VujZWhREGTV3s3MszE1+HDKrfRaMM9UTvGJ2wuTFoCauyHxQn47qhGZdDu2QE/05zcF4/3z20emIoBGz1FwiDfDnK2oEpt57+9AAHNSI9ZfY7dBgnIk7ZASnige9uxuG2ghfES4wVWEW1u9WyOdSwUtCK/98g2Uf8OsIu0ph3q5DPcc9sFLYdbRPwhjuEeh+22SmQqt1mC/+G5m3EULR4npdvuYNqILvSXdChKglsor9lJMzEVo5rcvIv/oREjiBA8Goug3uuBqTodYnKQYqhYK2iNFToxh6qiOwQy5zwpp10UIWdITvHmhCefMpX8rqSoiqOWnzbvypgWoXPfwlPPI+uOy1nN9VRE5IB/kfi97wQfno+Wg7VpQ4dkR6uOnjNVSkNvj72JpRlmN8rLNKFNzbaAFYgvcUUX0hFx8jxk6mnw1RfOOztXhHFa1nrjzBbuhit/eQ3ROYoAJlj88jKCbDSub9hGH6JOTNC3o3LknDo4Yt1WgUG/o+cCUIJlIosCHrwCGJyJwCnfpPyyx5OHHYz9mJxIDo/58VCVkk9VzGhIKqK3huzk X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: f045a226-a667-47f8-775e-08d921363ffe X-MS-Exchange-CrossTenant-AuthSource: BN6PR11MB1956.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2021 17:38:33.7186 (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: PWYuzI+cs7mKj51W/P5oVeapu9VwddOzIklwNv5VzP24be8Daxbm6CvVDo2oDr4pl9Wf90iVXuoWzkSHJA3CTO6G77Kdvy1zPgGfEdvJBPU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1101MB2162 X-Proofpoint-GUID: ClX34uu-vsxIyoavFGCIGer84uRGtVvH X-Proofpoint-ORIG-GUID: ClX34uu-vsxIyoavFGCIGer84uRGtVvH X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-05-27_09:2021-05-27,2021-05-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 adultscore=0 impostorscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105270113 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Daniel Borkmann commit b658bbb844e28f1862867f37e8ca11a8e2aa94a3 upstream. Small refactor with no semantic changes in order to consolidate the max ptr_limit boundary check. Signed-off-by: Daniel Borkmann Reviewed-by: John Fastabend Acked-by: Alexei Starovoitov Signed-off-by: Greg Kroah-Hartman [OP: backport to 4.19] Signed-off-by: Ovidiu Panait --- kernel/bpf/verifier.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index b260bcc7215f..12db86ebede9 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2731,12 +2731,12 @@ static struct bpf_insn_aux_data *cur_aux(struct bpf_verifier_env *env) static int retrieve_ptr_limit(const struct bpf_reg_state *ptr_reg, const struct bpf_reg_state *off_reg, - u32 *ptr_limit, u8 opcode) + u32 *alu_limit, u8 opcode) { bool off_is_neg = off_reg->smin_value < 0; bool mask_to_left = (opcode == BPF_ADD && off_is_neg) || (opcode == BPF_SUB && !off_is_neg); - u32 off, max; + u32 off, max = 0, ptr_limit = 0; if (!tnum_is_const(off_reg->var_off) && (off_reg->smin_value < 0) != (off_reg->smax_value < 0)) @@ -2750,22 +2750,27 @@ static int retrieve_ptr_limit(const struct bpf_reg_state *ptr_reg, max = MAX_BPF_STACK + mask_to_left; off = ptr_reg->off + ptr_reg->var_off.value; if (mask_to_left) - *ptr_limit = MAX_BPF_STACK + off; + ptr_limit = MAX_BPF_STACK + off; else - *ptr_limit = -off - 1; - return *ptr_limit >= max ? -ERANGE : 0; + ptr_limit = -off - 1; + break; case PTR_TO_MAP_VALUE: max = ptr_reg->map_ptr->value_size; if (mask_to_left) { - *ptr_limit = ptr_reg->umax_value + ptr_reg->off; + ptr_limit = ptr_reg->umax_value + ptr_reg->off; } else { off = ptr_reg->smin_value + ptr_reg->off; - *ptr_limit = ptr_reg->map_ptr->value_size - off - 1; + ptr_limit = ptr_reg->map_ptr->value_size - off - 1; } - return *ptr_limit >= max ? -ERANGE : 0; + break; default: return -EINVAL; } + + if (ptr_limit >= max) + return -ERANGE; + *alu_limit = ptr_limit; + return 0; } static bool can_skip_alu_sanitation(const struct bpf_verifier_env *env, From patchwork Thu May 27 17:37:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 449449 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=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, 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 443BAC4707F for ; Thu, 27 May 2021 17:38:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2850B613C9 for ; Thu, 27 May 2021 17:38:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235361AbhE0Rk1 (ORCPT ); Thu, 27 May 2021 13:40:27 -0400 Received: from mx0b-0064b401.pphosted.com ([205.220.178.238]:50078 "EHLO mx0b-0064b401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235348AbhE0Rk1 (ORCPT ); Thu, 27 May 2021 13:40:27 -0400 Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14RHYLcq002811; Thu, 27 May 2021 17:38:38 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2045.outbound.protection.outlook.com [104.47.51.45]) by mx0a-0064b401.pphosted.com with ESMTP id 38ss3vs2pe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 May 2021 17:38:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EfX0Ok1XDvVwH9V/7fmPgc5jqiQNjKqPzmfsGbDh/q+9h7Et5qqjnqn4i83uCH8V9HNEV6Vyk/QZw3/jvSe+enEyL+l+/Y/DazGFrYwNJUuLIc7nBxNQ76IECnyw1RZfSMmpQfZvaLX+kI5EBOb3cfKTuVatojU5qU4RA92VC/qY25Jbbw/vTWcHThm3reQE58KeJ4um9OKb82UKLCkNvqpXaIhU0AOq7g55nKkqCd9B/ueQhcI9FQvRb8aUXftBHN+51EW1EO+M7A62UfZo1NWHE5l/f59FAbE0YJLDLvOBNwA/nhps6JikjznZFHG7Q5AnFkU4BRSLm1jd7MrjuQ== 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=STqgmlW23g/TEhNuubyIzEAm9GPzKeA7DhGno33dz8w=; b=brTq2No6M7cv704rQ2YZCCEhQF+EbRnohYQODRSjcMWkSdE/A/MuCU/qqDq1ohqhPwTYZOFLCDnJWfUmJ/p4yZL+XB2Mq3VCRq55qh1VaTkpOuCm3+a7DmYxUCySjAgl4bdCxMWBgvskZfD5qnY/x3E8Qszw644HR5f36DSL47XZiXpMqGL1Ks6LJ9PlI5EWgA9+K32LeaM+Ruv6gU4mx3snKjeZSdEWAWxEOVaSu4dz6XQHs0RV1dhubbMR4zCL0UFd7aGLRGevGitcK0UFIolCmJ+B08NPt4CLNlZe8A2oqIwdQqWa+YQXUoY25702oEkW3DEEVyjLruG11jV1pQ== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=STqgmlW23g/TEhNuubyIzEAm9GPzKeA7DhGno33dz8w=; b=GBBm19l1DGogUXhWMktHYZhmgswW25TCAGP08k/UXv1Kf7upxqW0mMD/duVXsAQ1ucUzqg/c/LaTmfcz4+aWtqtKOzoqib1vB8tGFJkF1sUfzVpQiPrGLxSOW2r5B3XSvWYEU/MbGO29SFk3t08Jb2yAYJKOxqahdTKw3CYeI0Q= 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 BN6PR11MB1956.namprd11.prod.outlook.com (2603:10b6:404:104::19) by BN6PR1101MB2162.namprd11.prod.outlook.com (2603:10b6:405:50::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.27; Thu, 27 May 2021 17:38:37 +0000 Received: from BN6PR11MB1956.namprd11.prod.outlook.com ([fe80::f100:256b:e0af:7d33]) by BN6PR11MB1956.namprd11.prod.outlook.com ([fe80::f100:256b:e0af:7d33%3]) with mapi id 15.20.4173.024; Thu, 27 May 2021 17:38:37 +0000 From: Ovidiu Panait To: stable@vger.kernel.org Cc: fllinden@amazon.com, bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, yhs@fb.com, john.fastabend@gmail.com, samjonas@amazon.com Subject: [PATCH 4.19 09/12] bpf: Refactor and streamline bounds check into helper Date: Thu, 27 May 2021 20:37:29 +0300 Message-Id: <20210527173732.20860-10-ovidiu.panait@windriver.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210527173732.20860-1-ovidiu.panait@windriver.com> References: <20210527173732.20860-1-ovidiu.panait@windriver.com> X-Originating-IP: [46.97.150.20] X-ClientProxiedBy: VI1P189CA0013.EURP189.PROD.OUTLOOK.COM (2603:10a6:802:2a::26) To BN6PR11MB1956.namprd11.prod.outlook.com (2603:10b6:404:104::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from otp-linux01.wrs.com (46.97.150.20) by VI1P189CA0013.EURP189.PROD.OUTLOOK.COM (2603:10a6:802:2a::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20 via Frontend Transport; Thu, 27 May 2021 17:38:35 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: af49e69d-64da-405b-0fe8-08d921364237 X-MS-TrafficTypeDiagnostic: BN6PR1101MB2162: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2958; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aJjejAODikMBuotV6uDI6Gnb/TITJ4fd+P+nfsGnRJOtQF9jn33/6jdfbUe9XETiaDmNlPrOAMTCAkW5HzGtidTDN9++XBpnQFbslbwj0yxE0TLoZDheoYuI6mJULYSWNazgs5gq/qW6GYK7cJvNwmgPDA3T8SvZg/Pm7RxZOx7RwA2QOQFIil9dWViwr+eaFW2qUyG9RcH//VzvKx1uTgVU/nMatMnqvajXYm7MF2KDjuK5wpf7zRYWBQ9UdbrKt/B+AA8fr9vOuQr9/YfF4D8r1+U5auk6U/xksxhtUHZXCFve0AdzfSlmkzlM4OiwDnh8Z6zAqtZHya6SkpYChUDqVaQuPjkQ1YD6A3lEL1AGZe43+QFWMUCwUDLXd//+zTMnRlvo0XMXoWpS8lat6PRXSG45qJyIplQhdtduX+GTUmaHOTRr5zoUcLxBGtDDzlnfolY1IDwmvJTAJkZeCrS6mA0HEzmS7mptx1ZymCD3/v3tQF76iotjI0cSnzktKORnfRr9KiSUulyP3mKLqiOiD3TV8n6nucmGUgxvqCPY5ENcVfKpaiDZr//ZbeCTTAvXWl8E6r1CZhlnK68Q0ZMuxSvVppc2rt/ll2oHw8P//QKKnq75Ya5c+6Qe+2iBzYvTSNgsEAr/7rovyOWZ4Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN6PR11MB1956.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(39850400004)(136003)(396003)(346002)(66556008)(86362001)(8676002)(36756003)(6916009)(26005)(83380400001)(4326008)(5660300002)(316002)(8936002)(6666004)(66476007)(52116002)(6506007)(6512007)(478600001)(956004)(38350700002)(2616005)(66946007)(6486002)(186003)(44832011)(1076003)(38100700002)(16526019)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: QCGxK3bSplCq0QWKkFxzbhiVG0nAYCP6n0aMEd57ftG9QziZcszftiADdIHCvl4Rat56epZFzJBQ++eBU1QK2KyyxEU4cFUlCBzkOBedscklGI6wPzmolg8H4wDG77RWcwmwcSUAl60aaqLe9go4gRnFg2H814E38n5PbOUNrHcl0IQADfKJWG7Ujr63ZFD5E6f6K6eufFa8xsAfxy4snTzWMDjasXQ6wYbd4RRmUUtL/uPTA+A62v6B+zj6s3Bifit/pBxJhNPSkXIHYZsKOn/V5TyN/flJz4WDw+Zs243crOL6bF6nIOcM4u9pLQn0IfTkcuHwMJQrThxa4MZgA4TrWnOqNBwTuVaXW1RQbAtXYbhCAZ447iBs0Rf8gIg28mDLhbPfr6V6MMgpYJHrrr8WQnxNKzPvsGuXx492BEb/2brvMU6tLKq3le8hiDLEzormRdoJ3vY9xrhqhrMTZGywI1XJvB2S7wnfJO7cC0VP50sAwWwxUHlBLw6yvqAT8amFpdKcTqYuAGsw7D8ww5csd5hoC1JOFYlq3s7EY42xhTamVFz/RC307G/papsHAV3a4sy0j06BEGA4j6blFW7zdpqDJ72qKonLnsj2APcwdfFNp0UdwZYZP8Z3pwiIsLPA9rVdeBNtHJNoP7+485B2miFUMdM8eTqj1pHcpvB2sLDxeEZZVZ+hziGRLv5j9Vg1QFWncBJuAmpfnvAM4iZDaWNiOEdi8zzMbFv+mMXiV8bJaWEFKpV+n//qrCo1a66A/clGHCxxlZhhirEtnEIgHpHtn8uu+/stuYOyAphbQZKUyJQ6O6kX6Lx2eHO5hVGr/8nXTiMBXtS4ruvGlYDW4C67fPJ1PIdPpZQue/2h7tWWGMVk4UOGxZ6FxeYK6q15sZRlaQduwPl0VjsBvW7oamelxLbsEC9uCuF3Ljd70O4PfG1oT/5YocKDLBRHaNz1FMU4XodvUxwoTESXtaYhd5huCdAyxO8vgVgfVo8SqKgUNUusOPwLplXAy8MjyE28LxpchMSabYh90Y0Ya6DeWwtrZg7SQF1ZkWrHGXujZMBwKUQ8+z5ucdmLAE3OSLG5i4EkF0jyfNvbn+ESdxj6UtLQBc6ZeSz13yCq74WvHBijfR9bFEDGCA91T17v3eNyEXag4uZOSmcVqAl5/YhgHQ0c4m2Km6HWANJQ+BPug7zXVagJ0/JZ00/1BT/O0I4VmS+4Tw5QyLqpk5+HK8eVYD7x1jCYfJZ+xcVT/vSJVjahXOTCm7jY4FOoxFrWz+DRAvWtyVA8PWLHUfOqhYzCm1wtB44UWDIy/U/xmINGkuGtP1sgXvtT5s2dVAxP X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: af49e69d-64da-405b-0fe8-08d921364237 X-MS-Exchange-CrossTenant-AuthSource: BN6PR11MB1956.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2021 17:38:37.4100 (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: m8i1yV+RnZvGHc1I7OgvKX9BZLOaixvgvEo5OPJO7nph373MZLFUgeC7rGN+hYjnrak0t6wlOPNFYMML3s3IshiP3aoRwJ2y+TRp1UcFj0k= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1101MB2162 X-Proofpoint-GUID: CvaVxmqsTyCrXnt52HB-WW21O9IYWZOI X-Proofpoint-ORIG-GUID: CvaVxmqsTyCrXnt52HB-WW21O9IYWZOI X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-05-27_09:2021-05-27,2021-05-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 adultscore=0 impostorscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105270113 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Daniel Borkmann commit 073815b756c51ba9d8384d924c5d1c03ca3d1ae4 upstream. Move the bounds check in adjust_ptr_min_max_vals() into a small helper named sanitize_check_bounds() in order to simplify the former a bit. Signed-off-by: Daniel Borkmann Reviewed-by: John Fastabend Acked-by: Alexei Starovoitov [fllinden@amazon.com: backport to 5.4] Signed-off-by: Frank van der Linden Signed-off-by: Greg Kroah-Hartman Signed-off-by: Ovidiu Panait --- kernel/bpf/verifier.c | 54 +++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index cb79307a3aa0..b2fe044dc6bb 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2911,6 +2911,41 @@ static int sanitize_err(struct bpf_verifier_env *env, return -EACCES; } +static int sanitize_check_bounds(struct bpf_verifier_env *env, + const struct bpf_insn *insn, + const struct bpf_reg_state *dst_reg) +{ + u32 dst = insn->dst_reg; + + /* For unprivileged we require that resulting offset must be in bounds + * in order to be able to sanitize access later on. + */ + if (env->allow_ptr_leaks) + return 0; + + switch (dst_reg->type) { + case PTR_TO_STACK: + if (check_stack_access(env, dst_reg, dst_reg->off + + dst_reg->var_off.value, 1)) { + verbose(env, "R%d stack pointer arithmetic goes out of range, " + "prohibited for !root\n", dst); + return -EACCES; + } + break; + case PTR_TO_MAP_VALUE: + if (check_map_access(env, dst, dst_reg->off, 1, false)) { + verbose(env, "R%d pointer arithmetic of map value goes out of range, " + "prohibited for !root\n", dst); + return -EACCES; + } + break; + default: + break; + } + + return 0; +} + /* Handles arithmetic on a pointer and a scalar: computes new min/max and var_off. * Caller should also handle BPF_MOV case separately. * If we return -EACCES, caller may want to try again treating pointer as a @@ -3118,23 +3153,8 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env, __reg_deduce_bounds(dst_reg); __reg_bound_offset(dst_reg); - /* For unprivileged we require that resulting offset must be in bounds - * in order to be able to sanitize access later on. - */ - if (!env->allow_ptr_leaks) { - if (dst_reg->type == PTR_TO_MAP_VALUE && - check_map_access(env, dst, dst_reg->off, 1, false)) { - verbose(env, "R%d pointer arithmetic of map value goes out of range, " - "prohibited for !root\n", dst); - return -EACCES; - } else if (dst_reg->type == PTR_TO_STACK && - check_stack_access(env, dst_reg, dst_reg->off + - dst_reg->var_off.value, 1)) { - verbose(env, "R%d stack pointer arithmetic goes out of range, " - "prohibited for !root\n", dst); - return -EACCES; - } - } + if (sanitize_check_bounds(env, insn, dst_reg) < 0) + return -EACCES; return 0; } From patchwork Thu May 27 17:37:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 449448 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=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, 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 4F57AC47089 for ; Thu, 27 May 2021 17:38:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 31EF9613BE for ; Thu, 27 May 2021 17:38:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235371AbhE0Rkb (ORCPT ); Thu, 27 May 2021 13:40:31 -0400 Received: from mx0b-0064b401.pphosted.com ([205.220.178.238]:56562 "EHLO mx0b-0064b401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235205AbhE0Rkb (ORCPT ); Thu, 27 May 2021 13:40:31 -0400 Received: from pps.filterd (m0250812.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14RHZk0c027371; Thu, 27 May 2021 17:38:44 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2045.outbound.protection.outlook.com [104.47.51.45]) by mx0a-0064b401.pphosted.com with ESMTP id 38tfbh81c2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 May 2021 17:38:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gKRSeGndwmETLJreGjA4X3vEKi8WAwMJjI21EJVyeNO4VtcVoSnA+U+d/ijUK0Bim4A8CzhB2E3iHaKGUdHMjqpFwJrJrSSxuOUH4oa46XOj5a4ODv3LaRtYb0dPTwdK9Vo8aHblLmJXlNv65PmNEIqBcAKtzYDsgzGBkMXbhabM/xRDsAhJFdxB/s0hV7tvAHRFA8GTL7CLInm56dALU+AOGf0y0u3bfV8o9hd2SW8hdmoyxqloWkhjU5YaiuhBUUE6X9RN62lMboJH7OYuxxTZROlGd+1kICF2xfaT7R6/vfToKArWKBFedwXVJg/+df2eV1aGt+9N4cfUokQe4Q== 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=JtaiXxOhCP9UCk/fdVIFV2RwWeMlRCPtTeBpaoQxgjE=; b=JcT/lDI3wnLAJi6jMV372Ux4WnNREEb659HrQlkQ7n9gyvU6TXttDM1DDwIuh28kV4SL8ubpQ3eiYYP3qRQb9gD1Gk+3/EhpYozejEetU/ZxXZ4rzjChzVZ8J2Z2zyl+vqgRJ/kthvnnowFx17I4V02fwmdjL2Vx13IC/A/tnbhMDivEFv14wFVopR2R0HFlJN5ma3jHB4io8/SX3+KQvhCvIlK+n8YInJHb/fLtk7upLdq/wN+U1mXLYnsqgZcNfh9pC6iGL81rFwi9zvx5BogVSElQ5EelGwCEl4a7TOhH1e7YKfapQSY/1VFzlQsLwbsUU9OQQ2TSMPRsbmE0DA== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JtaiXxOhCP9UCk/fdVIFV2RwWeMlRCPtTeBpaoQxgjE=; b=TMj2b4UJT0u0tIPvxvLMZVF4aleJCmYXTmenH1EV0gFSTnSnhqOe64NOAmsjgBELWCr2+esCbannJ3MtnbhgytvVhltgaNhEqvhN66TstYUYUcBp6RFWiJEQJeCzVJTsvujC/ctSG7Ordjn1BpwdR74D8IHnVguKgIfZWrkAAXM= 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 BN6PR11MB1956.namprd11.prod.outlook.com (2603:10b6:404:104::19) by BN6PR1101MB2162.namprd11.prod.outlook.com (2603:10b6:405:50::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.27; Thu, 27 May 2021 17:38:43 +0000 Received: from BN6PR11MB1956.namprd11.prod.outlook.com ([fe80::f100:256b:e0af:7d33]) by BN6PR11MB1956.namprd11.prod.outlook.com ([fe80::f100:256b:e0af:7d33%3]) with mapi id 15.20.4173.024; Thu, 27 May 2021 17:38:43 +0000 From: Ovidiu Panait To: stable@vger.kernel.org Cc: fllinden@amazon.com, bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, yhs@fb.com, john.fastabend@gmail.com, samjonas@amazon.com Subject: [PATCH 4.19 12/12] bpf: Update selftests to reflect new error states Date: Thu, 27 May 2021 20:37:32 +0300 Message-Id: <20210527173732.20860-13-ovidiu.panait@windriver.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210527173732.20860-1-ovidiu.panait@windriver.com> References: <20210527173732.20860-1-ovidiu.panait@windriver.com> X-Originating-IP: [46.97.150.20] X-ClientProxiedBy: VI1P189CA0013.EURP189.PROD.OUTLOOK.COM (2603:10a6:802:2a::26) To BN6PR11MB1956.namprd11.prod.outlook.com (2603:10b6:404:104::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from otp-linux01.wrs.com (46.97.150.20) by VI1P189CA0013.EURP189.PROD.OUTLOOK.COM (2603:10a6:802:2a::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20 via Frontend Transport; Thu, 27 May 2021 17:38:41 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 07a92cb5-0364-4540-c4d0-08d92136458f X-MS-TrafficTypeDiagnostic: BN6PR1101MB2162: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:785; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qlH+HHiElaogx7DI59zB1BdUrtfFhBHrxAKvOrgPHOrkrdYt7eZEjnSN9Ym+5hACP2h4N4fadRBnu7fSf0sD/orqoBB9OWyOluFKoHRBrZwWYT7NkYzeFL/Lq+W6Q70awpgjNWoSzmfOLhbhO3vTSUEufV2JVc3ugv7LTfMFqvGZz5y6Vm1Dn+AChUHWFJpSNp5R12Ou8/YHlqiz9liD9vrr9FxHkWcfXgcbA6/UIkJhllFx8spFVqApA+3jFPrKBsHO6h4KbV395EcUL88gnOUDXBAUwh1RQqIoaovEc/GG4fUqtvGG3JpJ0XaBVKJO4EVncFrZ8GxRHifjNwzRbimeIXLWZG0paD6kfjZwKtDJASY51lVvr4F2DnIS/AGXEiIq6Z+7h16mXEQiFnf94oYfespGS9gxuLEjJrrQnHiV3kOi+nOJGoTRuym5ZlnWcvC4eTZAJPpWdK6zFyqou3IqXwjRde9kKFekn4NvBpW9hPngHkSEL+HuDtf+TgpU5M+1jd6fmzqQXnNvDompOld7Ahrw4yQ3fTWjGA5KwZ1sUR812oAScibjhKN/yytcBCpYyyN7l7DdReWkUc0UfMqmdGcMfU6A4KRcESY8FAANE8gJFBE6oA+T3o0FiFhBwKPfHGtNiyJ+edrbL3OPEw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN6PR11MB1956.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(39850400004)(136003)(396003)(346002)(66556008)(86362001)(8676002)(36756003)(6916009)(26005)(83380400001)(4326008)(5660300002)(316002)(8936002)(6666004)(66476007)(52116002)(6506007)(6512007)(478600001)(956004)(15650500001)(38350700002)(2616005)(66946007)(6486002)(186003)(44832011)(1076003)(38100700002)(16526019)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: O0HI/vJhoEu1HhXjPwUyH4qwnX71tiqeTV+krOkZrjSJl4qySNN7Moz0tw0VVEsbbpOViayk5XQZWsc8ox/HIoi6oI3LBa8EddLKf4keCnyrU+P9Vw0C+5QJA6XSvwJMfnPN9hiZ7bhhmwWXpwUZlP48/VQo/IBEDKKpQR5x9+6bm1j0RZGr9TcmIdfNM+30V9uLNvZWoExTzqUdjrzO2v+cB7hQcYFEUpZnoYFdIxHkt3xbOL/aaGPYuyEzDJkEnSa4TPUJqwwK1lLHHXQQz2Yq7WQ4lXctkhwvxv6saNHDhUZLkvgjJ94JbwmDF1CDqGfSo5FkyecaASKYnBQrcfOAba/z2zJDA/mjGO5Y+YFhhx6QhsksNH/G2ogILSofnLXRmOHry3sy7eb2oBkROGYY4nCmTY9nYAYUetSfqrBGVrtkr+OU0c/ebP9iib85Er6L9G0e2aEXSKGs1gxAWt030ZCt9sjokJux4lYzUVR1XxGb7vv05tgDDNAA9xQgDm7OIFs/lnzMWMsL5R4rLB10P+4LY6Rg1Cgmp6g1RQ/eiHEGZwi94DBJ/W3HJWAOsGzkUfslny9K3w/D+SJq6V5cgpp3UloTuMNjNff+NpMDL0eFltEt/U0VRstt7p9V6HTKz0ZXT9NhJQI05CRUNz4p8K4RDImsw/blJ+qO2yA6XoljDs2d0xGIiM0oJUntdv4ScanlbJZ0leV4sDwThabl1DDIy66oiO5bpU6BhPIXj9ho7LdawkOO7wbnNIhz24RXUtlzSC6JI/4w+hi6WBICFjyfulyv8Y1nyAsjPp8f1KLh/DwsczcZ6aF2FnP9U9/g/yjpwyeaNUjM/59G8S+8kFegLqDc96as92TDTf/7OWunMSUwfmwvRxvD0d0jJM+Wp6dQM7LtoHrphR+8YwShlOjL1uEk+itF5xpIOws4C8UGa+H2qxiXRhwD+Dl6997+7IBKKsUf1AE+JyEVFuQugfgjV0OZ0Fh3ngPf02xk+hzsA2RNgX/w3cCf9CKmTYJLlFtZj8Ol2RZB4PSYlLpgcBQYcVIrzoH6luFm8uUb2ViHmQC3wSoM3EzshvSjoYi/rEv1vMVo74/5Pn+l0WwE8mJUfwC6QWBndc26LaneutRLZV48u+dEA1tWeojK04eyPCWnMujXrH/PmP2cJGCV8tUq7cg/3x18XX92ZzTvCDFFiPATR8lMQK6OT/JvmO5cLpsy9Oqwfg2IQ/9ioIllzokeH8S8CCCEZhuIHFk+gRZqTRC8hRbTJVyLlm1fP3VPic0HgLAYx3tZqKpuiSKsruljUxFq9RRAJYmTQ50lkZqRLNCRRibhcZy34Hra X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 07a92cb5-0364-4540-c4d0-08d92136458f X-MS-Exchange-CrossTenant-AuthSource: BN6PR11MB1956.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2021 17:38:43.0335 (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: t/rAqcUtqgfbLQHC7ju4MutUviXn5ptuLu7/u+U1lHJghnosESk09dlecEm7BiyUiCrc1SLp4fBbolq5M4q2FYHQOu73GuQ1hrmUSBDzyV4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1101MB2162 X-Proofpoint-ORIG-GUID: tDLO8lLZYHVtbDe4UY0jW-lVGUaK-uks X-Proofpoint-GUID: tDLO8lLZYHVtbDe4UY0jW-lVGUaK-uks X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-05-27_09:2021-05-27,2021-05-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 spamscore=0 clxscore=1015 mlxscore=0 suspectscore=0 impostorscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105270113 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Daniel Borkmann commit d7a5091351756d0ae8e63134313c455624e36a13 upstream Update various selftest error messages: * The 'Rx tried to sub from different maps, paths, or prohibited types' is reworked into more specific/differentiated error messages for better guidance. * The change into 'value -4294967168 makes map_value pointer be out of bounds' is due to moving the mixed bounds check into the speculation handling and thus occuring slightly later than above mentioned sanity check. * The change into 'math between map_value pointer and register with unbounded min value' is similarly due to register sanity check coming before the mixed bounds check. * The case of 'map access: known scalar += value_ptr from different maps' now loads fine given masks are the same from the different paths (despite max map value size being different). Signed-off-by: Daniel Borkmann Reviewed-by: John Fastabend Acked-by: Alexei Starovoitov [OP: 4.19 backport, account for split test_verifier and different / missing tests] Signed-off-by: Ovidiu Panait --- tools/testing/selftests/bpf/test_verifier.c | 35 +++++++-------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index a34552aadc12..770f4bcc965c 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c @@ -2873,7 +2873,7 @@ static struct bpf_test tests[] = { BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, -8), BPF_EXIT_INSN(), }, - .errstr_unpriv = "R1 tried to add from different maps, paths, or prohibited types", + .errstr_unpriv = "R1 stack pointer arithmetic goes out of range", .result_unpriv = REJECT, .result = ACCEPT, }, @@ -7501,7 +7501,6 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", - .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7526,7 +7525,6 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", - .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7553,7 +7551,6 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", - .errstr_unpriv = "R8 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7579,7 +7576,6 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", - .errstr_unpriv = "R8 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7628,7 +7624,6 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", - .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7700,7 +7695,6 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", - .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7752,7 +7746,6 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", - .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7780,7 +7773,6 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", - .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7807,7 +7799,6 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", - .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7837,7 +7828,6 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", - .errstr_unpriv = "R7 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7868,7 +7858,6 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 4 }, .errstr = "unbounded min value", - .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, }, { @@ -7897,7 +7886,6 @@ static struct bpf_test tests[] = { }, .fixup_map1 = { 3 }, .errstr = "unbounded min value", - .errstr_unpriv = "R1 has unknown scalar with mixed signed bounds", .result = REJECT, .result_unpriv = REJECT, }, @@ -9799,7 +9787,7 @@ static struct bpf_test tests[] = { BPF_ALU64_REG(BPF_SUB, BPF_REG_0, BPF_REG_1), BPF_EXIT_INSN(), }, - .errstr_unpriv = "R0 tried to sub from different maps, paths, or prohibited types", + .errstr_unpriv = "R1 has pointer with unsupported alu operation", .errstr = "R0 tried to subtract pointer from scalar", .result = REJECT, }, @@ -9814,7 +9802,7 @@ static struct bpf_test tests[] = { BPF_ALU64_REG(BPF_SUB, BPF_REG_1, BPF_REG_0), BPF_EXIT_INSN(), }, - .errstr_unpriv = "R1 tried to sub from different maps, paths, or prohibited types", + .errstr_unpriv = "R1 has pointer with unsupported alu operation", .result_unpriv = REJECT, .result = ACCEPT, .retval = 1, @@ -9827,22 +9815,23 @@ static struct bpf_test tests[] = { BPF_ALU64_REG(BPF_SUB, BPF_REG_0, BPF_REG_1), BPF_EXIT_INSN(), }, - .errstr_unpriv = "R0 tried to sub from different maps, paths, or prohibited types", + .errstr_unpriv = "R1 has pointer with unsupported alu operation", .errstr = "R0 tried to subtract pointer from scalar", .result = REJECT, }, { "check deducing bounds from const, 4", .insns = { + BPF_MOV64_REG(BPF_REG_6, BPF_REG_1), BPF_MOV64_IMM(BPF_REG_0, 0), BPF_JMP_IMM(BPF_JSLE, BPF_REG_0, 0, 1), BPF_EXIT_INSN(), BPF_JMP_IMM(BPF_JSGE, BPF_REG_0, 0, 1), BPF_EXIT_INSN(), - BPF_ALU64_REG(BPF_SUB, BPF_REG_1, BPF_REG_0), + BPF_ALU64_REG(BPF_SUB, BPF_REG_6, BPF_REG_0), BPF_EXIT_INSN(), }, - .errstr_unpriv = "R1 tried to sub from different maps, paths, or prohibited types", + .errstr_unpriv = "R6 has pointer with unsupported alu operation", .result_unpriv = REJECT, .result = ACCEPT, }, @@ -9854,7 +9843,7 @@ static struct bpf_test tests[] = { BPF_ALU64_REG(BPF_SUB, BPF_REG_0, BPF_REG_1), BPF_EXIT_INSN(), }, - .errstr_unpriv = "R0 tried to sub from different maps, paths, or prohibited types", + .errstr_unpriv = "R1 has pointer with unsupported alu operation", .errstr = "R0 tried to subtract pointer from scalar", .result = REJECT, }, @@ -9867,7 +9856,7 @@ static struct bpf_test tests[] = { BPF_ALU64_REG(BPF_SUB, BPF_REG_0, BPF_REG_1), BPF_EXIT_INSN(), }, - .errstr_unpriv = "R0 tried to sub from different maps, paths, or prohibited types", + .errstr_unpriv = "R1 has pointer with unsupported alu operation", .errstr = "R0 tried to subtract pointer from scalar", .result = REJECT, }, @@ -9881,7 +9870,7 @@ static struct bpf_test tests[] = { offsetof(struct __sk_buff, mark)), BPF_EXIT_INSN(), }, - .errstr_unpriv = "R1 tried to sub from different maps, paths, or prohibited types", + .errstr_unpriv = "R1 has pointer with unsupported alu operation", .errstr = "dereference of modified ctx ptr", .result = REJECT, }, @@ -9895,7 +9884,7 @@ static struct bpf_test tests[] = { offsetof(struct __sk_buff, mark)), BPF_EXIT_INSN(), }, - .errstr_unpriv = "R1 tried to add from different maps, paths, or prohibited types", + .errstr_unpriv = "R1 has pointer with unsupported alu operation", .errstr = "dereference of modified ctx ptr", .result = REJECT, }, @@ -9907,7 +9896,7 @@ static struct bpf_test tests[] = { BPF_ALU64_REG(BPF_SUB, BPF_REG_0, BPF_REG_1), BPF_EXIT_INSN(), }, - .errstr_unpriv = "R0 tried to sub from different maps, paths, or prohibited types", + .errstr_unpriv = "R1 has pointer with unsupported alu operation", .errstr = "R0 tried to subtract pointer from scalar", .result = REJECT, },