Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3704089imm; Mon, 18 Jun 2018 02:38:12 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLGwmnGdU2huiUdrijylSb2cZS37jt+I6c6VP/wjTUDicl4osDdTgkxB6E4eUt5+D/f0eXY X-Received: by 2002:a63:7c55:: with SMTP id l21-v6mr10544034pgn.352.1529314692692; Mon, 18 Jun 2018 02:38:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529314692; cv=none; d=google.com; s=arc-20160816; b=bcf5hmq+GGHyvbAtmrD7S4XoqXmLRd93RHz0MihxIridXpDwsPwjVjvqLcxtiCNiDz mcHC70YddOQ0UaTnZJMLCMnrBP7YC9J4AnfaHqGMVDQdIyou9zhbdB1LPWK7sRBXxfOB sBBq6rQFmJFotSf1ENfEQzIaC17g+pcjMnCauzNG7JZ0diEDDfsWKDWWdPWv0XOS5ld5 Kx9aq8IgIKHwUlgEwPWmI8QzSw7JPkddo+mOfcnld9WfFY5/NcB6VlrCUQeJLsl8EDe8 0ReYvJ+K72qginr6DTX2xvBdL1a7FQyYYMPa2eQ7j0FYJ8qRh2gRxsQP++fB3AF4qcg/ XYLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=8AYoPBBJmjLsttmPZqR0YaSdR4BSH1SJ6a9dghOhawo=; b=Xlbb0FLLYj4T8EZyCWhso+ybTQd+RzUKB8S80tpnv14LIZG9RmFXNSv/Vm5zRQl6Wc LbnWHygfQrwt9jWTc8+faRdeHI5Z9UnmOvvF4fruBBvVFn6bbbToumnd+DdXNGu0bDzg kIHwIfBKV1V0BxaHZga4jVDYAZK+VZumQ/JLdpayUTlEEOT7acDVJlpWBLHhLm4R18RI oqfR7wAHO3SlR5cy7Q4HSG4/Yi50KekyW0OLGmOysoHwqUclX7euHATAFKDT4WLxoDu6 1+/yXDl9YENm3r/MeVU92/EKvYKbOao2L/zLDF09UrILmVu1LTu/yL1VxEcpFGStO4ec WDpg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t1-v6si13992812plq.280.2018.06.18.02.37.59; Mon, 18 Jun 2018 02:38:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966126AbeFRJhY (ORCPT + 99 others); Mon, 18 Jun 2018 05:37:24 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:55850 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935917AbeFRIXk (ORCPT ); Mon, 18 Jun 2018 04:23:40 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 95D03C74; Mon, 18 Jun 2018 08:23:39 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Borkmann , Mark Rutland , Alexei Starovoitov , Sasha Levin Subject: [PATCH 4.16 182/279] bpf: use array_index_nospec in find_prog_type Date: Mon, 18 Jun 2018 10:12:47 +0200 Message-Id: <20180618080616.472099979@linuxfoundation.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618080608.851973560@linuxfoundation.org> References: <20180618080608.851973560@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Daniel Borkmann [ Upstream commit d0f1a451e33d9ca834422622da30aa68daade56b ] Commit 9ef09e35e521 ("bpf: fix possible spectre-v1 in find_and_alloc_map()") converted find_and_alloc_map() over to use array_index_nospec() to sanitize map type that user space passes on map creation, and this patch does an analogous conversion for progs in find_prog_type() as it's also passed from user space when loading progs as attr->prog_type. Signed-off-by: Daniel Borkmann Cc: Mark Rutland Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/syscall.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -872,11 +872,17 @@ static const struct bpf_prog_ops * const static int find_prog_type(enum bpf_prog_type type, struct bpf_prog *prog) { - if (type >= ARRAY_SIZE(bpf_prog_types) || !bpf_prog_types[type]) + const struct bpf_prog_ops *ops; + + if (type >= ARRAY_SIZE(bpf_prog_types)) + return -EINVAL; + type = array_index_nospec(type, ARRAY_SIZE(bpf_prog_types)); + ops = bpf_prog_types[type]; + if (!ops) return -EINVAL; if (!bpf_prog_is_dev_bound(prog->aux)) - prog->aux->ops = bpf_prog_types[type]; + prog->aux->ops = ops; else prog->aux->ops = &bpf_offload_prog_ops; prog->type = type;