Skip to contentSkip to conversation

proc: fix dereference of ERR_PTR

PATCH In review Sudip Mukherjee 2 participants 2 messages Apr 6, 2016 Proc filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 proc: fix dereference of ERR_PTR

On the unlikely event of a bad name, d_hash_and_lookup() can return the error value in ERR_PTR(). And we were only checking the return value of d_hash_and_lookup() to be NULL. In case it is not NULL and has some error then d_inode() will try to dereference it later.

---
 fs/proc/base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/proc/base.c +1 -1
index b1755b2..a71df53 100644
@@ -1818,7 +1818,7 @@ bool proc_fill_cache(struct file *file, struct dir_context *ctx,
 	ino_t ino;
 
 	child = d_hash_and_lookup(dir, &qname);
-	if (!child) {
+	if (IS_ERR_OR_NULL(child)) {
 		child = d_alloc(dir, &qname);
 		if (!child)
 			goto end_instantiate;
Signature · 1 line
2.1.4
#1 lore raw
Quoted 4 lines · Sudip Mukherjee

On the unlikely event of a bad name, d_hash_and_lookup() can return the error value in ERR_PTR(). And we were only checking the return value of d_hash_and_lookup() to be NULL. In case it is not NULL and has some error then d_inode() will try to dereference it later.

s/unlikely/impossible/ - procfs doesn't _have_ ->d_hash. NAK; at most add a

        /* no ->d_hash() rejects on procfs */

comment as we have next to another call site in procfs.