Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1653632pxa; Thu, 20 Aug 2020 17:29:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7/MWldqH+jHN35xaAk0rNrrA2j63/t0vU+nL/rTjFt+PbhLMrnGjh0Y24Q/4eLFT4x6BT X-Received: by 2002:a50:fb10:: with SMTP id d16mr473070edq.134.1597969794691; Thu, 20 Aug 2020 17:29:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597969794; cv=none; d=google.com; s=arc-20160816; b=KRjifK1km0OzRZfzOfsY0HnnRzwZ14+syFDH9Y/EDRVeVDwO9b4TK5HvonIGXCbhzd yrrCaZhZKijmsNCcxRdxgM5g/NfpY/77TGh0yds6G5LFrR1Ii26MrqtJfeCxVe4434bx 7CBgw0Ky/bEyF0t/sYJe74RjYIYU9G5S+gYeSXtMnmDzD7ixt3uFCnS3BJNbsLy4IzpG yvOrHUNp/v82k8CDkWdm8hsTISZ1CdAgaNWWxizOmUezajAZUZYNeV5P3XNHj44xtEB7 6JzTKBtbBXjnruwk13bherU5rhCDDFuDeojMGfYsYOgGrJk80Vg3T1qPJ+AinvtHSMgt rNvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:smtp-origin-cluster:cc:to :smtp-origin-hostname:from:smtp-origin-hostprefix:dkim-signature; bh=/uUFrz2pplyNeuzwjVTtdWHekCwyi/O0CKqPnUBAh2Y=; b=FO8j0RAcnhochCu8DJiG5qiqQi8tbz/81vManbLlKG0u3iaCd0SfPvNFT5w+wH/tdT l9twneYeFGA/RDTe7aX555RhVrAD6MABNUbV8e/U0fxSoKVWc6ZFkrxUqnQNzvWRk4Ap ttBwxOydlx8Bmt2tVrmq7JCSy808O3dnpgxcAECr8wLEMxU1LCTVRiRmkBdoq3pMV7VH L8QsgKqzk7OziTVVvL1KaBaC2shg2RhVPBiqjZHHE/APER+sgAPrj6d7orgZqMlrAgAh vcWzjnFX3dydbAV/sBQgs9Z2HDSxY8G13pJGLRwpwV3t0XGWr9cfaPlAMPj9ftgeAaZn MIyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=hOOAhYdU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h20si72884ejy.449.2020.08.20.17.29.31; Thu, 20 Aug 2020 17:29:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=hOOAhYdU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727048AbgHUA20 (ORCPT + 99 others); Thu, 20 Aug 2020 20:28:26 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:51302 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727030AbgHUA2Z (ORCPT ); Thu, 20 Aug 2020 20:28:25 -0400 Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.0.42/8.16.0.42) with SMTP id 07L0Od3x005557 for ; Thu, 20 Aug 2020 17:28:23 -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=/uUFrz2pplyNeuzwjVTtdWHekCwyi/O0CKqPnUBAh2Y=; b=hOOAhYdUEg3OBsjRRyxwaFCjD/1f33nWqNGHwOPPwGn1LM6auWEGD2Q5necwVsEYsPO4 q498YGj0CaRMsctVXPRxRJj0h7vfVR8I+1QavTnNHFq973PtO7eeTykkAizUNG+kLgo2 TaOyb0keev+lbBQlY3GlyP1m6RZ0EdUzEw8= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0089730.ppops.net with ESMTP id 331hcbwgnc-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 20 Aug 2020 17:28:23 -0700 Received: from intmgw004.08.frc2.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::d) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 20 Aug 2020 17:28:14 -0700 Received: by devbig218.frc2.facebook.com (Postfix, from userid 116055) id 14363207539; Thu, 20 Aug 2020 17:28:14 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Udip Pant Smtp-Origin-Hostname: devbig218.frc2.facebook.com To: Udip Pant , Alexei Starovoitov , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , "David S . Miller" CC: , , Smtp-Origin-Cluster: frc2c02 Subject: [PATCH v2 bpf 1/2] bpf: verifier: check for packet data access based on target prog Date: Thu, 20 Aug 2020 17:28:03 -0700 Message-ID: <20200821002804.546826-1-udippant@fb.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-08-20_07:2020-08-19,2020-08-20 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 spamscore=0 priorityscore=1501 suspectscore=0 clxscore=1015 bulkscore=0 mlxlogscore=956 lowpriorityscore=0 phishscore=0 impostorscore=0 adultscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008210002 X-FB-Internal: deliver Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While using dynamic program extension (of type BPF_PROG_TYPE_EXT), we need to check the program type of the target program to grant the read / write access to the packet data. The BPF_PROG_TYPE_EXT type can be used to extend types such as XDP, SKB and others. Since the BPF_PROG_TYPE_EXT program type on itself is just a placeholder for those, we need this extended check for those target programs to actually work while using this option. Tested this with a freplace xdp program. Without this patch, the verifier fails with error 'cannot write into packet'. Signed-off-by: Udip Pant --- kernel/bpf/verifier.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index ef938f17b944..4d7604430994 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2629,7 +2629,11 @@ static bool may_access_direct_pkt_data(struct bpf_= verifier_env *env, const struct bpf_call_arg_meta *meta, enum bpf_access_type t) { - switch (env->prog->type) { + struct bpf_prog *prog =3D env->prog; + enum bpf_prog_type prog_type =3D prog->aux->linked_prog ? + prog->aux->linked_prog->type : prog->type; + + switch (prog_type) { /* Program types only with direct read access go here! */ case BPF_PROG_TYPE_LWT_IN: case BPF_PROG_TYPE_LWT_OUT: --=20 2.24.1