From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x224ZBKvsM01z105qSoNN2D/XOvPt3+FCwS3fAl9pXtix+F7HNzGi7PObw7Q64aG4+Yc/lJhU ARC-Seal: i=1; a=rsa-sha256; t=1517256457; cv=none; d=google.com; s=arc-20160816; b=ue82yNCFsCy14qaO68x61Y6cqlWu7Q46AuF4PXZEjQ41Cy7lb2eyENblS2E3AViaC0 YW6WFbQm9nQ5VZ1rWuwOqAjmf10oEN74ZebeZEn9okClEzhExN9JGs+4tXnDUAqxZof1 Sg+jD9zLWjZNHOhPq6G5CPAkb5q3z7va3Kta/FvtXm2knELpzSpX+CPV8Ot+RfEhIkAY tcINClX6jQvNZaCGYhWTCn31y7lutLbWdLLi9PnMKK/pZT2pB0fMZJ8266A2fT8W+PaG 2IQhJ0E/ztrjLkVurK3AYJb3w4j6mEuz97eJvlqQvCixpWpGy5ZFr9kqmLii0UUNIzXr 6TmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=rhQqWGbuLT7N6JNVdxMCb2sz6j79As1VCuHUN43lMDo=; b=ivn+VM/Nqz5mY+MYykm07WUdB1VoJmrY/aiq3fVNqbZjQqE2w2/5CK2aYVQmSNAcNA /Yx8J5bEiylBbzUkQW5sQlnlouUvEaD4ardKJPcCsFjt/8vxdsKN0onM5ik6m2Ra1dIF JTDs3vleaxq7+nLsquVjIG/gemWWRC2UhYGl8BgILWWmMaG/JkqylZnIQ4vI4HL4vzQD 94EJ5EAsDrYnAnQYq/5jIqlx7QXrwIVxSrLVuTzdGAs9x2DKqRXrgb/GQSUqY8IQIDoW 2nN+ArZUpwOAQo8/DGmhgyGAnLIKYT74kgPSHZPUct1s1m+8qRCmpT6mIXedkmKDPDL2 Cf+w== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-LABELS: =?utf-8?b?IlxcU2VudCI=?= X-GMAIL-THRID: =?utf-8?q?1590958707351984083?= X-GMAIL-MSGID: =?utf-8?q?1590958707351984083?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 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;