Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp837469ybi; Fri, 12 Jul 2019 05:29:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqyfRIc/7wOpuHuDISQnEgqkCZVciFRXuGdGWVZI70dPnWY/LF4G9rOlYE/AqxRb7xF5dCd3 X-Received: by 2002:a63:f4e:: with SMTP id 14mr10626206pgp.58.1562934544668; Fri, 12 Jul 2019 05:29:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562934544; cv=none; d=google.com; s=arc-20160816; b=ffT6rf420oUNbhuDF+6x/JJhdBnUnUYeiZP6kuBv2VZnZD7EAiKBWLvKNcS1mvcl2T 24n9kgXO/LBJbmp0ylpEiEQurAwWz0kSBleOE9Ux2K37v+6Ae5gNtLufYFqA9h0IoCQu /gMHQ0xyPO9vBYDb6wyAiv+/siFfgcXh89xexgejeLjXprlq03WjNisnNEAnhXJ/tIEp 2D6t0YopYVkABDP2IKzILFmZcXHFrNNtf4CsjT5paK/uSYzegly67LNmU1iU4SV67Rte 0ZG3L1bbfatOsa3As+IoM8LRjmNhTh3Iv8PyFJP72J9VqvyU2zxYHcJCCQ5toflxgKk8 9qfw== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kTWfoiC1bM7Z9PDnCqan3ktu7SNU8VoNVPcb26LO0MY=; b=VtzycH3NjWrNreOj3I0bOdsCCe5FEOQR+icdS2bblDNfNVOqkv0QDyqr61mgQ/EAEw uGWCRiWh6U5D7MikeKTGRrOk8gcqb8x4ITVG88tdOMjTQIlT9dmSrlUnNTsGF+GGkQCt s+MNGdYcQU/EVyXLwQR9U0XqAaY/LKMiHKBOyVLbw+/bDih+Oy6hD5eo8+88+1QBbH7K cKZVCw8qAcbL1OsR760kQMottiDtDJAT8o5azrnRLhY4qUDpan08fAKAaBYt9uv1rnrP Sy2hjYH/L2gOCAEP0t5RMW+/7vdSifHcqAdgT88T06uMd0fCxADiknNq1viRSyXvs6wM Pkhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="DV/8PEq6"; 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 31si7939128plc.356.2019.07.12.05.28.49; Fri, 12 Jul 2019 05:29:04 -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; dkim=pass header.i=@kernel.org header.s=default header.b="DV/8PEq6"; 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 S1728703AbfGLM1w (ORCPT + 99 others); Fri, 12 Jul 2019 08:27:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:40970 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728677AbfGLM1u (ORCPT ); Fri, 12 Jul 2019 08:27:50 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C7481216C8; Fri, 12 Jul 2019 12:27:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934469; bh=UgvX4NKm8hwhyfUD3407gBRNpyry022uPnp8FgjLEEA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DV/8PEq6LvSpw8T66e6ZeXAcvuzzmd9TMbEDBezuZXkormBhIT1s8V2Gctq+hzGfp B+pEh2ZDSEcgoZsfsUnN2vD6ul1suy+0tC2k3lnQydtuQrs58NcqE3pBZXatGYrOZA GAdL0obzjGMB1KISzt0/cqGdGoXWcQZKGI+X2TsM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Toshiaki Makita , Daniel Borkmann , Sasha Levin Subject: [PATCH 5.1 064/138] bpf, devmap: Fix premature entry free on destroying map Date: Fri, 12 Jul 2019 14:18:48 +0200 Message-Id: <20190712121631.132305427@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121628.731888964@linuxfoundation.org> References: <20190712121628.731888964@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit d4dd153d551634683fccf8881f606fa9f3dfa1ef ] 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 Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- kernel/bpf/devmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c index 1e525d70f833..e001fb1a96b1 100644 --- a/kernel/bpf/devmap.c +++ b/kernel/bpf/devmap.c @@ -291,10 +291,10 @@ void __dev_map_flush(struct bpf_map *map) if (unlikely(!dev)) continue; - __clear_bit(bit, bitmap); - bq = this_cpu_ptr(dev->bulkq); bq_xmit_all(dev, bq, XDP_XMIT_FLUSH, true); + + __clear_bit(bit, bitmap); } } -- 2.20.1