Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4571567pxf; Tue, 16 Mar 2021 17:53:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiSHA9uEpASc90tBKCaF91hWBBfxaETcRHaZpwUTO/UJq/RpeCUc/IsaYvVhBTe1DnMCbv X-Received: by 2002:a17:906:4e57:: with SMTP id g23mr32393669ejw.47.1615942401265; Tue, 16 Mar 2021 17:53:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615942401; cv=none; d=google.com; s=arc-20160816; b=FX4hK3ZRg+Im/AmMLaITyOnf55SY0wgZm7qBVb/S01wpGZcnLKRpdxkxbPk65oM7PM P9Ks2M+k1aPU4kcu3EB5odmbvbbfPlwKVELuqNI6+3HdDbYwhj9N1j596VLEhhVpOrhe SQ9vPbXfKEe3fWJwQDoIge/j9QxBW/XFUajSqk3hCCkt+fyNugErUSRmfBBux2i21z2G 13LqVzfnSqJXL2G45PZFPGtvzuCSDZ0/4SSfabETdzipgCDohlDwSXiXPwpUl9pS1gxs JXpfZUew4K8u3U4kB74S/7ZR1YSd7Q9Son8QkKdcsFIsow3ywkV+WC+BeDlYT6hkRUTZ gXLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=g+COD45asCD6AViOAc7MrxWQy6+3ypSO2/Rgi0R4u9w=; b=VRpTnzKdfmq9ceOh8DZAD8gA9XAANjHrSIxxJi5/i9o7SwPeowhDGRmlhJNTQpM3H5 1PI18UqCtD939ELfvmUVW5NrtubiyISP/MR66NEGj6wgV10JQQDO/X87QX3YvvvVVEfk r/5dp4Mn5dYipKM0WUduXd1rw5bim5kZVWsLdpCF2P4vKeoKwIDxA4fUOlvEA2WfKYa/ 3QhUMmrNzPfU37V4N0n6+0jeeVkJq9Xej2AJUNO7oMgnl80UUoqxOOfVwvNZFkZsuqYl cJAkVH7h1gIoX+OmhyCbj7Tn+5Sb++2Ex7wFYUtkMYj0qu+3BrTotzfXIvkoDvIImGCg Z8Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nCAmIz5z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w11si14712225ejc.1.2021.03.16.17.52.58; Tue, 16 Mar 2021 17:53:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nCAmIz5z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229769AbhCQAqT (ORCPT + 99 others); Tue, 16 Mar 2021 20:46:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229789AbhCQAqI (ORCPT ); Tue, 16 Mar 2021 20:46:08 -0400 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33F40C06175F for ; Tue, 16 Mar 2021 17:46:08 -0700 (PDT) Received: by mail-io1-xd31.google.com with SMTP id o9so39251318iow.6 for ; Tue, 16 Mar 2021 17:46:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=g+COD45asCD6AViOAc7MrxWQy6+3ypSO2/Rgi0R4u9w=; b=nCAmIz5z0Rtq4Zy6d4iypjH+JgXX77D0C1BrmyEH6Mdl+rccaEDL2wis0CQPEUaVQj JKiK+ZeDiVtU7Axq1ODLN5mpSjErYkB4gbVMt2r3EDWPZ/RAzphW83Jbf2+8TzpikncG 4WPZ023Wm1DrVdechGNdeQDLZaOGY9BNN3osI= 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=g+COD45asCD6AViOAc7MrxWQy6+3ypSO2/Rgi0R4u9w=; b=amhU9IbCxs9P4ePN8riA+PyeikqV6OiadwODoDowJ9moerwyJ79YqQaIXkIOLwg1kq iQMA/8huHCmHxfAzKotpHByo9a0k1m5eJGpkgk2Qg+T8Hyw+42D1ZHM7rt2RggzKU1o0 lcEwhd3KRdMwwVGfKp67zm5X/O7G9zt4M+UMINL7G0NwCrVqMe5vHB475jHDaLZTp/0b NmORG4pUIylItDy2LsTfd8xco9it4PMO+iVTnePvKQzontIe8xXUpz+gpkXLXCzWItr5 zOZqtBBriBDiA6J63h1XQrnPT0s3ZC55UVB3tby5XdQ6S9/d3kY5Egyh/qTQAulx28JC bODg== X-Gm-Message-State: AOAM531a1RYzmWTqu4WcH92ua+mXIqoDHq3Yk/WdxbQGCZy9belbin1W c2MNTxnxHg6A5em8Ofl6sdz/35of2FmAifZeltVnJg== X-Received: by 2002:a05:6602:2102:: with SMTP id x2mr5498716iox.83.1615941967649; Tue, 16 Mar 2021 17:46:07 -0700 (PDT) MIME-Version: 1.0 References: <20210310220211.1454516-1-revest@chromium.org> <20210310220211.1454516-2-revest@chromium.org> In-Reply-To: From: Florent Revest Date: Wed, 17 Mar 2021 01:45:57 +0100 Message-ID: Subject: Re: [PATCH bpf-next 1/5] bpf: Add a ARG_PTR_TO_CONST_STR argument type To: Andrii Nakryiko Cc: bpf , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Yonghong Song , KP Singh , Brendan Jackman , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 17, 2021 at 1:35 AM Andrii Nakryiko wrote: > On Tue, Mar 16, 2021 at 4:58 PM Florent Revest wrote: > > On Tue, Mar 16, 2021 at 2:03 AM Andrii Nakryiko > > wrote: > > > On Wed, Mar 10, 2021 at 2:02 PM Florent Revest wrote: > > > > + } else if (arg_type == ARG_PTR_TO_CONST_STR) { > > > > + struct bpf_map *map = reg->map_ptr; > > > > + int map_off, i; > > > > + u64 map_addr; > > > > + char *map_ptr; > > > > + > > > > + if (!map || !bpf_map_is_rdonly(map)) { > > > > + verbose(env, "R%d does not point to a readonly map'\n", regno); > > > > + return -EACCES; > > > > + } > > > > + > > > > + if (!tnum_is_const(reg->var_off)) { > > > > + verbose(env, "R%d is not a constant address'\n", regno); > > > > + return -EACCES; > > > > + } > > > > + > > > > + if (!map->ops->map_direct_value_addr) { > > > > + verbose(env, "no direct value access support for this map type\n"); > > > > + return -EACCES; > > > > + } > > > > + > > > > + err = check_helper_mem_access(env, regno, > > > > + map->value_size - reg->off, > > > > + false, meta); > > > > > > you expect reg to be PTR_TO_MAP_VALUE, so probably better to directly > > > use check_map_access(). And double-check that register is of expected > > > type. just the presence of ref->map_ptr might not be sufficient? > > > > Sorry, just making sure I understand your comment correctly, are you > > suggesting that we: > > 1- skip the check_map_access_type() currently done by > > check_helper_mem_access()? or did you implicitly mean that we should > > call it as well next to check_map_access() ? > > check_helper_mem_access() will call check_map_access() for > PTR_TO_MAP_VALUE and we expect only PTR_TO_MAP_VALUE, right? So why go > through check_helper_mem_access() if we know we need > check_map_access()? Less indirection, more explicit. So I meant > "replace check_helper_mem_access() with check_map_access()". Mhh I suspect there's still a misunderstanding, these function names are really confusing ahah. What about check_map_access*_type*. which is also called by check_helper_mem_access (before check_map_access): https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/tree/kernel/bpf/verifier.c#n4329 Your message sounds like we should skip it so I was asking if that's what you also implicitly meant or if you missed it? > > 2- enforce (reg->type == PTR_TO_MAP_VALUE) even if currently > > guaranteed by compatible_reg_types, just to stay on the safe side ? > > I can't follow compatible_reg_types :( If it does, then I guess it's > fine without this check. It's alright, I can keep an extra check just for safety. :)