Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4640533ybl; Wed, 22 Jan 2020 01:50:55 -0800 (PST) X-Google-Smtp-Source: APXvYqyFonQNC3M7qSS+WzcMSvVFsQ9C4L2tP4CJgZ3xA9Oq9UnpZnparo7Y/769Xu5Iw5UYtKTJ X-Received: by 2002:a9d:53cb:: with SMTP id i11mr6873749oth.158.1579686655480; Wed, 22 Jan 2020 01:50:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579686655; cv=none; d=google.com; s=arc-20160816; b=BXFOSMbLW4ZPLAdzxLObHgb+m9PQVcmbKqKgBlj9qnK057XyiTT8/Q0QP3FNRmYt16 g806dQDcXIyBo50XtbBBvdPOeFJ8d67FibGhxoXz2LzIkBxHM+d/P9K/McfigNFbf7fK F1g38hioxKBPGsOU1xShTgw0hfx3adXVYS8SMf9POfoIhFx7apaJOW+MrwTVh0HCT13S 8wxIuEqC2d6oJpB8Yqkgnk3BuAkc0eqmitf88e0ep6d7Px91n9LinlVhYcAD0IYmlxvH lY7+x2/grwQP7fWuu8QbqMsRDcpRHrpWzgH0bBmE+s+w8alQk5wY/fPUA04EOA2galbt AH0g== 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=EhnRLAdx254BsBn7G+GStXeyKkOq8jFp2/Rpqdp1CtU=; b=n6Fn95gGCrlRaIBkZlFAjID7xn+KKswNGh5oLnIItDRHkkQHk5QSR5elsClvxrOlop Tk2kNQfv94UDlIA7NshGhZ+y01L7Od1rj94ezUmGlHc5TzJaKzIBqTXdoh8Qf9/Agjl7 H059U+Q1tLqgXEIG0zvjmQc/zdh30X6dNaAiNPyY1wtbna8TkkMbj2VY138A064jWFc2 zJgZ4ELX+6FLsRHQIDmamqLNQVUHPBT+z36NG8afjkkMJLqdWf4CsyAZNZjY1CuQvA5Y TRBioYyobPWx7FIT1VFNJ7uJ5ftNzQfUDjWFbEAAFeqOaWzPGdIrUnRyT4ld87IIIk0A uW5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ti3lBZLP; 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 v24si14452981otq.87.2020.01.22.01.50.44; Wed, 22 Jan 2020 01:50:55 -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=Ti3lBZLP; 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 S1733157AbgAVJjM (ORCPT + 99 others); Wed, 22 Jan 2020 04:39:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:56532 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733145AbgAVJjJ (ORCPT ); Wed, 22 Jan 2020 04:39:09 -0500 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 29E0724680; Wed, 22 Jan 2020 09:39:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579685948; bh=RR+nFKij4VabaC5YVhm66/fxmKNHMt8p/paFyJe6+2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ti3lBZLPCkDKl5aEP71xO2sVzgBAxiWv+RuaKwWx2iWGueMWUQQGBf+8Po0i8eUK2 3WJQU2YYptPVxu617A8LGUMI97wAUqAEiH0+8AETAy6etOnUl1z5D341b1QQb2gpJ6 j0QKr+nVnB0NwprlSPsjDibB7SCBI+5qBcocmU2w= 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 4.14 47/65] ptp: free ptp device pin descriptors properly Date: Wed, 22 Jan 2020 10:29:32 +0100 Message-Id: <20200122092757.884265813@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092750.976732974@linuxfoundation.org> References: <20200122092750.976732974@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 @@ -179,6 +179,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); @@ -315,9 +316,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);