From patchwork Tue Sep 8 17:57:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonghong Song X-Patchwork-Id: 261341 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=-6.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=no 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 18669C43461 for ; Tue, 8 Sep 2020 17:57:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D93B821D41 for ; Tue, 8 Sep 2020 17:57:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="bbqDHaAY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732176AbgIHR5i (ORCPT ); Tue, 8 Sep 2020 13:57:38 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:50570 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728184AbgIHR5W (ORCPT ); Tue, 8 Sep 2020 13:57:22 -0400 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.42/8.16.0.42) with SMTP id 088HvH2E007609 for ; Tue, 8 Sep 2020 10:57:21 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=facebook; bh=kM8n0ZP0Aws+jsdQw0Zf7gHq68l6vzED6c5DDHwLnZo=; b=bbqDHaAY1eKGxknTWr/u2qp4kjdD2NZjvYvuR5w4G7Wo9Zh1CsXHIIjxRQxi8ASO3btL sJcqgWRZk8ShNtJQnQRg0bmFXnbR1dgYs2zqqjVFT7SElO+Hp0zz2ZpJ9Vk4RZDdkMwp R+xNAAO9B1I6xOXA1waKxtj/qDfHcL6OhIg= Received: from mail.thefacebook.com ([163.114.132.120]) by m0001303.ppops.net with ESMTP id 33c91hdmte-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 08 Sep 2020 10:57:20 -0700 Received: from intmgw005.03.ash8.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c085:11d::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 8 Sep 2020 10:57:11 -0700 Received: by devbig003.ftw2.facebook.com (Postfix, from userid 128203) id 702673704B12; Tue, 8 Sep 2020 10:57:02 -0700 (PDT) From: Yonghong Song To: , CC: Alexei Starovoitov , Daniel Borkmann , Subject: [PATCH bpf-next v3 0/2] bpf: permit map_ptr arithmetic with opcode add and offset 0 Date: Tue, 8 Sep 2020 10:57:02 -0700 Message-ID: <20200908175702.2463416-1-yhs@fb.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-09-08_09:2020-09-08,2020-09-08 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 mlxscore=0 phishscore=0 priorityscore=1501 malwarescore=0 suspectscore=8 adultscore=0 spamscore=0 bulkscore=0 mlxlogscore=954 impostorscore=0 lowpriorityscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009080170 X-FB-Internal: deliver Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org With CORE, it is possible that the compiler may produce code like r1 = 0 // relocation instruction map_ptr += r1 ... Currently verifier does not allow map_ptr arithmetic, even for adding with 0. This patch set relaxed the condition so the above code can be accepted. Patch #1 is the kernel implementation and Patch #2 added selftest tests to cover the new functionality. Changelog: v2 -> v3: . only change hashmap subtest to use non-inline version of check_default(), other subtests still used inline version. This will provide coverage for both inline and non-inline check_default(). (Andrey) v1 -> v2: . add comment to clarify smin_val represents the const. (Andrii) Yonghong Song (2): bpf: permit map_ptr arithmetic with opcode add and offset 0 selftests/bpf: add test for map_ptr arithmetic kernel/bpf/verifier.c | 4 +++ .../selftests/bpf/progs/map_ptr_kern.c | 10 +++++- .../testing/selftests/bpf/verifier/map_ptr.c | 32 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-)