From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6630D145A16; Thu, 13 Jun 2024 12:20:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718281201; cv=none; b=oH/pMMAiHcd7LD1jn20n++PuPtMLhgFV/6nn2WPNC46Klas7LZ1aauPDdLTH9unzUnGKTXZOfbzNYvLUoGPxTMPYDpXnD1Tr/ImbtXgRcOYzwr88BESVCOehOLTpGkTM44RC8rVpfao7TcwT0VIrIdzVrFHtNgIUmNgW/8kw5go= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718281201; c=relaxed/simple; bh=/Ef6Zuzv+vgeEEVUGyq5fxGVRkPYymZBJB6rm/51nLg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=la3GI7o3EEqUJLaHuWYASaO+KpJEGPsXbg2jOdA9Qh+3lMTQQSHRqF0Fo1N7XHsS1mz1gyYkbxwRyCUXUCRapTU3Xnhh7cGD6R8dN2Amp8j0KyJ1eHeYzY6XcrAZh0lffZxPejcyqo6g0N6k5PhKlLlsFVPrw1i0IwfVIJEIpOM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=f9PNHlg5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="f9PNHlg5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D89D8C2BBFC; Thu, 13 Jun 2024 12:20:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1718281201; bh=/Ef6Zuzv+vgeEEVUGyq5fxGVRkPYymZBJB6rm/51nLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f9PNHlg5frZ9h/wywYs+5/qaR7TCKGPn1XcEPSlOFm2s3uXSdqulSQLuGWAGQyZR0 i07qQQ1KZm0gZkjZku4T4G6fuQ8xSPsGd8DyJ7SjEuR2wrTZI4V/+hfXMDDyhr21ye 7EjxEU7+xaKg9Rx5JpfwRQ9yBDm7YyZhvxh8AFNg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Huai-Yuan Liu , Sasha Levin Subject: [PATCH 5.10 175/317] ppdev: Add an error check in register_device Date: Thu, 13 Jun 2024 13:33:13 +0200 Message-ID: <20240613113254.328367654@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240613113247.525431100@linuxfoundation.org> References: <20240613113247.525431100@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Huai-Yuan Liu [ Upstream commit fbf740aeb86a4fe82ad158d26d711f2f3be79b3e ] In register_device, the return value of ida_simple_get is unchecked, in witch ida_simple_get will use an invalid index value. To address this issue, index should be checked after ida_simple_get. When the index value is abnormal, a warning message should be printed, the port should be dropped, and the value should be recorded. Fixes: 9a69645dde11 ("ppdev: fix registering same device name") Signed-off-by: Huai-Yuan Liu Link: https://lore.kernel.org/r/20240412083840.234085-1-qq810974084@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/char/ppdev.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c index f6024d97fe70b..a97edbf7455a6 100644 --- a/drivers/char/ppdev.c +++ b/drivers/char/ppdev.c @@ -296,28 +296,35 @@ static int register_device(int minor, struct pp_struct *pp) if (!port) { pr_warn("%s: no associated port!\n", name); rc = -ENXIO; - goto err; + goto err_free_name; } index = ida_alloc(&ida_index, GFP_KERNEL); + if (index < 0) { + pr_warn("%s: failed to get index!\n", name); + rc = index; + goto err_put_port; + } + memset(&ppdev_cb, 0, sizeof(ppdev_cb)); ppdev_cb.irq_func = pp_irq; ppdev_cb.flags = (pp->flags & PP_EXCL) ? PARPORT_FLAG_EXCL : 0; ppdev_cb.private = pp; pdev = parport_register_dev_model(port, name, &ppdev_cb, index); - parport_put_port(port); if (!pdev) { pr_warn("%s: failed to register device!\n", name); rc = -ENXIO; ida_free(&ida_index, index); - goto err; + goto err_put_port; } pp->pdev = pdev; pp->index = index; dev_dbg(&pdev->dev, "registered pardevice\n"); -err: +err_put_port: + parport_put_port(port); +err_free_name: kfree(name); return rc; } -- 2.43.0