From patchwork Fri Sep 4 21:06:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 514765 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 604CD140771 for ; Sat, 5 Sep 2015 07:06:48 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=eZPe027m; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933930AbbIDVG0 (ORCPT ); Fri, 4 Sep 2015 17:06:26 -0400 Received: from mail-yk0-f181.google.com ([209.85.160.181]:32805 "EHLO mail-yk0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933786AbbIDVGX (ORCPT ); Fri, 4 Sep 2015 17:06:23 -0400 Received: by ykei199 with SMTP id i199so33037857yke.0; Fri, 04 Sep 2015 14:06:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=InPmgd94ELgsjDuIhK33C2wEqlKhLV4JZ758ynYM2Z4=; b=eZPe027mo9qndfN7Dtcu+FnfvtVH8tkf5jVuOIQReFmEnVwIujCaEQdn67lLrd2Reg EDh997WtCbKk3ttIv7YROp1NrP1bEREzuYdZAbBoM3O27cI4z402BdbDA1aJ/54kToeA ju0KcX7+lBat1jz5bn7jqopHCHbVRIwSHnqeNkmPR1isy08pO3bA07rfom3LgauRyR/m gu2K0xbYXmHJTIJ07g5ThBLD4TJAhj8y4x+mUodX3Lz1/iLdI2fnQ6RgzdTNiGJj1PlH w1CpNPd+TPAbdzHF2axvj27s7KIU4pdC58efwJQY3Luq7ZWUIUWUTejoCEZ+cFTkMdT5 dCvA== X-Received: by 10.129.34.138 with SMTP id i132mr6331927ywi.104.1441400782850; Fri, 04 Sep 2015 14:06:22 -0700 (PDT) Received: from Alexeis-MacBook-Pro-2.local ([12.97.19.194]) by smtp.gmail.com with ESMTPSA id w186sm3361500ywf.18.2015.09.04.14.06.21 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Sep 2015 14:06:22 -0700 (PDT) Date: Fri, 4 Sep 2015 14:06:19 -0700 From: Alexei Starovoitov To: Tycho Andersen Cc: Kees Cook , Alexei Starovoitov , Will Drewry , Oleg Nesterov , Andy Lutomirski , Pavel Emelyanov , "Serge E. Hallyn" , Daniel Borkmann , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [PATCH 6/6] ebpf: allow BPF_REG_X in src_reg conditional jumps Message-ID: <20150904210619.GF1842@Alexeis-MacBook-Pro-2.local> References: <1441382664-17437-1-git-send-email-tycho.andersen@canonical.com> <1441382664-17437-7-git-send-email-tycho.andersen@canonical.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1441382664-17437-7-git-send-email-tycho.andersen@canonical.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Fri, Sep 04, 2015 at 10:04:24AM -0600, Tycho Andersen wrote: > The classic converter generates conditional jumps with: > > if (BPF_SRC(fp->code) == BPF_K && (int) fp->k < 0) { > ... > } else { > insn->dst_reg = BPF_REG_A; > insn->src_reg = BPF_REG_X; > insn->imm = fp->k; > bpf_src = BPF_SRC(fp->code); > } > > but here, we enforce that the src_reg == BPF_REG_0. We should also allow > BPF_REG_X since that's what the converter generates; this enables us to > load eBPF programs that were generated by the converter. good catch. classic->extended converter is just being untidy. It shouldn't be populating unused 'src_reg' field when BPF_SRC == BPF_K verifier is doing the right thing. It's rejecting instructions that have junk in unused fields to make sure that someday we can extend it with something useful. The fix should be something like this: the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/net/core/filter.c b/net/core/filter.c index 13079f03902e..05a04ea87172 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -478,9 +478,9 @@ do_pass: bpf_src = BPF_X; } else { insn->dst_reg = BPF_REG_A; - insn->src_reg = BPF_REG_X; insn->imm = fp->k; bpf_src = BPF_SRC(fp->code); + insn->src_reg = bpf_src == BPF_X ? BPF_REG_X : 0; } -- To unsubscribe from this list: send the line "unsubscribe netdev" in