From patchwork Mon May 18 17:36:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 225563 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3922C433E1 for ; Mon, 18 May 2020 18:28:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7397E20657 for ; Mon, 18 May 2020 18:28:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589826488; bh=18kelMiuxmlsuUdBZVM0nsM6j/squYz1UglbO0FLr6M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=D5MlmMlvT1gFIoZ8E9y3gP79dDjvYNsJntfG9P3ITZHPaaCLXp+2iBIL5Ts3fJWOd wIkO2rRtO8G2Sn9Avbq+Oi34sIG0rmreKvK5U/lHqWn6Qi+xGDt02LXLdd9130KvTf tQkXRphNkrGHUN8ejEdQ6sp2wynv+mT65GcDmzEM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728783AbgERS2E (ORCPT ); Mon, 18 May 2020 14:28:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:40632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729024AbgERRnQ (ORCPT ); Mon, 18 May 2020 13:43:16 -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 7345B20715; Mon, 18 May 2020 17:43:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589823795; bh=18kelMiuxmlsuUdBZVM0nsM6j/squYz1UglbO0FLr6M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SZNrCwoniH1mkkalcbT6RdWXNMp2Z1N7xprmweDKQVsb8J3npBS85jC2h5VagUFI0 RjxS12fHA+hV/d15DXbKKKNPWtOYTus58W8+YoNDMDorHq/qKIumsi/xb5WkH04Uzk TVv4me1Fy54CeD8BsDc0PTOlK+N7oddiQSvHnxKU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Antti Laakso , Vladis Dronov , Richard Cochran , "David S. Miller" , Ben Hutchings , Sasha Levin Subject: [PATCH 4.9 40/90] ptp: free ptp device pin descriptors properly Date: Mon, 18 May 2020 19:36:18 +0200 Message-Id: <20200518173459.303551655@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200518173450.930655662@linuxfoundation.org> References: <20200518173450.930655662@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Vladis Dronov commit 75718584cb3c64e6269109d4d54f888ac5a5fd15 upstream. There is a bug in ptp_clock_unregister(), where ptp_cleanup_pin_groups() first frees ptp->pin_{,dev_}attr, but then posix_clock_unregister() needs them to destroy a related sysfs device. These functions can not be just swapped, as posix_clock_unregister() frees ptp which is needed in the ptp_cleanup_pin_groups(). Fix this by calling ptp_cleanup_pin_groups() in ptp_clock_release(), right before ptp is freed. This makes this patch fix an UAF bug in a patch which fixes an UAF bug. Reported-by: Antti Laakso Fixes: a33121e5487b ("ptp: fix the race between the release of ptp_clock and cdev") Link: https://lore.kernel.org/netdev/3d2bd09735dbdaf003585ca376b7c1e5b69a19bd.camel@intel.com/ Signed-off-by: Vladis Dronov Acked-by: Richard Cochran Signed-off-by: David S. Miller Signed-off-by: Ben Hutchings Signed-off-by: Sasha Levin --- drivers/ptp/ptp_clock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c index 2c1ae324da182..bf1536f1c90bb 100644 --- a/drivers/ptp/ptp_clock.c +++ b/drivers/ptp/ptp_clock.c @@ -175,6 +175,7 @@ static void ptp_clock_release(struct device *dev) { struct ptp_clock *ptp = container_of(dev, struct ptp_clock, dev); + ptp_cleanup_pin_groups(ptp); mutex_destroy(&ptp->tsevq_mux); mutex_destroy(&ptp->pincfg_mux); ida_simple_remove(&ptp_clocks_map, ptp->index); @@ -276,9 +277,8 @@ int ptp_clock_unregister(struct ptp_clock *ptp) if (ptp->pps_source) pps_unregister_source(ptp->pps_source); - ptp_cleanup_pin_groups(ptp); - posix_clock_unregister(&ptp->clock); + return 0; } EXPORT_SYMBOL(ptp_clock_unregister);