Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3099680rwe; Mon, 29 Aug 2022 05:58:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR4BV+bv5TfKPMur07MeUHhC5FG8i7GfQjIw6A7DKzSkVKq3So/fE+sBSfcwyc0XghYj8N/h X-Received: by 2002:a05:6402:882:b0:447:e6b9:89db with SMTP id e2-20020a056402088200b00447e6b989dbmr12423308edy.346.1661777914094; Mon, 29 Aug 2022 05:58:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661777914; cv=none; d=google.com; s=arc-20160816; b=m1uBP2pchwR3MQFUfrKvlNI/gnYUp9PpxGwLgN8Ztzr+QxZP13cNO30CGu2HpwyPyU IVtpcKkXqe7OMRpC39MGUzK9FawsRKIWLtE35Qawn1bURNKF4LmjzXMbzg8fopGdWExH B2PfK0Wt9WRl/pNMPcdwINad6zn9ynPkRnledLncV6kZpo0QCXUV5F5RYN37/dGQGH+a 0wNpxSRObXtwDZkIH3PpOpnsRnREAZLdj2NaWBlGyz41nrPGdfyF76EpKkou0sd/2dWx 05jJ7WnAV5pKtp0JTCc0ZJ4bUPNGOJ+tr3DX6i4P5nXYtSM258UUYkwd/yxVWcYEvQVb zkzQ== 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=7CzT4UxXoRimKnDwqdLD9Mx0Q//V9sbuIfC0PkJMBQA=; b=SluIKDPqsqM09e3HkH1j4stDZRBNXMHIBmJuQmFC2pDvei9bRuCtj2l9436T00TPad nbD4BivIVfm1FqhTFUKCX2fL9tvhiZIN9PpExzxQeyS09YE/V5M9Nv2wCvgE90g7NIyC IvNYzGYPLIf7NbYI01n+JftYD3HwRaurj2NNFczpJ/G4k9UC6546uLyZX+QT3Mx0g/8h CqbD7UypuEJRHdqQxi3ZVphhfe0vm6j/zpngXTcY3hkMEenyKwzXCsIl1u/3oi1iwsM6 rZQvByU1c/8R0T2e2gziDO1tqquG5I1SbGp+dGceouT8q+807VRac4SHGHpiffBSHW/w nQkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bW2rBlWF; 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 dt10-20020a170907728a00b007419a23eb1dsi1622590ejc.171.2022.08.29.05.58.07; Mon, 29 Aug 2022 05:58:34 -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=bW2rBlWF; 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 S231290AbiH2M0Z (ORCPT + 99 others); Mon, 29 Aug 2022 08:26:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231156AbiH2M0G (ORCPT ); Mon, 29 Aug 2022 08:26:06 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 620811D0E3; Mon, 29 Aug 2022 05:10:07 -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 ams.source.kernel.org (Postfix) with ESMTPS id 5C0FDB80F9F; Mon, 29 Aug 2022 11:09:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B6C0C433D7; Mon, 29 Aug 2022 11:09:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771392; bh=ZDiK8jX6cb1oKsAdnCNZLZhtFnRPXVYAq73tA3QscPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bW2rBlWFSQkZYJaZvwDwm83gLn0yeu+8BSSYVZoJcR616otj/L7RAXHgsIiBai++P BsID7wkXjRtv6pTt02HnwxAdrZ9t3TB9miCN3YxeeqoL//1Pb+w+5eFpduqywx9ua+ wYWc1okWqxXvfJiqAWj6z7XyoMyBPxuKr3A7Q3So= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Duoming Zhou , "David S. Miller" , Sasha Levin Subject: [PATCH 5.19 026/158] nfc: pn533: Fix use-after-free bugs caused by pn532_cmd_timeout Date: Mon, 29 Aug 2022 12:57:56 +0200 Message-Id: <20220829105809.876472837@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105808.828227973@linuxfoundation.org> References: <20220829105808.828227973@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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 f1e941dbf80a9b8bab0bffbc4cbe41cc7f4c6fb6 ] When the pn532 uart device is detaching, the pn532_uart_remove() is called. But there are no functions in pn532_uart_remove() that could delete the cmd_timeout timer, which will cause use-after-free bugs. The process is shown below: (thread 1) | (thread 2) | pn532_uart_send_frame pn532_uart_remove | mod_timer(&pn532->cmd_timeout,...) ... | (wait a time) kfree(pn532) //FREE | pn532_cmd_timeout | pn532_uart_send_frame | pn532->... //USE This patch adds del_timer_sync() in pn532_uart_remove() in order to prevent the use-after-free bugs. What's more, the pn53x_unregister_nfc() is well synchronized, it sets nfc_dev->shutting_down to true and there are no syscalls could restart the cmd_timeout timer. Fixes: c656aa4c27b1 ("nfc: pn533: add UART phy driver") Signed-off-by: Duoming Zhou Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/nfc/pn533/uart.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/nfc/pn533/uart.c b/drivers/nfc/pn533/uart.c index 2caf997f9bc94..07596bf5f7d6d 100644 --- a/drivers/nfc/pn533/uart.c +++ b/drivers/nfc/pn533/uart.c @@ -310,6 +310,7 @@ static void pn532_uart_remove(struct serdev_device *serdev) pn53x_unregister_nfc(pn532->priv); serdev_device_close(serdev); pn53x_common_clean(pn532->priv); + del_timer_sync(&pn532->cmd_timeout); kfree_skb(pn532->recv_skb); kfree(pn532); } -- 2.35.1