Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp125480pxa; Tue, 18 Aug 2020 18:16:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+z0rwe2vI45piVybzfX4mQKRE27UoUeA0QKuwZ6cXDJ0NVOZZYi0f5VJ8ErF70BxAEhzm X-Received: by 2002:aa7:cdd0:: with SMTP id h16mr22514057edw.116.1597799775124; Tue, 18 Aug 2020 18:16:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597799775; cv=none; d=google.com; s=arc-20160816; b=tu3eqe+QO4F1Js8/fTrwTYTsTzKRSQtUohqTzBN3G935Dz9WkBGVHB6txCWOOaDk3E ura/nwsqwEkrtwgPNPSxwvlfwB9WTKaFNFvCpauOYr8NYGa3C2INe9jhzjAX2Tdtztrj x7Gq/xJ++l4++kTf6j9lblSBBhw0/F+5eDMl1ES0DVc2pq+N953GL/aRphF0SC7XtzkG eT9Tm1hTEI4mzX2nFLksJU0M8x+3hCKBB61frg0Vqc0s1cFUBMuufSbcPnanyYMQlbyX T6iwl3qnzZ/SP6o43ruaQLlEfjfuSV6npI1BG4tij/ADPl7QYwr83qEsluKZQmNvPlL+ 07yw== 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=ohoHMRu4/bl3vpATSiy0BZNdyj3CfT6zlrtPCHwvfUKLpWQn3c1WorcKJtH7ILBBHt N5pLuw8Jao2Y1Rb8sWJv71czueD1PshdCcA/WDmaLtbGOKfbXDi/wzJLZMUfNYBwpS0B FQr6htOZuHXrTQNBHSahiMAR5tXxZCgpvI8OXp/mXIUbMN7VGSE6XdWiUrbq/XeNwBC6 Hy1vi7lxeCtvdaz9CM+H40r/05q9GcPTsHD1xMPk5i+6H3J7hCyMtiyLwuUyf1HmaHJm 8Zy13nMEj1Oz5LFRZy5uEq5lG7Gi3OJZ29BZaQOIhFB2nd1c5FxLMQHt78Q8fPdhoIe+ 4cMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=A08HzhhP; 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 k23si14015556ejg.514.2020.08.18.18.15.50; Tue, 18 Aug 2020 18:16:15 -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=A08HzhhP; 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 S1727103AbgHSBO6 (ORCPT + 99 others); Tue, 18 Aug 2020 21:14:58 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:58780 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726923AbgHSBO5 (ORCPT ); Tue, 18 Aug 2020 21:14:57 -0400 Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07J1DW85018300 for ; Tue, 18 Aug 2020 18:14:56 -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=A08HzhhPElIP8ar1HUd6SO3WoFR2zWYS304bUD3/iGH7tq16rHT9X+6i+bNksEqKJLBo tPJNPbLzpcBnIor4xYyEYi7riZWFWYvmcvYY3NG7BEl+DYk4GgNICA273F6w3AuMIU+L 3tXb3CcQoiPSbZxSgxn7eetJn3yu2L3kzDc= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 3304kpp0ep-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 18 Aug 2020 18:14:56 -0700 Received: from intmgw002.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; Tue, 18 Aug 2020 18:14:54 -0700 Received: by devbig218.frc2.facebook.com (Postfix, from userid 116055) id 4079D207458; Tue, 18 Aug 2020 18:14:50 -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 bpf] bpf: verifier: check for packet data access based on target prog Date: Tue, 18 Aug 2020 18:12:44 -0700 Message-ID: <20200819011244.2027725-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-18_16:2020-08-18,2020-08-18 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 clxscore=1011 spamscore=0 impostorscore=0 mlxscore=0 adultscore=0 malwarescore=0 mlxlogscore=896 lowpriorityscore=0 suspectscore=0 phishscore=0 bulkscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008190010 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