From: Lawrence Brakmo Subject: [PATCH bpf-next v8 04/12] bpf: Only reply field should be writeable Date: Tue, 23 Jan 2018 23:57:54 -0800 Message-ID: <20180124075802.1522053-5-brakmo@fb.com> References: <20180124075802.1522053-1-brakmo@fb.com> Mime-Version: 1.0 Content-Type: text/plain Cc: Kernel Team , Blake Matheny , Alexei Starovoitov , Daniel Borkmann , Eric Dumazet , Neal Cardwell , Yuchung Cheng To: netdev Return-path: Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:57212 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752411AbeAXH6N (ORCPT ); Wed, 24 Jan 2018 02:58:13 -0500 Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w0O7rSZG024947 for ; Tue, 23 Jan 2018 23:58:13 -0800 Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2fpgq1rq06-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Tue, 23 Jan 2018 23:58:13 -0800 In-Reply-To: <20180124075802.1522053-1-brakmo@fb.com> Sender: netdev-owner@vger.kernel.org List-ID: Currently, a sock_ops BPF program can write the op field and all the reply fields (reply and replylong). This is a bug. The op field should not have been writeable and there is currently no way to use replylong field for indices >= 1. This patch enforces that only the reply field (which equals replylong[0]) is writeable. Fixes: 40304b2a1567 ("bpf: BPF support for sock_ops") Signed-off-by: Lawrence Brakmo --- net/core/filter.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index 0cf170f..c356ec0 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -3845,8 +3845,7 @@ static bool sock_ops_is_valid_access(int off, int size, { if (type == BPF_WRITE) { switch (off) { - case offsetof(struct bpf_sock_ops, op) ... - offsetof(struct bpf_sock_ops, replylong[3]): + case offsetof(struct bpf_sock_ops, reply): break; default: return false; -- 2.9.5