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]
Date:   Thu, 20 May 2021 10:01:50 -0700
From:   Guenter Roeck <linux@...ck-us.net>
To:     Derek Kiernan <derek.kiernan@...inx.com>
Cc:     Dragan Cvetic <dragan.cvetic@...inx.com>,
        Arnd Bergmann <arnd@...db.de>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Michal Simek <michal.simek@...inx.com>,
        linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
        Guenter Roeck <linux@...ck-us.net>
Subject: [RFC PATCH] misc: xilinx-sdfec: Check if file->private_data is NULL

container_of() only returns NULL if the passed pointer is NULL _and_
the embedded element is the first element of the structure. Even if that
is the case, testing against it is misleading and possibly dangerous
because the position of the embedded element may change. Explicitly
check if the parameter is NULL and bail out if so instead of checking
the result of container_of().

Signed-off-by: Guenter Roeck <linux@...ck-us.net>
---
RFC:

The NULL check in the poll function is likely unnecessary. Interestingly,
there is no NULL check in the ioctl function, even though there is a
similar container_of() in that function. However, I do not feel
comfortable enough to change the functionality of this code and drop
the check entirely.

 drivers/misc/xilinx_sdfec.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/misc/xilinx_sdfec.c b/drivers/misc/xilinx_sdfec.c
index 23c8448a9c3b..0a3721d31dea 100644
--- a/drivers/misc/xilinx_sdfec.c
+++ b/drivers/misc/xilinx_sdfec.c
@@ -1011,11 +1011,11 @@ static __poll_t xsdfec_poll(struct file *file, poll_table *wait)
 	__poll_t mask = 0;
 	struct xsdfec_dev *xsdfec;
 
-	xsdfec = container_of(file->private_data, struct xsdfec_dev, miscdev);
-
-	if (!xsdfec)
+	if (!file->private_data)
 		return EPOLLNVAL | EPOLLHUP;
 
+	xsdfec = container_of(file->private_data, struct xsdfec_dev, miscdev);
+
 	poll_wait(file, &xsdfec->waitq, wait);
 
 	/* XSDFEC ISR detected an error */
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ