From patchwork Fri Sep 4 19:49:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonghong Song X-Patchwork-Id: 1357822 Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=fb.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=fb.com header.i=@fb.com header.a=rsa-sha256 header.s=facebook header.b=AVWGPPNi; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BjpCP5ZWMz9sSJ for ; Sat, 5 Sep 2020 05:49:05 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726317AbgIDTtE (ORCPT ); Fri, 4 Sep 2020 15:49:04 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:5362 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726135AbgIDTtE (ORCPT ); Fri, 4 Sep 2020 15:49:04 -0400 Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 084JiS25019773 for ; Fri, 4 Sep 2020 12:49:02 -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=C54RzPYh0WcdtnHkSujzfGk55J7PC3BFeV3fyo30ulg=; b=AVWGPPNi8G6y9WSSFyqXXXmz6PmjUF9RVvaG7cqSj/Rco2ViKjqNCY4nLZU0h2lr3ZGH 0A5of2XsVBjkQsdzQNuyy7MsR7rBX4bUDUjM6SFMjfchNfUQb19uB181NYR9omlhCebw t/53NfNbtM464sKQm4ecHM5+/VOznGQqEt8= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 33b99qn4m8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 04 Sep 2020 12:49:02 -0700 Received: from intmgw005.03.ash8.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::e) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 4 Sep 2020 12:49:01 -0700 Received: by devbig003.ftw2.facebook.com (Postfix, from userid 128203) id B2A0D3704C1B; Fri, 4 Sep 2020 12:49:00 -0700 (PDT) From: Yonghong Song To: , CC: Alexei Starovoitov , Daniel Borkmann , Subject: [PATCH bpf-next 0/2] bpf: permit map_ptr arithmetic with opcode add and offset 0 Date: Fri, 4 Sep 2020 12:49:00 -0700 Message-ID: <20200904194900.3031319-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-04_15:2020-09-04,2020-09-04 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 impostorscore=0 suspectscore=8 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 lowpriorityscore=0 clxscore=1015 malwarescore=0 mlxlogscore=718 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009040171 X-FB-Internal: deliver Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@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. 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 | 3 ++ .../selftests/bpf/progs/map_ptr_kern.c | 4 +-- .../testing/selftests/bpf/verifier/map_ptr.c | 32 +++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-)