Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp460165yba; Wed, 15 May 2019 04:30:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqxVmlWj6Ca7y5HnGMJWf/WzIabhadqTUibTagBu8daDXGOcSfMlh5HLtdzTPXyT/quGxwcv X-Received: by 2002:a63:5c1b:: with SMTP id q27mr44444406pgb.127.1557919818653; Wed, 15 May 2019 04:30:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557919818; cv=none; d=google.com; s=arc-20160816; b=r9praAvx2peifKoHDWIrhd+XsFgFc/bBXN5+DkjVWKWMj1MRbq+UKu+Y8ZU1PNqLtU FybRPai2aNdCbdqtW2mDiyxm+tzDDuUIMGlSjWWxFocFgsw4fgr53uHwE8fBjrIht9Qs +hzzZ9YgkdNUVW+vHmw7/6QyB7CyHWm7NjGUvDqVcggi7Qt345WQWp9eU+Vh9NaMSMKf 1PaVcA4tQE+SKOiC8qFbWEIMcaBKKgEtQXjuaGp12TttCPsG9MN3JmJHKOu+Hf41N7uM OD6whMEb1qOD1p/cab75cTu8HvKBmmgy0mTW4wwRWERCN9CGvMa2BLrsk9HMj+nDAcV7 xjBw== 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=yAL1at86Vp2wzNtKhBCY0ESaGBLnpiCsxBzY+OR8c6s=; b=Qxzug/r46cCnPKsbaJV8gU1u0k8a06ADUBDEfVAAj2FtM7tTDouK9rpGjn8NHshebX LdFOKDq6q9ehupTD2IdZ2YoN530FO0EJ+yO3pvSFajNtJ/0lmj1zO4ENtSeuBthnMRxY 1aUc39PCGwR83mxbfWZMKQ9f4NL7hioQqvRnGuLUqhZ4mbv/x8bz7IRjMkjM31BNJHWy 0JMrfEvSKNvHyPY+xC+jm0IQbSZdgrTSZfwib5vFp2XQo1VByVcYVL1XDD2rDJi/3PoP JXI2EBSI77000V29IGXTe64TmG1lXF+vr8fWa1E9/n0N+742JX4BKasZ9OCBGQ/m5mca QozQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RNOFeWgk; 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 ch16si1579615plb.76.2019.05.15.04.30.04; Wed, 15 May 2019 04:30:18 -0700 (PDT) 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=RNOFeWgk; 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 S1732034AbfEOL10 (ORCPT + 99 others); Wed, 15 May 2019 07:27:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:38210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731820AbfEOL1T (ORCPT ); Wed, 15 May 2019 07:27:19 -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 3AE75206BF; Wed, 15 May 2019 11:27:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919638; bh=KpIPZUyxMP0Na8z5+5BAeSGLtjGmrs+ZQiYaeJuyOUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RNOFeWgkOpcXyEsB2y3B2DmzXlUhKNBd/M5otrRznC6CBJU9Qyx9yxEH9zq+rM2HE cZNPjwGDq/0PsraZ7ldMwDNDDHo1A4lP73c8mg1w9E+R+KZdkV5OerDubUmLT7vHow PYubruYzBIfN8hxT6c2p8u1jryL1VTwyStrYozt8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , "David S. Miller" , Sasha Levin Subject: [PATCH 5.0 038/137] qede: fix write to freed pointer error and double free of ptp Date: Wed, 15 May 2019 12:55:19 +0200 Message-Id: <20190515090656.150382406@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090651.633556783@linuxfoundation.org> References: <20190515090651.633556783@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 [ Upstream commit 1dc2b3d65523780ed1972d446c76e62e13f3e8f5 ] The err2 error return path calls qede_ptp_disable that cleans up on an error and frees ptp. After this, the free'd ptp is dereferenced when ptp->clock is set to NULL and the code falls-through to error path err1 that frees ptp again. Fix this by calling qede_ptp_disable and exiting via an error return path that does not set ptp->clock or kfree ptp. Addresses-Coverity: ("Write to pointer after free") Fixes: 035744975aec ("qede: Add support for PTP resource locking.") Signed-off-by: Colin Ian King Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/qlogic/qede/qede_ptp.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/qlogic/qede/qede_ptp.c b/drivers/net/ethernet/qlogic/qede/qede_ptp.c index 5f3f42a253616..bddb2b5982dcf 100644 --- a/drivers/net/ethernet/qlogic/qede/qede_ptp.c +++ b/drivers/net/ethernet/qlogic/qede/qede_ptp.c @@ -490,18 +490,17 @@ int qede_ptp_enable(struct qede_dev *edev, bool init_tc) ptp->clock = ptp_clock_register(&ptp->clock_info, &edev->pdev->dev); if (IS_ERR(ptp->clock)) { - rc = -EINVAL; DP_ERR(edev, "PTP clock registration failed\n"); + qede_ptp_disable(edev); + rc = -EINVAL; goto err2; } return 0; -err2: - qede_ptp_disable(edev); - ptp->clock = NULL; err1: kfree(ptp); +err2: edev->ptp = NULL; return rc; -- 2.20.1