Commit ac7f1061 authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by Linus Torvalds
Browse files

proc: fix /proc/*/map_files lookup

Current code does:

	if (sscanf(dentry->, "%lx-%lx", start, end) != 2)

However sscanf() is broken garbage.

It silently accepts whitespace between format specifiers
(did you know that?).

It silently accepts valid strings which result in integer overflow.

Do not use sscanf() for any even remotely reliable parsing code.

	# readlink '/proc/1/map_files/55a23af39000-55a23b05b000'

	# readlink '/proc/1/map_files/               55a23af39000-55a23b05b000'

	# readlink '/proc/1/map_files/55a23af39000-55a23b05b000    '

	very broken
	# readlink '/proc/1/map_files/1000000000000000055a23af39000-55a23b05b000'

Andrei said:

: This patch breaks criu.  It was a bug in criu.  And this bug is on a minor
: path, which works when memfd_create() isn't available.  It is a reason why
: I ask to not backport this patch to stable kernels.
: In CRIU this bug can be triggered, only if this patch will be backported
: to a kernel which version is lower than v3.16.


Signed-off-by: default avatarAlexey Dobriyan <>
Cc: Pavel Emelyanov <>
Cc: Andrei Vagin <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 9f7118b2
......@@ -100,6 +100,8 @@
#include "internal.h"
#include "fd.h"
#include "../../lib/kstrtox.h"
/* NOTE:
* Implementing inode permission operations in /proc is almost
* certainly an error. Permission checks need to happen during
......@@ -1906,8 +1908,33 @@ end_instantiate:
static int dname_to_vma_addr(struct dentry *dentry,
unsigned long *start, unsigned long *end)
if (sscanf(dentry->, "%lx-%lx", start, end) != 2)
const char *str = dentry->;
unsigned long long sval, eval;
unsigned int len;
len = _parse_integer(str, 16, &sval);
return -EINVAL;
if (sval != (unsigned long)sval)
return -EINVAL;
str += len;
if (*str != '-')
return -EINVAL;
len = _parse_integer(str, 16, &eval);
return -EINVAL;
if (eval != (unsigned long)eval)
return -EINVAL;
str += len;
if (*str != '\0')
return -EINVAL;
*start = sval;
*end = eval;
return 0;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment