Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp734253imm; Fri, 5 Oct 2018 10:49:53 -0700 (PDT) X-Google-Smtp-Source: ACcGV607qsM1kbF3Ej9P9Ve0ouIrRNYLdBROT89y3MsSLsEj3CAovdDcdUgcz/JKmqLJbQpWnwet X-Received: by 2002:a62:1112:: with SMTP id z18-v6mr13155421pfi.200.1538761793154; Fri, 05 Oct 2018 10:49:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538761793; cv=none; d=google.com; s=arc-20160816; b=X9GUABqn9x6D6qYy/sFJ6XwF/5WJ0i/znb7ABInU35gR4gkX1fF9U3udeQmpGqYRGp GdPl7bOPHl9SGRgruhHN0X1coto8PHBEMW/ZVT0wuI3aN50oQY9BOqnDmOLMP2jAIfyp sucW6lBIEiM8mCMLjh3c9TqLtTLRoKAB2jliD9cAvLBVGYfmXmcH7Y3HQzcwdwmXwECb 9bVE9qBpBu3GAAOgmfYwu2qNqyc1bFdjptv0XW2w5Hhfm9CEzRsDFmIE/Mu1IsOkFWO8 2qdSwsgm+dcR+7JEaieZsV7uixctXJFjDjn6PF+slCDLMQn2a5McgoeBmRxXhcodDPWe iQMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=oG8WQn2IxUV23Frl9GKGcK3r9SskFlESO3IjhBiT+mo=; b=xmeRd8Dr8f68OVfRRF/1OVPlD8oljPJnhd0oJjLHVAPCtG07clemF+Df0npU/SM+T7 qiIzjMS6YsBRPentUY4wn4f+PUyZDt9GCEraakKKY0IAzVxdIQFTfptEO6ILLdmRaw0t /uvvE7CAjWj8yXN7oSYGsQu5ssk02tHlSfjQkkONo91eCASHRq4KWm3nUgB/x3L0TYT0 76Ltgf8wxgQ5NLOivA6R9hRN7nPF9vInpzLV5OPlghCWrDHrNI7htefMtzVZkGa4gWfc ga5cjJTv0KSGbED6F1KuDSAoN26KVCbLZo5PJV/dGWhyYfFKjFi2PB7TcQUCpS7fmkeQ 0XMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dfhzR9tE; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n188-v6si4835889pfn.113.2018.10.05.10.49.38; Fri, 05 Oct 2018 10:49:53 -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=@google.com header.s=20161025 header.b=dfhzR9tE; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728674AbeJFAtJ (ORCPT + 99 others); Fri, 5 Oct 2018 20:49:09 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:39926 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728021AbeJFAtJ (ORCPT ); Fri, 5 Oct 2018 20:49:09 -0400 Received: by mail-ot1-f67.google.com with SMTP id c20-v6so13496550otl.6 for ; Fri, 05 Oct 2018 10:49:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oG8WQn2IxUV23Frl9GKGcK3r9SskFlESO3IjhBiT+mo=; b=dfhzR9tE/sJY7hvL4IOp8S/jTK2VA2Zl91To+E96HDBI+YMVf2S6EqDQ9c+JWn7H+y AK8Uac2qlU+5JwG19nSzKznCA/SHCKE3wEgO7c6yuf7osQKRGwSW6AUODPzVw7C0GiPr Nwc2AlmJnp+RHQr8yZ6Z4eOR4yy+eFdaC1i203y0isZAT/sRvv3YFlnoMYAC+xZXkPZQ dvlN1dEp029Y59k3vkkpBmkFw+iAySft4rlkFJZB/+ccmsS4wWfmNHjYOqxFeURP80Ut z5lYh60tkJYkCOoT+8Gvo6WTG63MwDNz9CgL8H2QJ/cmS1zrZlzbFvRDZR3rFzC4Okcd f7Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oG8WQn2IxUV23Frl9GKGcK3r9SskFlESO3IjhBiT+mo=; b=Kf2VFUvj07iWLuH2KTFHC1vBS4imgmSiF4bqHcGKshxg6zRddFHPYzLEnREwL5j21l Y4GkDsaTpdeib8wugxMKhKXvd6kuaW7srO9+xeKyVoeDxNkVXh8MBM/IgrF/ibn5SsGV huZSkhvv8Gs/ff1l3/+98LljeF/wp++HiUtEC+0PRKDMG2r8ge3j+4N3U5qLoASvSqaL war1WNb7ltX8H1m9iG/TIuUmzyVrBw7/wzsvUTZpufILAcIcYt0uBtsFmozoaHv0BAVA Rq/O0se1Bz4Z9gl4+KZPAfBwLlr+wNa40z5HZLUXGcmviX479C/zw5/emeBvyS+CkOnI BT/A== X-Gm-Message-State: ABuFfogIvgJN1M/cM/ECCuJrBfiaZGarspm4s7WMxrPjV2vjDoUwXgR3 opwE1mAOalfzPgDZkvSzs0K7vTIlGNAThLzex4aYCg== X-Received: by 2002:a9d:49ac:: with SMTP id g44mr7483561otf.198.1538761762069; Fri, 05 Oct 2018 10:49:22 -0700 (PDT) MIME-Version: 1.0 References: <20181005161759.177992-1-jannh@google.com> In-Reply-To: From: Jann Horn Date: Fri, 5 Oct 2018 19:48:55 +0200 Message-ID: Subject: Re: [PATCH] bpf: 32-bit RSH verification must truncate input before the ALU op To: Edward Cree Cc: Daniel Borkmann , Alexei Starovoitov , Network Development , "David S. Miller" , kernel list 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 On Fri, Oct 5, 2018 at 7:45 PM Edward Cree wrote: > On 05/10/18 17:17, Jann Horn wrote: > > When I wrote commit 468f6eafa6c4 ("bpf: fix 32-bit ALU op verification"), I > > assumed that, in order to emulate 64-bit arithmetic with 32-bit logic, it > > is sufficient to just truncate the output to 32 bits; and so I just moved > > the register size coercion that used to be at the start of the function to > > the end of the function. > > > > That assumption is true for almost every op, but not for 32-bit right > > shifts, because those can propagate information towards the least > > significant bit. Fix it by always truncating inputs for 32-bit ops to 32 > > bits. > > > > Also get rid of the coerce_reg_to_size() after the ALU op, since that has > > no effect. > Might be worth saying something like "because src_reg is passed by value". > > Fixes: 468f6eafa6c4 ("bpf: fix 32-bit ALU op verification") > > Acked-by: Daniel Borkmann > > Signed-off-by: Jann Horn > > --- > Acked-by: Edward Cree > > kernel/bpf/verifier.c | 10 +++++++++- > > 1 file changed, 9 insertions(+), 1 deletion(-) > > > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > > index bb07e74b34a2..465952a8e465 100644 > > --- a/kernel/bpf/verifier.c > > +++ b/kernel/bpf/verifier.c > > @@ -2896,6 +2896,15 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env, > > u64 umin_val, umax_val; > > u64 insn_bitness = (BPF_CLASS(insn->code) == BPF_ALU64) ? 64 : 32; > Incidentally, I don't see why this needs to be a u64 (rather than say a u8). Yeah, the size of the integer doesn't really matter there... but it's being compared against other u64 values further down, so I also don't see a particular need to change it.