[PATCH 2/4] initramfs: mark dirp as a __user pointer on clean_rootfs()

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Namhyung Kim
Date: Wednesday, August 18, 2010 - 8:37 pm

dirp is used for calling syscall routines so it would be better to be a user
pointer unless we want to cast it on every syscalls.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
 init/initramfs.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/init/initramfs.c b/init/initramfs.c
index 75a43c5..d90d1cf 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -526,7 +526,7 @@ static void __init clean_rootfs(void)
 {
 	int fd;
 	void *buf;
-	struct linux_dirent64 *dirp;
+	struct linux_dirent64 __user *dirp;
 	int num;
 
 	fd = sys_open((const char __user __force *) "/", O_RDONLY, 0);
@@ -540,14 +540,16 @@ static void __init clean_rootfs(void)
 		return;
 	}
 
-	dirp = buf;
+	dirp = (struct linux_dirent64 __user __force *) buf;
 	num = sys_getdents64(fd, dirp, BUF_SIZE);
 	while (num > 0) {
 		while (num > 0) {
 			struct stat st;
 			int ret;
+			unsigned short len;
 
-			ret = sys_newlstat(dirp->d_name, &st);
+			ret = sys_newlstat(dirp->d_name,
+					   (struct stat __user __force *)&st);
 			WARN_ON_ONCE(ret);
 			if (!ret) {
 				if (S_ISDIR(st.st_mode))
@@ -556,10 +558,11 @@ static void __init clean_rootfs(void)
 					sys_unlink(dirp->d_name);
 			}
 
-			num -= dirp->d_reclen;
-			dirp = (void *)dirp + dirp->d_reclen;
+			len = ((struct linux_dirent64 __force *) dirp)->d_reclen;
+			num -= len;
+			dirp = (void __user *)dirp + len;
 		}
-		dirp = buf;
+		dirp = (struct linux_dirent64 __user __force *) buf;
 		memset(buf, 0, BUF_SIZE);
 		num = sys_getdents64(fd, dirp, BUF_SIZE);
 	}
-- 
1.7.0.4

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/4] initramfs: remove sparse warnings, Namhyung Kim, (Wed Aug 18, 8:37 pm)
[PATCH 1/4] initramfs: refactor clean_path(), Namhyung Kim, (Wed Aug 18, 8:37 pm)
[PATCH 2/4] initramfs: mark dirp as a __user pointer on cl ..., Namhyung Kim, (Wed Aug 18, 8:37 pm)
[PATCH 4/4] initramfs: add missing __user markup, Namhyung Kim, (Wed Aug 18, 8:37 pm)
Re: [PATCH 0/4] initramfs: remove sparse warnings, Arnd Bergmann, (Thu Aug 19, 7:38 am)
Re: [PATCH 0/4] initramfs: remove sparse warnings, Namhyung Kim, (Thu Aug 19, 9:57 am)
Re: [PATCH 0/4] initramfs: remove sparse warnings, Namhyung Kim, (Fri Aug 20, 8:36 am)
Re: [PATCH 0/4] initramfs: remove sparse warnings, Arnd Bergmann, (Sun Aug 22, 1:33 pm)
Re: [PATCH 0/4] initramfs: remove sparse warnings, Namhyung Kim, (Mon Aug 23, 7:59 am)