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.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,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 DE29EC31E44 for ; Fri, 14 Jun 2019 11:04:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BA2712133D for ; Fri, 14 Jun 2019 11:04:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727175AbfFNLE4 (ORCPT ); Fri, 14 Jun 2019 07:04:56 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:36379 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727054AbfFNLE4 (ORCPT ); Fri, 14 Jun 2019 07:04:56 -0400 Received: by mail-ed1-f68.google.com with SMTP id k21so2944241edq.3 for ; Fri, 14 Jun 2019 04:04:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=gDQHdoJkjMyWAWD6F86RlCqtG6jM6BlmY2sdnAminyQ=; b=cNoCbjASDvIz3uCPrEvUtPbc14XMbFiECayzhJPhoYjAlVmgyEqWEK1SpLiQiUts9q vc7i4hJWn8srnz78NiAIjyyWHqh/RydZDwEwIsVFk72G2blh87jcZoKLCPXld/pn33XB XePLPx26bkXAwL0lOdJYY0sNLEk34Sj+F51QIIpp/QOVAjHmQCZmodpwTEdNVRQCC7lk qgl28jpFKoBaf3f54usYf9jjFKGQDTmPQlMS/d43wrX7fTPol9mzJFBHJ86Wp2GBqQD3 kCWa7drTG0LTw4/YPXm/v3Elp89AhYJzWoyQc801K76i6RicYpM/yGUihKAWr4/dDGku OFEw== X-Gm-Message-State: APjAAAV7pAZ1tilQNsBjW6rcor9KjH1gfMaNadL2lD/sxBIbUVQWQRbt I02CgEVstrpYfc3fX2+0r0Udlg== X-Google-Smtp-Source: APXvYqwcvUZZvnmPYJu0xr+xVEs3aP1mvppxJWYLXCIQnzHZQ1D15PovB5fBDPlCB74snV6Ng/xtsA== X-Received: by 2002:a50:f982:: with SMTP id q2mr31569019edn.270.1560510294552; Fri, 14 Jun 2019 04:04:54 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a00:7660:6da:443::2]) by smtp.gmail.com with ESMTPSA id o93sm790721edd.46.2019.06.14.04.04.53 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 14 Jun 2019 04:04:53 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 3AF921804AF; Fri, 14 Jun 2019 13:04:53 +0200 (CEST) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Toshiaki Makita , Alexei Starovoitov , Daniel Borkmann , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , John Fastabend Cc: Toshiaki Makita , netdev@vger.kernel.org, xdp-newbies@vger.kernel.org, bpf@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , David Ahern Subject: Re: [PATCH bpf 1/3] devmap: Fix premature entry free on destroying map In-Reply-To: <20190614082015.23336-2-toshiaki.makita1@gmail.com> References: <20190614082015.23336-1-toshiaki.makita1@gmail.com> <20190614082015.23336-2-toshiaki.makita1@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett Date: Fri, 14 Jun 2019 13:04:53 +0200 Message-ID: <877e9octre.fsf@toke.dk> MIME-Version: 1.0 Content-Type: text/plain Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Toshiaki Makita writes: > dev_map_free() waits for flush_needed bitmap to be empty in order to > ensure all flush operations have completed before freeing its entries. > However the corresponding clear_bit() was called before using the > entries, so the entries could be used after free. > > All access to the entries needs to be done before clearing the bit. > It seems commit a5e2da6e9787 ("bpf: netdev is never null in > __dev_map_flush") accidentally changed the clear_bit() and memory access > order. > > Note that the problem happens only in __dev_map_flush(), not in > dev_map_flush_old(). dev_map_flush_old() is called only after nulling > out the corresponding netdev_map entry, so dev_map_free() never frees > the entry thus no such race happens there. > > Fixes: a5e2da6e9787 ("bpf: netdev is never null in __dev_map_flush") > Signed-off-by: Toshiaki Makita I recently posted a patch[0] that gets rid of the bitmap entirely, so I think you can drop this one... -Toke [0] https://lore.kernel.org/netdev/156042464148.25684.11881534392137955942.stgit@alrua-x1/ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-f67.google.com ([209.85.208.67]:39000 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727083AbfFNLE4 (ORCPT ); Fri, 14 Jun 2019 07:04:56 -0400 Received: by mail-ed1-f67.google.com with SMTP id m10so2923281edv.6 for ; Fri, 14 Jun 2019 04:04:55 -0700 (PDT) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= Subject: Re: [PATCH bpf 1/3] devmap: Fix premature entry free on destroying map In-Reply-To: <20190614082015.23336-2-toshiaki.makita1@gmail.com> References: <20190614082015.23336-1-toshiaki.makita1@gmail.com> <20190614082015.23336-2-toshiaki.makita1@gmail.com> Date: Fri, 14 Jun 2019 13:04:53 +0200 Message-ID: <877e9octre.fsf@toke.dk> MIME-Version: 1.0 Content-Type: text/plain Sender: xdp-newbies-owner@vger.kernel.org List-ID: To: Toshiaki Makita , Alexei Starovoitov , Daniel Borkmann , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , John Fastabend Cc: netdev@vger.kernel.org, xdp-newbies@vger.kernel.org, bpf@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , David Ahern Toshiaki Makita writes: > dev_map_free() waits for flush_needed bitmap to be empty in order to > ensure all flush operations have completed before freeing its entries. > However the corresponding clear_bit() was called before using the > entries, so the entries could be used after free. > > All access to the entries needs to be done before clearing the bit. > It seems commit a5e2da6e9787 ("bpf: netdev is never null in > __dev_map_flush") accidentally changed the clear_bit() and memory access > order. > > Note that the problem happens only in __dev_map_flush(), not in > dev_map_flush_old(). dev_map_flush_old() is called only after nulling > out the corresponding netdev_map entry, so dev_map_free() never frees > the entry thus no such race happens there. > > Fixes: a5e2da6e9787 ("bpf: netdev is never null in __dev_map_flush") > Signed-off-by: Toshiaki Makita I recently posted a patch[0] that gets rid of the bitmap entirely, so I think you can drop this one... -Toke [0] https://lore.kernel.org/netdev/156042464148.25684.11881534392137955942.stgit@alrua-x1/