Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1287474imm; Wed, 1 Aug 2018 13:17:06 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeZy/RlB+X6wv/FC+ZkcGeH3E8LzcHttBS8w4Hx7APIzJKJRykMnO9K6DfXUOoxngriRkBh X-Received: by 2002:a62:1c13:: with SMTP id c19-v6mr8440290pfc.148.1533154626883; Wed, 01 Aug 2018 13:17:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533154626; cv=none; d=google.com; s=arc-20160816; b=v6RcX/hjcsBbOqjaBjDfbc2UwQvOCsmH1w7uonxzh7UobSm2ccUCUX8E0Gx853ghuC +mo8RCXu3dTZ35ZXbPcwSzOrCs6ePJDB3Omcl2wGNxw6fcBmQ7fZYvcaM4UYQDVxnAAN zVckL1Rnxq9z9la6sjNh6J3Z3Cjh/mFCJdo8dK9JwHc2wyZo6n1nbxAe48XKXgJJpjNi rKpoGhjvS9a1fY7aCJk17IkH+YmJ7v5Ij1g2RYnNGkmXM4w1TT1DQJ52U7rZF9iAcSXa rk26uBg3zodg1iOWhIQ9mrkdOW8W3cdVI+XcrexKS9hZo1wJqbCec1dHsqkrSo9e5HjA ohKA== 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:arc-authentication-results; bh=QzgP0B+knB2/fbh+r0wUNrSwiWzGIguTL0ndYaZ+Ylk=; b=gzUMta2AIym2V+Q03l29wwepOuMVXIl+ANBJK9yjPB5TrnvwrCky75mJ0KH5/hxAn/ IFN+IEjUoiv1TarR7skKncF/5RXsiVAAjqLGiPJR+04bq1CEgFZ6VjvxVemmv/T0gf06 KwOGWS44PTC22ZEnNeByJyQrpMKhxv6xL1LGfMpNtMqUDhQqsp1jJ26lMXPIG55ZRyKa nPxDsmg8sxQRI9FQIPuDlM26vH/8TrysljAuGSjUk3t0U2sd9APJe8y5FN8wOofb3f5W q8YeBci4v69HnppVu9SIGtY0XmL89W+UCn3enycZKlIFDCU5yf1Q5sKjck8HTlQjOABa 449w== 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 184-v6si18021669pfe.249.2018.08.01.13.16.51; Wed, 01 Aug 2018 13:17:06 -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 S1731902AbeHAWD3 (ORCPT + 99 others); Wed, 1 Aug 2018 18:03:29 -0400 Received: from www62.your-server.de ([213.133.104.62]:43322 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729647AbeHAWD3 (ORCPT ); Wed, 1 Aug 2018 18:03:29 -0400 Received: from [78.46.172.2] (helo=sslproxy05.your-server.de) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.85_2) (envelope-from ) id 1fkxXK-0006Py-Ju; Wed, 01 Aug 2018 22:15:58 +0200 Received: from [62.203.87.61] (helo=linux.home) by sslproxy05.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1fkxXK-000Nw1-FK; Wed, 01 Aug 2018 22:15:58 +0200 Subject: Re: [PATCH v4 bpf-next 08/14] bpf: introduce the bpf_get_local_storage() helper function To: Roman Gushchin Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Alexei Starovoitov References: <20180727215243.3850-1-guro@fb.com> <20180727215243.3850-9-guro@fb.com> <20180801002831.GA25953@castle.DHCP.thefacebook.com> From: Daniel Borkmann Message-ID: <82abfd03-1023-e785-a3ba-c63788acc659@iogearbox.net> Date: Wed, 1 Aug 2018 22:15:57 +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: <20180801002831.GA25953@castle.DHCP.thefacebook.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.0/24803/Wed Aug 1 18:43:39 2018) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/01/2018 02:28 AM, Roman Gushchin wrote: > On Wed, Aug 01, 2018 at 12:50:16AM +0200, Daniel Borkmann wrote: >> On 07/27/2018 11:52 PM, Roman Gushchin wrote: >> [...] >>> @@ -2533,6 +2541,16 @@ static int check_helper_call(struct bpf_verifier_env *env, int func_id, int insn >>> } >>> >>> regs = cur_regs(env); >>> + >>> + /* check that flags argument in get_local_storage(map, flags) is 0, >>> + * this is required because get_local_storage() can't return an error. >>> + */ >>> + if (func_id == BPF_FUNC_get_local_storage && >>> + !tnum_equals_const(regs[BPF_REG_2].var_off, 0)) { >>> + verbose(env, "get_local_storage() doesn't support non-zero flags\n"); >>> + return -EINVAL; >>> + } >> >> Hmm, this check is actually not correct. You will still be able to pass non-zero >> values in there. arg2_type from the helper is ARG_ANYTHING, so the register type >> could for example be one of the pointer types and it will still pass the verifier. >> The correct way to check would be to use register_is_null(). >> >>> + >>> /* reset caller saved regs */ >>> for (i = 0; i < CALLER_SAVED_REGS; i++) { >>> mark_reg_not_init(env, regs, caller_saved[i]); > > Oh, perfect catch! > The diff is below. Please, let me know if you prefer me to resend > the whole patch/patchset. Yeah, please resend at that point. There are also some other minor things which would be great if you could roll them in as well in a respin along with this fix and the uapi helper description adjustment with test case fix: - patch 1: bpf_map_release_memlock() should also use bpf_uncharge_memlock() directly - patch 2: cgroup_storage_map_alloc() only checks attr->key_size and attr->value_size but what about attr->max_entries and attr->map_flags? Should attr->max_entries be forced to 0 and at least attr->map_flags that don't make any sense in this context get rejected on map creation? - patch 9: not all uapi changes were copied over into tools' uapi header Thanks, Daniel