Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp670936ybi; Wed, 3 Jul 2019 02:50:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzOc+ZlFJZQi3y5c+LQlCYsDCvYB1otzNhYQGW0brBRh9mvOtwN23vrrHVOLcu/vLYpKZP+ X-Received: by 2002:a63:2b0c:: with SMTP id r12mr5350535pgr.206.1562147439970; Wed, 03 Jul 2019 02:50:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562147439; cv=none; d=google.com; s=arc-20160816; b=GrCgv83vkdEmbRs4bsEyJBae45/VsJEOyuYTOpTbeXz9uRkvAWkrJqrDppQLuARkg9 HQefzrNeweTp2KgTtHqo8U9nANAz3fP55Q0IxMUX1mT7MBgOOp3y1fNRt60hhQVvxap8 lY5h06zQMA65FD4bPqrnwcoYljuJBQESZ1lHGXXIbo4Ksh6rOvlHK/eiLsdoMmq+e2KJ R1Rsh7osDc+O+hEl/+Wo2Jeg/yR2kIc7cSyI2EaRtdde4gkZTiEpukgjcXkA6KtOZ5oE Q9LVu64SdH1LVnplv1IImtrH4KuJGEKbebWXlp+4/0wriZkliCaeTWv9C8+pq09zVY1X I7Dg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=bLtwXe9uX5WzdXV31hA5MLW5T9sQiWUwlhs5FrmHzU4=; b=onOhTkaVGVtSAi8Bk/k2Ut56PG+xHTT7kGNGHHICiAY7GEuSkCdl9ifv8NfFNBt69C B+9O/MWShbEJccJnterOrugPCOEHKZgANs9fU+f1UkgJSNzMNHOZejv39yzf5pcKr3yN zUw5rYe95g1yp/5upkniiwdM18KbKlG883U4RTeZeoGK1OYHOIIZTrQDZxrS33fweE// FswA5JxrMlcdnRbtPN0Q+RGCv/lzCHT98oybo7d90gTI8qE70gF/UOMvTR3Xl7+3GQA3 UFjjxrCLfHGju7X94yKdIfS6FJ6X8sDuGi/2wsUApYdqTJjrx2gaVRlOE30MPow/Kj9v i8YQ== 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 7si1904738pfh.38.2019.07.03.02.50.23; Wed, 03 Jul 2019 02:50:39 -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; 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 S1726964AbfGCJuD (ORCPT + 99 others); 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!