Received: by 10.223.176.5 with SMTP id f5csp3431448wra; Mon, 29 Jan 2018 13:05:16 -0800 (PST) X-Google-Smtp-Source: AH8x225ypx0QFf56jWiaVzROQTtd2ln+5l51V4DsLtZicmpL1dB8gk+cQ1u/qYTXAmKBOaSBN2Is X-Received: by 10.98.163.79 with SMTP id s76mr28386120pfe.67.1517259916800; Mon, 29 Jan 2018 13:05:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517259916; cv=none; d=google.com; s=arc-20160816; b=UQdrehpOIjK8aRmQemeIDM1qZ/gTkRhvZtKcCe/QbUliRcc4sQOzlqhXExjfjlhrQa /Vx1NOirQP/k7oxN0ZmQ7Rp9sw9O0APvCtrefZvd4fIP81V+Hpaa+86DVXe61ARCfnVH q3lOKeto392Q3xn8psDm2pP9BB1rRwur2V0nGqJxOkBdOc8SG1RtiFodSRBMwA32wnob ahA9l1JC8eeqEAtkDXCotf+yF7Xf7YQfphryXp6yQuofIJWbAhWJ6/FwXa28ZoLVLGbf LTHY+XMNDz77Xsd2FqXcqwFa48sA26J2hmKBZ4xeijIu0vE9pWgKJVubwY9MTluPEd50 P+Vg== 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=rhQqWGbuLT7N6JNVdxMCb2sz6j79As1VCuHUN43lMDo=; b=fuauF8FBBJjgBueJiQohUXDyFGrizq5UfTwkeHnh6jZoGWNpzJj4lMLtQ6ymt9kz+x ov1y4uW2o/7ZRgcRA4yXeIxTQMk5wKgi5/2bRx7CemG6VlSr2BKDBY9WtkX+UoMWHyrr qBPbVG5b2ttpCfLAL7rh+2/gfOPKbWZV+Ionh7iWeKsBCPFx3cvDs4m/goTplGZ1Q967 aoSs3C/VD6kZXZ3Iei5f7fkabyFYUyqsvpIWoTLvYdXfXkqPgrf+4e5vmQFnMR7miiBv zrksbNEMlt2HOe9cnl94pOwRvGsSPs3P1vHsvjtxBbI89q1v2MHJy5X0j/QaK+VLy+H2 KIYw== 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 y128si8075990pgb.55.2018.01.29.13.05.02; Mon, 29 Jan 2018 13:05:16 -0800 (PST) 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 S1752310AbeA2VEd (ORCPT + 99 others); Mon, 29 Jan 2018 16:04:33 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:51072 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752899AbeA2UHg (ORCPT ); Mon, 29 Jan 2018 15:07:36 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C13752FB7; Mon, 29 Jan 2018 13:06:54 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Eric Dumazet , "David S. Miller" Subject: [PATCH 4.9 60/66] bpf: fix bpf_tail_call() x64 JIT Date: Mon, 29 Jan 2018 13:57:24 +0100 Message-Id: <20180129123843.039553830@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180129123839.842860149@linuxfoundation.org> References: <20180129123839.842860149@linuxfoundation.org> User-Agent: quilt/0.65 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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexei Starovoitov [ upstream commit 90caccdd8cc0215705f18b92771b449b01e2474a ] - bpf prog_array just like all other types of bpf array accepts 32-bit index. Clarify that in the comment. - fix x64 JIT of bpf_tail_call which was incorrectly loading 8 instead of 4 bytes - tighten corresponding check in the interpreter to stay consistent The JIT bug can be triggered after introduction of BPF_F_NUMA_NODE flag in commit 96eabe7a40aa in 4.14. Before that the map_flags would stay zero and though JIT code is wrong it will check bounds correctly. Hence two fixes tags. All other JITs don't have this problem. Signed-off-by: Alexei Starovoitov Fixes: 96eabe7a40aa ("bpf: Allow selecting numa node during map creation") Fixes: b52f00e6a715 ("x86: bpf_jit: implement bpf_tail_call() helper") Acked-by: Daniel Borkmann Acked-by: Martin KaFai Lau Reviewed-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- arch/x86/net/bpf_jit_comp.c | 4 ++-- kernel/bpf/core.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -278,9 +278,9 @@ static void emit_bpf_tail_call(u8 **ppro /* if (index >= array->map.max_entries) * goto out; */ - EMIT4(0x48, 0x8B, 0x46, /* mov rax, qword ptr [rsi + 16] */ + EMIT2(0x89, 0xD2); /* mov edx, edx */ + EMIT3(0x39, 0x56, /* cmp dword ptr [rsi + 16], edx */ offsetof(struct bpf_array, map.max_entries)); - EMIT3(0x48, 0x39, 0xD0); /* cmp rax, rdx */ #define OFFSET1 43 /* number of bytes to jump */ EMIT2(X86_JBE, OFFSET1); /* jbe out */ label1 = cnt; --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -715,7 +715,7 @@ select_insn: struct bpf_map *map = (struct bpf_map *) (unsigned long) BPF_R2; struct bpf_array *array = container_of(map, struct bpf_array, map); struct bpf_prog *prog; - u64 index = BPF_R3; + u32 index = BPF_R3; if (unlikely(index >= array->map.max_entries)) goto out;