Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9984236ybi; Wed, 24 Jul 2019 13:32:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqxSe7ugmHN+XGMB7PoFmtM8NeLcuF0HnrVoF1kC0DvXkvWRH/7mwDhYXXTGc2aEUQDIp4gT X-Received: by 2002:a17:90a:ab0b:: with SMTP id m11mr92083646pjq.73.1564000361005; Wed, 24 Jul 2019 13:32:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564000360; cv=none; d=google.com; s=arc-20160816; b=lqMLqPriRg9i+TXgGE0BHzit7itbYA8nWPVqnQbth+2fpakiTJdstdujiuEjJPKUAg RSPw9j7PwQ6tFABBlU8SxmtWw5HXb/EvQRImHyhI4U/IGOFP6WxTfqRc0MOA0iv9RmMO h7AC2J21ImKcfzEUw4eHvAWLVA0iQwAug0y5wv2PO/JpUpA6IVBjiAgMF6m9zQDErK9Z 8ZJpUXal89WSfeEBJGLYhxuYhK8e1oV8oTCknTVvguW3J6rKi0pli/ZzTngFt6eswqxG x3ODuewgiD6ztKuw0kkAhEIaic2JXNGPeg5cIQhWdvMCCwkJEiZabSvdOeL4xptyFAsJ Dpzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=b7LbtW0A7Wl8widFuUaHh6J09rdlXepAIVg0h51Z2Qc=; b=I635G8CPQN5eqaGDYFLEFKsOJY501EJ9xXlONSe00MLOgTfqK+LuXkUNL2DAoj4AkH 1poHnD+pWkfBKmHqznn25NaCshkG4ztHkMj9v6TcdZoayDqZq4Zi0MsVFCkpzrn05fmD jEDmZasYIlKgaj7RupY195c9jFWBw/fTzQMZIY/zxT0uSd475tgq5tJUR0HMvBISYiB1 d4jUTbyKfSypvOpVdiAt3DJnUSkgN1sXMb6rRo+sVnb6QczR75yoV/GXjWrPmMzZMLW0 xR/3KdUPXGrNYR7YzD6CqXobKktH6lTkV+p0yxFIG35M1bNfe3fKIN+fNVRzXhtv5Kzs Zjdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=caZfpW8p; 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 k15si20435752pgj.216.2019.07.24.13.32.25; Wed, 24 Jul 2019 13:32:40 -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; dkim=pass header.i=@kernel.org header.s=default header.b=caZfpW8p; 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 S1728308AbfGXTbD (ORCPT + 99 others); Wed, 24 Jul 2019 15:31:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:51536 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728306AbfGXTbC (ORCPT ); Wed, 24 Jul 2019 15:31:02 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C260D21951; Wed, 24 Jul 2019 19:31:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996661; bh=B/MRkndD4KINmC0kypX/wNiPqJQbmlsj1gSgqJmCGME=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=caZfpW8p9vFU3xIYdfgiOiAg+D3YRuJpNWl1mBPxjJannJJ4ex6L9D6B0z3CU2ofA 6iRUkDslxf1XiiwrIC8TWru/702Zw8swiMBJOgCrGXk7H0mwDrApz6cgq7vUElnNfG kDmoGpkVuoH7Rt82ledq9JBdq7ONqWFzb+BaG508= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yauheni Kaliuta , Jakub Kicinski , Quentin Monnet , Jiong Wang , Song Liu , Daniel Borkmann , Sasha Levin Subject: [PATCH 5.2 174/413] bpf: fix BPF_ALU32 | BPF_ARSH on BE arches Date: Wed, 24 Jul 2019 21:17:45 +0200 Message-Id: <20190724191747.374500795@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 75672dda27bd00109a84cd975c17949ad9c45663 ] Yauheni reported the following code do not work correctly on BE arches: ALU_ARSH_X: DST = (u64) (u32) ((*(s32 *) &DST) >> SRC); CONT; ALU_ARSH_K: DST = (u64) (u32) ((*(s32 *) &DST) >> IMM); CONT; and are causing failure of test_verifier test 'arsh32 on imm 2' on BE arches. The code is taking address and interpreting memory directly, so is not endianness neutral. We should instead perform standard C type casting on the variable. A u64 to s32 conversion will drop the high 32-bit and reserve the low 32-bit as signed integer, this is all we want. Fixes: 2dc6b100f928 ("bpf: interpreter support BPF_ALU | BPF_ARSH") Reported-by: Yauheni Kaliuta Reviewed-by: Jakub Kicinski Reviewed-by: Quentin Monnet Signed-off-by: Jiong Wang Acked-by: Song Liu Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- kernel/bpf/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 080e2bb644cc..f2148db91439 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -1364,10 +1364,10 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn, u64 *stack) insn++; CONT; ALU_ARSH_X: - DST = (u64) (u32) ((*(s32 *) &DST) >> SRC); + DST = (u64) (u32) (((s32) DST) >> SRC); CONT; ALU_ARSH_K: - DST = (u64) (u32) ((*(s32 *) &DST) >> IMM); + DST = (u64) (u32) (((s32) DST) >> IMM); CONT; ALU64_ARSH_X: (*(s64 *) &DST) >>= SRC; -- 2.20.1