Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3056856rwe; Mon, 29 Aug 2022 05:15:06 -0700 (PDT) X-Google-Smtp-Source: AA6agR7+VdgSFvZjCvK9/wNUoa7zS72hm8oSoq8PP8krw9U80IEur+EZYtw/ARwj2g4HJQwvOQPc X-Received: by 2002:a17:907:7632:b0:73d:c346:de57 with SMTP id jy18-20020a170907763200b0073dc346de57mr13684456ejc.647.1661775306258; Mon, 29 Aug 2022 05:15:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661775306; cv=none; d=google.com; s=arc-20160816; b=OrNsmEIm6Z90Z+TJYQSgfNHZrTm2U1LWSDxuoSGD1Y/IzuLqIszRFoK3po8qQFtirt H1nVie0eWLMrHsoZn+7NGlslAumx0iMvIc77iIHocAUIiKGkO+6VmBQwSZik1K8vAZNI 7vnXRxDTBn33DJZEWXWr/y1BuOLSBAjR8elqiurBBQqZjpI74toUTsi8fuHbmdk2lJDv DuHE7ugHy9kVHBcBCwQi+hrsfA/bwOZF4GkgbGnu5DVhkM5rC8byHYAnTbNFrksw4Lm6 Db/VbmhAyvZA5iGHjMNbILiOrFCt6ssuqsrwn4o3JXh6SS0ypxL1XUpev+RlAGAmGSaK p5JQ== 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=xupLyW5ekMfZ3x+o33EVYLY4+QKcO+LjJnTu62Qs6MQ=; b=z6Ibbmbkwt5DCXmu3pwOlmonAFujw6Rvq8pVjkfmjrhM9ONHojC3jxrRuzFCjl/HMb iBK6+8VUxut+dSuZJeNVUiqpGsdVOzCM2zFDZGP8FPuEb4Vir2AholtwPbyJuVWHkoe8 kojm9S+6p+lECJkdYknx8ZJOl9rGbVtQRQtNiq5tp3bGVe91CmtIscuNZbVPF7zSykU8 F/2Y7KNRwknaxcqbHUa8ZBeZDCnSHkig6K1Vt+RUdiz8fJNiv6NQjgMGeV0d8D5Ye4i3 KJNuPG36VwIG6VVZ9NmqSCj0mE7M0u4sbdhELhLQ4tz04WUSgKx7wAm488TY9QZcFJO3 UeiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sHRk26T3; 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 gb23-20020a170907961700b0074157a46cd5si1686751ejc.172.2022.08.29.05.14.40; Mon, 29 Aug 2022 05:15:06 -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=sHRk26T3; 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 S232380AbiH2LhB (ORCPT + 99 others); Mon, 29 Aug 2022 07:37:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232810AbiH2LgI (ORCPT ); Mon, 29 Aug 2022 07:36:08 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1953B7D7BC; Mon, 29 Aug 2022 04:20:40 -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 A2688B80F3B; Mon, 29 Aug 2022 11:05:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7EFDC433C1; Mon, 29 Aug 2022 11:05:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771107; bh=IAXDwtfFOmitaIKfjHPlHTXJpqG+oOz2KWYeG26f2ZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sHRk26T30VgQYp8PHv14XxNkkFQXoenkAQaVRynMEQAl333u5U0A4lOLBnPKYCUe4 ckKRPS/k7fz3Zlmdo+whB1jlHHhC5W/q6buIRgeLEbdu8/2US3nA44G0+yExe2K0Bw pdneKWEF4vPOYOLX6IP/MHZAO7BJP5bN/VKoLFwA= 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.10 22/86] nfc: pn533: Fix use-after-free bugs caused by pn532_cmd_timeout Date: Mon, 29 Aug 2022 12:58:48 +0200 Message-Id: <20220829105757.429379589@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105756.500128871@linuxfoundation.org> References: <20220829105756.500128871@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 a0665d8ea85bc..e92535ebb5287 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