* [PATCH] kernfs: Add check for NULL pointer before writing to it.
@ 2018-11-20 8:38 Ashish Mhetre
0 siblings, 0 replies; only message in thread
From: Ashish Mhetre @ 2018-11-20 8:38 UTC (permalink / raw)
To: tj, linux-kernel; +Cc: linux-tegra, vdumpa, Snikam, Bo Yan, Ashish Mhetre
From: Bo Yan <byan@nvidia.com>
The strlcpy function returns the length of source pointer when the
requested size is 0. This behavior is relied upon for sched tracing.
We can't simply return when buf is 0, but we have to protect against the
scenario when buf is 0 and requested size is non-zero, in which case the
strlcpy would lead to illegal memory access.
This issue is reported by coverity as strlcpy might end up using a NULL
buffer and non-zero buf_length value.
To avoid this, add check and return -EINVAL in this case.
Signed-off-by: Bo Yan <byan@nvidia.com>
Signed-off-by: Ashish Mhetre <amhetre@nvidia.com>
---
fs/kernfs/dir.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 4ca0b5c..76c85a5 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -129,6 +129,9 @@ static int kernfs_path_from_node_locked(struct kernfs_node *kn_to,
size_t depth_from, depth_to, len = 0;
int i, j;
+ if (WARN_ON(!buf && buflen > 0))
+ return -EINVAL;
+
if (!kn_to)
return strlcpy(buf, "(null)", buflen);
--
2.7.4
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-11-20 8:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-20 8:38 [PATCH] kernfs: Add check for NULL pointer before writing to it Ashish Mhetre
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®