Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3054842pxb; Mon, 18 Apr 2022 14:39:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8Io8qvshD8jbjso2Jz8+a7fqI1WnPoVg3hpOfkzBpyFOzcsaj6R1T81DSf0TfJx+lwaFW X-Received: by 2002:a17:902:8608:b0:158:c532:d8b2 with SMTP id f8-20020a170902860800b00158c532d8b2mr12598320plo.46.1650317982366; Mon, 18 Apr 2022 14:39:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650317982; cv=none; d=google.com; s=arc-20160816; b=Pw/ZL2utzAMtvVk7bzBfzeEB1UHnDd8FOV0QpdjyyMM1hVvbfJxes3muUWH+/9Yt3r ov/fvK43ZrhQWRKiERGi9QswEdoNGZIhu8BpFJlVf/mbMFNhbDUYQSFbqKTnQdaHuoAY OCNH19CKknoedgOHEzx13cKCdEfv+uuYjzuAx1wxKARTrJwdQKm16FPtFawsMDb0uhyS irN6cN4fZ4qmJmYqMbUZJv+UjfB7AJAdGnMztk0wFE6ZD5s1H88aI7c4P0sj4EzDgARM xE9CM0A2qvmfSHG5LqsetPzXsOEKklGdkYWOxNfupJ/cvZTY853scdNJnBJgY1gt/ANE ZWAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Clm41AWar8uoEybXF6olXXF6IGRRYo61GKV/O26s660=; b=qOAzWSlHqONaHSrh5ht1sW1X26P+ZwmmcFmCy9LreJntlZefesXtDh4LXacgFZEeBK b9vAWomsXIlJEr2Q9I4tSAuQx89UFDiRiU5rc/CwbNeJmFCVWZAOhqo4fUEsTeaWlqIV WvRDMytFGuw0qRG0CCqd8ak+4ZlA4rxYWxw7E3zR6fLA0N6DkFo8IrtW7FNGLWdS0AO0 LWthumUnh6zLND7a0CJ+X22nil0mk2S0fczHBhJ9E/Ph5qPDm+dP5R9p7QUmWyJlKDH6 JD5yyYFkRJWRCweEi2Z0MnLsDxbQ35psFihAa9exzHu6tKom4FaelOPWu2dMQ59XvlS8 /5tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1YhncvQ6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 205-20020a6304d6000000b0038285075b9csi6600296pge.723.2022.04.18.14.39.26; Mon, 18 Apr 2022 14:39:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1YhncvQ6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239369AbiDRMgW (ORCPT + 99 others); Mon, 18 Apr 2022 08:36:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238968AbiDRMaZ (ORCPT ); Mon, 18 Apr 2022 08:30:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC65720BF9; Mon, 18 Apr 2022 05:23:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E9FC860FB6; Mon, 18 Apr 2022 12:23:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DDC69C385A7; Mon, 18 Apr 2022 12:23:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650284616; bh=hV4sZbdWRl5CDXKOmPmgx+SZXH3jUf1gWjRJWhZ0+J0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1YhncvQ6uCWbEAAas/P4Gemf6kcFdNQ5xHrQz7L8cEqPSeEVV7wMk4oSDSkazYLE/ 50FI/76TPxpcrLw5KORCXJXBSg/CyLNXJqtdi7gKJ+z5qiWowgzRLDcoKbxBTq2kgL WbQUya+7E2/atwD5ArFs7tABot85lxYO57k72tUI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Duoming Zhou , Jiri Slaby , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.17 170/219] drivers: net: slip: fix NPD bug in sl_tx_timeout() Date: Mon, 18 Apr 2022 14:12:19 +0200 Message-Id: <20220418121211.639853201@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121203.462784814@linuxfoundation.org> References: <20220418121203.462784814@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Duoming Zhou [ Upstream commit ec4eb8a86ade4d22633e1da2a7d85a846b7d1798 ] When a slip driver is detaching, the slip_close() will act to cleanup necessary resources and sl->tty is set to NULL in slip_close(). Meanwhile, the packet we transmit is blocked, sl_tx_timeout() will be called. Although slip_close() and sl_tx_timeout() use sl->lock to synchronize, we don`t judge whether sl->tty equals to NULL in sl_tx_timeout() and the null pointer dereference bug will happen. (Thread 1) | (Thread 2) | slip_close() | spin_lock_bh(&sl->lock) | ... ... | sl->tty = NULL //(1) sl_tx_timeout() | spin_unlock_bh(&sl->lock) spin_lock(&sl->lock); | ... | ... tty_chars_in_buffer(sl->tty)| if (tty->ops->..) //(2) | ... | synchronize_rcu() We set NULL to sl->tty in position (1) and dereference sl->tty in position (2). This patch adds check in sl_tx_timeout(). If sl->tty equals to NULL, sl_tx_timeout() will goto out. Signed-off-by: Duoming Zhou Reviewed-by: Jiri Slaby Link: https://lore.kernel.org/r/20220405132206.55291-1-duoming@zju.edu.cn Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/slip/slip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/slip/slip.c b/drivers/net/slip/slip.c index 98f586f910fb..8ed4fcf70b9b 100644 --- a/drivers/net/slip/slip.c +++ b/drivers/net/slip/slip.c @@ -469,7 +469,7 @@ static void sl_tx_timeout(struct net_device *dev, unsigned int txqueue) spin_lock(&sl->lock); if (netif_queue_stopped(dev)) { - if (!netif_running(dev)) + if (!netif_running(dev) || !sl->tty) goto out; /* May be we must check transmitter timeout here ? -- 2.35.1