linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@gmail.com>
To: Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 2/4] initramfs: mark dirp as a __user pointer on clean_rootfs()
Date: Thu, 19 Aug 2010 12:37:42 +0900	[thread overview]
Message-ID: <1282189064-3904-3-git-send-email-namhyung@gmail.com> (raw)
In-Reply-To: <1282189064-3904-1-git-send-email-namhyung@gmail.com>

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


  parent reply	other threads:[~2010-08-19  3:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-19  3:37 [PATCH 0/4] initramfs: remove sparse warnings Namhyung Kim
2010-08-19  3:37 ` [PATCH 1/4] initramfs: refactor clean_path() Namhyung Kim
2010-08-19  3:37 ` Namhyung Kim [this message]
2010-08-19  3:37 ` [PATCH 3/4] initramfs: mark collect buffers as __user pointers Namhyung Kim
2010-08-19  3:37 ` [PATCH 4/4] initramfs: add missing __user markup Namhyung Kim
2010-08-19 14:38 ` [PATCH 0/4] initramfs: remove sparse warnings Arnd Bergmann
2010-08-19 16:57   ` Namhyung Kim
2010-08-20 12:00   ` Al Viro
2010-08-20 15:36     ` Namhyung Kim
2010-08-22 20:33       ` Arnd Bergmann
2010-08-23 14:59         ` Namhyung Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1282189064-3904-3-git-send-email-namhyung@gmail.com \
    --to=namhyung@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).