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=-3.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS,USER_AGENT_NEOMUTT 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 E33BDC43387 for ; Wed, 16 Jan 2019 23:30:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AF190206C2 for ; Wed, 16 Jan 2019 23:30:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="u6fN3+Ob" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727370AbfAPXaf (ORCPT ); Wed, 16 Jan 2019 18:30:35 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:44453 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726994AbfAPXaf (ORCPT ); Wed, 16 Jan 2019 18:30:35 -0500 Received: by mail-pg1-f193.google.com with SMTP id t13so3506093pgr.11 for ; Wed, 16 Jan 2019 15:30:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=RGIrD5y+vpgvmXnDo/XbpAf096bIy9q9Fg3XaXXcZrg=; b=u6fN3+ObjWoUsI+lr7QVy4IfC7u5fI6KbzVRI0wSna0mgIyCiVn4lEJ4xR5z73qBZ7 mdvItRjLj4v9IuW1+iWeOL0WIBc5uxqMVdIz45XcsE0OKFdLQua2qlQOgWtiS/Jm4MVu K6o+qynZXn4QCfdqEhwyUx+yGUH1Wa+dtjexrbOFI4LymqEGr+cpQ5l4T4wMjjsnVsr0 OOtB26zpjgke82QjHQMUn9a7jEzAnXss+Af4jtb6MQtVzwsamkvcmfyT09lTOlPzuAkd 2nH+7+T1yXkCv4WmovIBw9lVE0s/LIMBFSCk0VuFn8aIJzYmHZweYLL/Q/q3Nc+D+RqI SDxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=RGIrD5y+vpgvmXnDo/XbpAf096bIy9q9Fg3XaXXcZrg=; b=QNQkDEHzkL7k68j+/efceFS4IR1htg2qdfUWcKZDb1vGdHubAeGfolaQ+eMIX7B+IF 4vvJLuiZiC7ffOD/OLJeoxcf3zUeOaDpiNO7M80uiIyaiKeZSpmBI4oBiCZnd2fRqQtQ OlEwT+mDCVsIKvUa7xF6mWUUxukygf376FxdxSHmiae+9mcLcSxhLTdn9jfN3WXEuITx 6pdH3YF7n3jvpKVO0EPGug4NZL2PYNT2x8qk09cRhsiQutSV/djQJBPNkjfqUBx/ywUl VnYcKK/WWLHWsQR9tpCe1zA3CEC51GdOs9Q9sTSg3JpWOt8wx3E4oS/3PHOY9jkRNRgu rDLg== X-Gm-Message-State: AJcUukfgDz4AM3FGwdXtF+yE1Uxp0MUb3e7K/X//VhNMMCvr43oXSSJL OhNyeu/hp1RJXsuzBpzjYI8= X-Google-Smtp-Source: ALg8bN4RjQAMq+3nR/G+UemsHcHlFqjvcVcZIqHGwh/ZrjKJLfvw6hm7lfH7t8oR6u00Ncyyvoc/uw== X-Received: by 2002:a62:26c7:: with SMTP id m190mr12587611pfm.79.1547681433820; Wed, 16 Jan 2019 15:30:33 -0800 (PST) Received: from ast-mbp ([2620:10d:c090:200::6:30ae]) by smtp.gmail.com with ESMTPSA id d69sm10145709pfg.168.2019.01.16.15.30.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jan 2019 15:30:32 -0800 (PST) Date: Wed, 16 Jan 2019 15:30:31 -0800 From: Alexei Starovoitov To: Daniel Borkmann Cc: Alexei Starovoitov , davem@davemloft.net, jakub.kicinski@netronome.com, netdev@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH bpf-next 1/9] bpf: introduce bpf_spin_lock Message-ID: <20190116233029.xdaddrfehfjk4hrx@ast-mbp> References: <20190116050830.1881316-1-ast@kernel.org> <20190116050830.1881316-2-ast@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180223 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Thu, Jan 17, 2019 at 12:16:44AM +0100, Daniel Borkmann wrote: > On 01/16/2019 11:48 PM, Daniel Borkmann wrote: > > On 01/16/2019 06:08 AM, Alexei Starovoitov wrote: > [...] > >> @@ -6096,6 +6226,11 @@ static int do_check(struct bpf_verifier_env *env) > >> return -EINVAL; > >> } > >> > >> + if (env->cur_state->active_spin_lock) { > >> + verbose(env, "bpf_spin_unlock is missing\n"); > >> + return -EINVAL; > >> + } > >> + > >> if (state->curframe) { > >> /* exit from nested function */ > >> env->prev_insn_idx = env->insn_idx; > > > > I think if I'm not mistaken there should still be a possibility for causing a > > deadlock, namely if in the middle of the critical section I'm using an LD_ABS > > or LD_IND instruction with oob index such that I cause an implicit return 0 > > while lock is held. At least I don't see this being caught, probably also for > > such case a test_verifier snippet would be good. > > > > Wouldn't we also need to mark queued spinlock functions as notrace such that > > e.g. from kprobe one cannot attach to these causing a deadlock? > > I think there may be another problem: haven't verified, but it might be possible > at least from reading the code that I have two programs which share a common > array/hash with spin_lock in BTF provided. Program A is properly using spin_lock > as in one of your examples. Program B is using map in map with inner map being > that same map using spin_lock. When we return that fake inner_map_meta as > reg->map_ptr then we can bypass any read/write restrictions into spin_lock area > which is normally prevented by verifier. Meaning, map in map needs to be made > aware of spin_lock case as well. 2nd great catch. thanks! Indeed inner_map_meta doesn't preserve all the fields from struct bpf_map. It seems long term we'll be able to support spin_lock in inner map too, but for now I'll disable it.