Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3000954ybi; Mon, 17 Jun 2019 14:24:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqzDIaUJMx+pjRr9CV+MaS7PllBJcpZl64wqVf3XB/xPH2uBUsWXbpe4IFf/FoTxbk5e0q3H X-Received: by 2002:aa7:84d1:: with SMTP id x17mr92539654pfn.188.1560806673640; Mon, 17 Jun 2019 14:24:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560806673; cv=none; d=google.com; s=arc-20160816; b=mhaectXNxHXHc/I/tcPqXc83nlveeu0pT3egSLX/xALbNtVQGnQcp23hVdO/NN2MoV Wo4Ja16xuKBn8GY+bR25o3Ps/Pa04yiKlRNgROJ50VaijpTQdnRgdmaWcpFMQ3kp0ECd V73QPg1jWK4x/2e0R/2LszbE3AIwnBAIB/2NVQUzNP2s1pHiwY244Vx2PBFMZKXYVJv+ vndCVmVtMOwhL53oTeFF/ECqJJUSzSTsowfEMQjWs7/6UiNK/EpUuCokP94wO8WBUyYv meV+lnRrBAe7hoX1bodyqzXpNjrIT1seq0NI8qmw+5tyBFL5OEKGw09IMEuUKexFCIeA 5sQg== 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=Ct7VAtq6BSD6RcpMAhMBSjM2t2d0/VUyq7FPdBm612Q=; b=EkoBC8Rx9XNr3DOFRSocrnXqfxHXWcw1qD9Y6v6GdVh2GD4XmEfhq/bmFzz2al/9/+ MXlmz+DdvqAfEKaqHKEv8nfLNfoJ5R7OEUs3jtHXA2H+zfJPGAkKOFKZGxWYGdG8oFhr 8pFb0Eh9urdG0GqQ02boEOgeE7MPQmDh4Iln+M0jsaVA1zpxGABsJ9u9K5pDMCQ4RmZ2 rpoF6LlXwqRA7tH6I/PfsjTU4TrX/66pW/RzS+NwZz+fmiOKtApyIjntL4+3r0Z2R/b6 F8qnz3GImLe88a/lhaP3Fn81ZGQh1Z8uXukHTmT+7xAIi3PLgauaJLORzjDjSbdeCEWu uobQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=q26+4LFo; 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 a14si7592489pgg.384.2019.06.17.14.24.18; Mon, 17 Jun 2019 14:24:33 -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=q26+4LFo; 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 S1729591AbfFQVWp (ORCPT + 99 others); Mon, 17 Jun 2019 17:22:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:47420 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729168AbfFQVWl (ORCPT ); Mon, 17 Jun 2019 17:22:41 -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 3D0D52063F; Mon, 17 Jun 2019 21:22:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560806559; bh=4HBY7V9Q6baNtwiAz2Ub7+lfEj5/tmjfFc8zZ7NgEpw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q26+4LFouvXUlHKni50u1gI0RyO3NVp6WL/ywlmC+YWoqESUYC0AOAbC0AXhpJW0g xDyNZnXT67l2CjZZkcB6qKelzfNto24EYPlDkTXpqQShO+yLExrnAg2us2W2uZUJcZ FWnPCsHFpQ46W4p927qsZSyAQ9T2AAxGnqVLLVFw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Fastabend , Daniel Borkmann , Sasha Levin Subject: [PATCH 5.1 049/115] bpf: sockmap, only stop/flush strp if it was enabled at some point Date: Mon, 17 Jun 2019 23:09:09 +0200 Message-Id: <20190617210802.979202296@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617210759.929316339@linuxfoundation.org> References: <20190617210759.929316339@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 014894360ec95abe868e94416b3dd6569f6e2c0c ] If we try to call strp_done on a parser that has never been initialized, because the sockmap user is only using TX side for example we get the following error. [ 883.422081] WARNING: CPU: 1 PID: 208 at kernel/workqueue.c:3030 __flush_work+0x1ca/0x1e0 ... [ 883.422095] Workqueue: events sk_psock_destroy_deferred [ 883.422097] RIP: 0010:__flush_work+0x1ca/0x1e0 This had been wrapped in a 'if (psock->parser.enabled)' logic which was broken because the strp_done() was never actually being called because we do a strp_stop() earlier in the tear down logic will set parser.enabled to false. This could result in a use after free if work was still in the queue and was resolved by the patch here, 1d79895aef18f ("sk_msg: Always cancel strp work before freeing the psock"). However, calling strp_stop(), done by the patch marked in the fixes tag, only is useful if we never initialized a strp parser program and never initialized the strp to start with. Because if we had initialized a stream parser strp_stop() would have been called by sk_psock_drop() earlier in the tear down process. By forcing the strp to stop we get past the WARNING in strp_done that checks the stopped flag but calling cancel_work_sync on work that has never been initialized is also wrong and generates the warning above. To fix check if the parser program exists. If the program exists then the strp work has been initialized and must be sync'd and cancelled before free'ing any structures. If no program exists we never initialized the stream parser in the first place so skip the sync/cancel logic implemented by strp_done. Finally, remove the strp_done its not needed and in the case where we are using the stream parser has already been called. Fixes: e8e3437762ad9 ("bpf: Stop the psock parser before canceling its work") Signed-off-by: John Fastabend Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- net/core/skmsg.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/core/skmsg.c b/net/core/skmsg.c index cc94d921476c..49d1efa329d7 100644 --- a/net/core/skmsg.c +++ b/net/core/skmsg.c @@ -554,8 +554,10 @@ static void sk_psock_destroy_deferred(struct work_struct *gc) struct sk_psock *psock = container_of(gc, struct sk_psock, gc); /* No sk_callback_lock since already detached. */ - strp_stop(&psock->parser.strp); - strp_done(&psock->parser.strp); + + /* Parser has been stopped */ + if (psock->progs.skb_parser) + strp_done(&psock->parser.strp); cancel_work_sync(&psock->work); -- 2.20.1