From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBD4CC06511 for ; Wed, 3 Jul 2019 09:50:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CF278218A3 for ; Wed, 3 Jul 2019 09:50:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727017AbfGCJuD (ORCPT ); Wed, 3 Jul 2019 05:50:03 -0400 Received: from www62.your-server.de ([213.133.104.62]:51416 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726434AbfGCJuD (ORCPT ); Wed, 3 Jul 2019 05:50:03 -0400 Received: from [88.198.220.130] (helo=sslproxy01.your-server.de) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1hibtd-0006bp-Bc; Wed, 03 Jul 2019 11:49:49 +0200 Received: from [2a02:1205:5054:6d70:b45c:ec96:516a:e956] (helo=linux.home) by sslproxy01.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1hibtd-0000Zx-1y; Wed, 03 Jul 2019 11:49:49 +0200 Subject: Re: [PATCH bpf 1/3] bpf, x32: Fix bug with ALU64 {LSH,RSH,ARSH} BPF_X shift by 0 To: Luke Nelson , linux-kernel@vger.kernel.org Cc: Luke Nelson , Xi Wang , Wang YanQing , "David S. Miller" , Alexey Kuznetsov , Hideaki YOSHIFUJI , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, Alexei Starovoitov , Martin KaFai Lau , Song Liu , Yonghong Song , Shuah Khan , Jakub Kicinski , Jiong Wang , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org References: <20190629055759.28365-1-luke.r.nels@gmail.com> From: Daniel Borkmann Message-ID: <5c2080f4-532e-d239-13b1-4a5a620f6c33@iogearbox.net> Date: Wed, 3 Jul 2019 11:49:47 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20190629055759.28365-1-luke.r.nels@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.100.3/25499/Wed Jul 3 10:03:10 2019) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/29/2019 07:57 AM, Luke Nelson wrote: > The current x32 BPF JIT for shift operations is not correct when the > shift amount in a register is 0. The expected behavior is a no-op, whereas > the current implementation changes bits in the destination register. > > The following example demonstrates the bug. The expected result of this > program is 1, but the current JITed code returns 2. > > r0 = 1 > r1 = 1 > r2 = 0 > r1 <<= r2 > if r1 == 1 goto end > r0 = 2 > end: > exit > > The bug is caused by an incorrect assumption by the JIT that a shift by > 32 clear the register. On x32 however, shifts use the lower 5 bits of > the source, making a shift by 32 equivalent to a shift by 0. > > This patch fixes the bug using double-precision shifts, which also > simplifies the code. > > Fixes: 03f5781be2c7 ("bpf, x86_32: add eBPF JIT compiler for ia32") > Co-developed-by: Xi Wang > Signed-off-by: Xi Wang > Signed-off-by: Luke Nelson Series applied, thanks!