mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-11-06 17:39:01 +01:00
proc: fix the issue of proc_mem_open returning NULL
proc_mem_open() can return an errno, NULL, or mm_struct*. If it fails to
acquire mm, it returns NULL, but the caller does not check for the case
when the return value is NULL.
The following conditions lead to failure in acquiring mm:
- The task is a kernel thread (PF_KTHREAD)
- The task is exiting (PF_EXITING)
Changes:
- Add documentation comments for the return value of proc_mem_open().
- Add checks in the caller to return -ESRCH when proc_mem_open()
returns NULL.
Link: https://lkml.kernel.org/r/[email protected]
Reported-by: [email protected]
Closes: https://lore.kernel.org/all/[email protected]
Signed-off-by: Penglei Jiang <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Adrian Ratiu <[email protected]>
Cc: Christian Brauner <[email protected]>
Cc: Felix Moessbauer <[email protected]>
Cc: Jeff layton <[email protected]>
Cc: Lorenzo Stoakes <[email protected]>
Cc: Mateusz Guzik <[email protected]>
Cc: Thomas Gleinxer <[email protected]>
Cc: xu xin <[email protected]>
Cc: Alexey Dobriyan <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
This commit is contained in:
1 parent
3dfd79cc87
commit
65c6604725
3 files changed
+17
-11
No files matched your search
+9
-3
@@ -827,7 +827,13 @@ static const struct file_operations proc_single_file_operations = {
|
||||
.release = single_release,
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* proc_mem_open() can return errno, NULL or mm_struct*.
|
||||
*
|
||||
* - Returns NULL if the task has no mm (PF_KTHREAD or PF_EXITING)
|
||||
* - Returns mm_struct* on success
|
||||
* - Returns error code on failure
|
||||
*/
|
||||
struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode)
|
||||
{
|
||||
struct task_struct *task = get_proc_task(inode);
|
||||
@@ -854,8 +860,8 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
|
||||
{
|
||||
struct mm_struct *mm = proc_mem_open(inode, mode);
|
||||
|
||||
if (IS_ERR(mm))
|
||||
return PTR_ERR(mm);
|
||||
if (IS_ERR_OR_NULL(mm))
|
||||
return mm ? PTR_ERR(mm) : -ESRCH;
|
||||
|
||||
file->private_data = mm;
|
||||
return 0;
|
||||
|
||||
+6
-6
@@ -212,8 +212,8 @@ static int proc_maps_open(struct inode *inode, struct file *file,
|
||||
|
||||
priv->inode = inode;
|
||||
priv->mm = proc_mem_open(inode, PTRACE_MODE_READ);
|
||||
if (IS_ERR(priv->mm)) {
|
||||
int err = PTR_ERR(priv->mm);
|
||||
if (IS_ERR_OR_NULL(priv->mm)) {
|
||||
int err = priv->mm ? PTR_ERR(priv->mm) : -ESRCH;
|
||||
|
||||
seq_release_private(inode, file);
|
||||
return err;
|
||||
@@ -1325,8 +1325,8 @@ static int smaps_rollup_open(struct inode *inode, struct file *file)
|
||||
|
||||
priv->inode = inode;
|
||||
priv->mm = proc_mem_open(inode, PTRACE_MODE_READ);
|
||||
if (IS_ERR(priv->mm)) {
|
||||
ret = PTR_ERR(priv->mm);
|
||||
if (IS_ERR_OR_NULL(priv->mm)) {
|
||||
ret = priv->mm ? PTR_ERR(priv->mm) : -ESRCH;
|
||||
|
||||
single_release(inode, file);
|
||||
goto out_free;
|
||||
@@ -2069,8 +2069,8 @@ static int pagemap_open(struct inode *inode, struct file *file)
|
||||
struct mm_struct *mm;
|
||||
|
||||
mm = proc_mem_open(inode, PTRACE_MODE_READ);
|
||||
if (IS_ERR(mm))
|
||||
return PTR_ERR(mm);
|
||||
if (IS_ERR_OR_NULL(mm))
|
||||
return mm ? PTR_ERR(mm) : -ESRCH;
|
||||
file->private_data = mm;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -260,8 +260,8 @@ static int maps_open(struct inode *inode, struct file *file,
|
||||
|
||||
priv->inode = inode;
|
||||
priv->mm = proc_mem_open(inode, PTRACE_MODE_READ);
|
||||
if (IS_ERR(priv->mm)) {
|
||||
int err = PTR_ERR(priv->mm);
|
||||
if (IS_ERR_OR_NULL(priv->mm)) {
|
||||
int err = priv->mm ? PTR_ERR(priv->mm) : -ESRCH;
|
||||
|
||||
seq_release_private(inode, file);
|
||||
return err;
|
||||
|
||||
Reference in new issue
Block a user