Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pidfs: fix pidfs_free_pid()

Ensure that we handle the case where task creation fails and pid->attr
was never accessed at all.

Signed-off-by: Christian Brauner <brauner@kernel.org>

+10 -8
+10 -8
fs/pidfs.c
··· 150 150 */ 151 151 VFS_WARN_ON_ONCE(pid->stashed); 152 152 153 + /* 154 + * This if an error occurred during e.g., task creation that 155 + * causes us to never go through the exit path. 156 + */ 157 + if (unlikely(!attr)) 158 + return; 159 + 160 + /* This never had a pidfd created. */ 153 161 if (IS_ERR(attr)) 154 162 return; 155 163 156 - /* 157 - * Any dentry must've been wiped from the pid by now. Otherwise 158 - * there's a reference count bug. 159 - */ 160 - VFS_WARN_ON_ONCE(pid->stashed); 161 - 162 - xattrs = attr->xattrs; 164 + xattrs = no_free_ptr(attr->xattrs); 163 165 if (xattrs) 164 - simple_xattrs_free(attr->xattrs, NULL); 166 + simple_xattrs_free(xattrs, NULL); 165 167 } 166 168 167 169 #ifdef CONFIG_PROC_FS