From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A73D9C433DB for ; Wed, 17 Mar 2021 00:47:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E7D064F92 for ; Wed, 17 Mar 2021 00:47:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229808AbhCQAqV (ORCPT ); Tue, 16 Mar 2021 20:46:21 -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-Google-Smtp-Source: ABdhPJwB3XvpqehjtxC0Gn0gio1Yg8n6+Cqib9VxyLHpyQSa1ebiGIZB+cDDuNsZ1p92Y9L6rQsylO53XZJfkIqulrM= 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. :)