Received: by 10.223.176.5 with SMTP id f5csp969766wra; Fri, 2 Feb 2018 09:02:37 -0800 (PST) X-Google-Smtp-Source: AH8x226xXslMsJz1n3buX5SLnNSd57j38QpetFAM0lJafpQZWjvLjj3NoYmNz+MGplP0QLW7h0D1 X-Received: by 2002:a17:902:61:: with SMTP id 88-v6mr27139359pla.428.1517590957459; Fri, 02 Feb 2018 09:02:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517590957; cv=none; d=google.com; s=arc-20160816; b=ozbLD5VlF3hqsdAMrycVt1+5BLxG0hwdC0Xfy8UGLol4lcpfNBvc4ABw2doPJsoASo Tt8RGEWrXEjwzeVTNopx5AiiSD6axwba35No4z4dIPzeaB9nxoMXDHEbSn67YIrsMMM7 sLQ7niFLh/SdE4dyow11JAYfMWf3nTsn2Jy6fInD8bkEXC5pBctX0tuJi2YLOaBUAqVb rL32BEe6ZfFoAI/vgxeZyLsZRoW2D98Zj7/duEBG9rROLMLgsFtUUdLoja19Jtd6ofAe peFctVSnq5c6Kf6uvNlw+VOt22mLKrQkEMrBlRljUr68syuEviqwMqOWnn5Lpm5svFrM 56cg== 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=2+UPYoNLVKkHHcKNrk6iyl6rKsP0JMGyRA/93ZGXFjE=; b=C9ZjUmf0ZnLWdlQWMnZ9AVKKXk/X7US7Oj3vD2oy8Ou+QR1s+M0g5DWfvRjq4smrFj HhFg76wbIW1CSQs+axPs+frQdM/91XrudXLKbdytuqmIbwdXFJapTmc31ki553+OQqYr FjUNM+tCK1pML+YlZIQRwQ2gh3sa15aXdU3gLlf/7UxRqe4Jy5p7BPMzsrxVXGwv/A4b 79J9tKnJu5pMbu6EiMXPfPXN21H1NiafccdR2juKmewtmjDW3eqqRYpK3OPfQJI0S5Es Cs3MSrhH5zyp/lwPy1tVNj6LjnFYg4DlErU50opIXSnV/emQb4PUN2HOkcJFBaBLZ5c7 kzeQ== 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 z9si1470804pfl.34.2018.02.02.09.02.22; Fri, 02 Feb 2018 09:02:37 -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 S1752464AbeBBRB2 (ORCPT + 99 others); Fri, 2 Feb 2018 12:01:28 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:34738 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752593AbeBBRAX (ORCPT ); Fri, 2 Feb 2018 12:00:23 -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 51EB5DCF; Fri, 2 Feb 2018 17:00:22 +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.4 04/67] bpf: fix bpf_tail_call() x64 JIT Date: Fri, 2 Feb 2018 17:57:33 +0100 Message-Id: <20180202140815.700661977@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140815.091718203@linuxfoundation.org> References: <20180202140815.091718203@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.4-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 @@ -266,9 +266,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 @@ -517,7 +517,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;