lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230417195003.19504-1-korotkov.maxim.s@gmail.com>
Date:   Mon, 17 Apr 2023 22:50:03 +0300
From:   Maxim Korotkov <korotkov.maxim.s@...il.com>
To:     Heikki Krogerus <heikki.krogerus@...ux.intel.com>
Cc:     Maxim Korotkov <korotkov.maxim.s@...il.com>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        linux-usb@...r.kernel.org, linux-kernel@...r.kernel.org,
        lvc-project@...uxtesting.org
Subject: [PATCH] usb: typec: fix potential NULL dereference

The pointer 'adev' was being dereferenced before being checked for NULL
in the 'type_alt mode_enter()' and 'type_alt mode_exit()' functions.
Although this is a hypothetical issue, it's better to move the pointer
assignment after the NULL check to avoid any potential problems.

Found by Linux Verification Center with Svace static analyzer.

Fixes: 8a37d87d72f0 ("usb: typec: Bus type for alternate modes")
Signed-off-by: Maxim Korotkov <korotkov.maxim.s@...il.com>
---
 drivers/usb/typec/bus.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/typec/bus.c b/drivers/usb/typec/bus.c
index 098f0efaa58d..ae0aca8f33db 100644
--- a/drivers/usb/typec/bus.c
+++ b/drivers/usb/typec/bus.c
@@ -125,13 +125,16 @@ EXPORT_SYMBOL_GPL(typec_altmode_notify);
  */
 int typec_altmode_enter(struct typec_altmode *adev, u32 *vdo)
 {
-	struct altmode *partner = to_altmode(adev)->partner;
-	struct typec_altmode *pdev = &partner->adev;
+	struct altmode *partner;
+	struct typec_altmode *pdev;
 	int ret;
 
 	if (!adev || adev->active)
 		return 0;
 
+	partner = to_altmode(adev)->partner;
+	pdev = &partner->adev;
+
 	if (!pdev->ops || !pdev->ops->enter)
 		return -EOPNOTSUPP;
 
@@ -156,13 +159,15 @@ EXPORT_SYMBOL_GPL(typec_altmode_enter);
  */
 int typec_altmode_exit(struct typec_altmode *adev)
 {
-	struct altmode *partner = to_altmode(adev)->partner;
-	struct typec_altmode *pdev = &partner->adev;
+	struct altmode *partner;
+	struct typec_altmode *pdev;
 	int ret;
 
 	if (!adev || !adev->active)
 		return 0;
 
+	partner = to_altmode(adev)->partner;
+	pdev = &partner->adev;
 	if (!pdev->ops || !pdev->ops->exit)
 		return -EOPNOTSUPP;
 
-- 
2.37.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ