From patchwork Thu May 12 21:00:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 1630429 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=M+Aq3G8x; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linux-fsi-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KzkhX2CMRz9sG0 for ; Fri, 13 May 2022 07:01:00 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KzkhV1zCPz3c7L for ; Fri, 13 May 2022 07:00:58 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=M+Aq3G8x; dkim-atps=neutral X-Original-To: linux-fsi@lists.ozlabs.org Delivered-To: linux-fsi@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=eajames@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=M+Aq3G8x; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KzkhL3svPz3brx for ; Fri, 13 May 2022 07:00:49 +1000 (AEST) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24CKuFUZ030686; Thu, 12 May 2022 21:00:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=1KwfhkldnBNAglWnX9p2UAFz4cu4GJ4dugWpMyEm/YU=; b=M+Aq3G8xD2cr+Z0cpB3tIs9aRkoK4gcspKMbSZKV2OEBMU+gXTo8T4sbojYMj4FCT7ux UK0rOUrmPNp66pqFaa8rGBv0C3QiHh2yvIhZUIzpGxCza9XTKDIl5Di7XP5C3/8O+oV4 g+NtI5i1p42FbHqOHbspJUJn6gDmgy0sK3IQH1Kh4Ghrf/pX6QfHtYcvAL0sRLvbD2BD WBOhZaLqxZjPINDAiuezMXD5/B9ICCwTqKy+PGamGHx3w/nXxsSoKkCKNCQKxl5+TKyd LvJRIzlpsdZzn4sg6aDCVB4x3oEVIyWvuG/0hm+JO3XzHjhjmwwGD+x1sUNc1X7h4g/J uQ== Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3g19q6g2ak-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 May 2022 21:00:45 +0000 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 24CKwSOW017618; Thu, 12 May 2022 21:00:45 GMT Received: from b03cxnp08026.gho.boulder.ibm.com (b03cxnp08026.gho.boulder.ibm.com [9.17.130.18]) by ppma02dal.us.ibm.com with ESMTP id 3fwgday76c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 May 2022 21:00:45 +0000 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 24CL0iDk32768334 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 12 May 2022 21:00:44 GMT Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ED2F313605D; Thu, 12 May 2022 21:00:43 +0000 (GMT) Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A11FD136055; Thu, 12 May 2022 21:00:43 +0000 (GMT) Received: from v0005c16.aus.stglabs.ibm.com (unknown [9.211.56.168]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP; Thu, 12 May 2022 21:00:43 +0000 (GMT) From: Eddie James To: linux-fsi@lists.ozlabs.org Subject: [PATCH] fsi: occ: Prevent use after free Date: Thu, 12 May 2022 16:00:34 -0500 Message-Id: <20220512210034.59907-1-eajames@linux.ibm.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: j2hZuXqg4k_jRswtDikHsB2aCBsJaAvY X-Proofpoint-ORIG-GUID: j2hZuXqg4k_jRswtDikHsB2aCBsJaAvY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-12_17,2022-05-12_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 adultscore=0 spamscore=0 mlxscore=0 mlxlogscore=829 lowpriorityscore=0 priorityscore=1501 phishscore=0 clxscore=1011 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205120087 X-BeenThere: linux-fsi@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair@popple.id.au, linux-kernel@vger.kernel.org Errors-To: linux-fsi-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "linux-fsi" Use get_device and put_device in the open and close functions to make sure the device doesn't get freed while a file descriptor is open. Signed-off-by: Eddie James --- drivers/fsi/fsi-occ.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/fsi/fsi-occ.c b/drivers/fsi/fsi-occ.c index c9cc75fbdfb9..9e48dc62b1c5 100644 --- a/drivers/fsi/fsi-occ.c +++ b/drivers/fsi/fsi-occ.c @@ -82,6 +82,9 @@ static int occ_open(struct inode *inode, struct file *file) struct miscdevice *mdev = file->private_data; struct occ *occ = to_occ(mdev); + if (!occ->buffer) + return -ENOENT; + if (!client) return -ENOMEM; @@ -94,6 +97,7 @@ static int occ_open(struct inode *inode, struct file *file) client->occ = occ; mutex_init(&client->lock); file->private_data = client; + get_device(occ->dev); /* We allocate a 1-page buffer, make sure it all fits */ BUILD_BUG_ON((OCC_CMD_DATA_BYTES + 3) > PAGE_SIZE); @@ -143,7 +147,7 @@ static ssize_t occ_write(struct file *file, const char __user *buf, ssize_t rc; u8 *cmd; - if (!client) + if (!client || !client->occ->buffer) return -ENODEV; if (len > (OCC_CMD_DATA_BYTES + 3) || len < 3) @@ -197,6 +201,7 @@ static int occ_release(struct inode *inode, struct file *file) { struct occ_client *client = file->private_data; + put_device(client->occ->dev); free_page((unsigned long)client->buffer); kfree(client); @@ -672,6 +677,7 @@ static int occ_remove(struct platform_device *pdev) struct occ *occ = platform_get_drvdata(pdev); kvfree(occ->buffer); + occ->buffer = NULL; misc_deregister(&occ->mdev);