Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4823893ybl; Wed, 22 Jan 2020 05:26:10 -0800 (PST) X-Google-Smtp-Source: APXvYqwQLHBUitfJRQOGa1VhSmFxdhCt+67Bh1GWXFSjm+W3N3h/wijx6XYto15CdMDd3WnM0tBt X-Received: by 2002:a54:401a:: with SMTP id x26mr6551105oie.101.1579699570108; Wed, 22 Jan 2020 05:26:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579699570; cv=none; d=google.com; s=arc-20160816; b=jYBdlviBQku3NFLKUz23730U+MzNvVEAqT7lo6UkJGuCM+BQ4trI/ZPMglF+2HWrgG rWmh6R/8cPRjCIqRZmpBba8LZPcfkq3DOYh4QHck0WzfV4gISwcUPvTvMQUcyh7+1uxf P6f0PIcBxP8nF5Nwmg29xb5ppTVfhx2m5eShoPHqEqJ4c/Npj2MH3EHt+14eJvwpsBIi RK97fbRnGfRMUCQeM5jV1B6GNYUr2iezj+UYkp/A84x5KH/ho1wgwrLN+Mxl2c1IOzrD qBw2JY1djpbVZl+UUpjI3ETgaRE+E195dAhmZ+BkmNb6IvmbDB33pJKFbhm5m+PARZKO Cf9A== 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=ynYYrydDqegXyyO27JjzebowC1cpzFRpsD1OwQqFgEQ=; b=GzfCtbvjUCPqYR+CM/jNnFccZ1WHGSdNVKY/YLLj80h5eg4ElbjW5laIIqO6lABXKq cd4KOFzwcH/AVKiWvVko2Ov8XB/KdJE6OwVnC7rn/ZfA3/h2ytnqJtbiimABSDJzECRS TW2eoLcC9NCDeUyOw+lQXPg7532XNc2HDLxF8Fylh+5rj3RNN0iyeDs8Iw6l5fe258yh 5evsodOR1G9Bz5/KbRwbkhT11PKVvCGRuLfnaulQ0C2T1PYcw6fZZn9GzBSd4XMOe+jD 98zDP0R0T/D246qHVYhzYaPbmDAHxIj3V7NaioXhou6X1ELxs4QKTzK4aUgqy7l2CRcf 5inQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=a43CHnWA; 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 l25si23460607otn.69.2020.01.22.05.25.58; Wed, 22 Jan 2020 05:26:10 -0800 (PST) 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=a43CHnWA; 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 S1730635AbgAVNYI (ORCPT + 99 others); Wed, 22 Jan 2020 08:24:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:42852 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729441AbgAVNYH (ORCPT ); Wed, 22 Jan 2020 08:24:07 -0500 Received: from localhost (unknown [84.241.205.26]) (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 E11FD2467B; Wed, 22 Jan 2020 13:24:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579699446; bh=VCKeJPeEMxr6OsWtINChBKZsnu6gFOR3faHdsd6h1Wk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a43CHnWAdN7ZRMtV8mw0DzTkSNACPniAmYU+BRasJyytHs4Jc6Vf2PzkC3Nv2vC37 Tqot6wGiQgS8AwrLdOLb3nN7V7UvUIJqXf8hi8+llBK7ohlp9GoPLeGO/HIrmh9dhH kC/eCgMKrF/GypKjVWcj7/fHOF32l7U0DOTg/1TQ= 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" Subject: [PATCH 5.4 146/222] ptp: free ptp device pin descriptors properly Date: Wed, 22 Jan 2020 10:28:52 +0100 Message-Id: <20200122092844.183839189@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092833.339495161@linuxfoundation.org> References: <20200122092833.339495161@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 From: Vladis Dronov [ Upstream commit 75718584cb3c64e6269109d4d54f888ac5a5fd15 ] 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: Greg Kroah-Hartman --- drivers/ptp/ptp_clock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/ptp/ptp_clock.c +++ b/drivers/ptp/ptp_clock.c @@ -170,6 +170,7 @@ static void ptp_clock_release(struct 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); @@ -302,9 +303,8 @@ int ptp_clock_unregister(struct ptp_cloc 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);