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 3/4] initramfs: mark collect buffers as __user pointers
Date: Thu, 19 Aug 2010 12:37:43 +0900 [thread overview]
Message-ID: <1282189064-3904-4-git-send-email-namhyung@gmail.com> (raw)
In-Reply-To: <1282189064-3904-1-git-send-email-namhyung@gmail.com>
collected, vcollected, collect are used for syscall routines so it would be
better to be __user pointers. We can add __user/__force markup on every calls
but marking them as user pointers requires less change.
Impact: remove sparse warnings, no functional change
Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
init/initramfs.c | 45 +++++++++++++++++++++++++--------------------
1 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/init/initramfs.c b/init/initramfs.c
index d90d1cf..2aa8c96 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -174,19 +174,19 @@ static inline void __init eat(unsigned n)
count -= n;
}
-static __initdata char *vcollected;
-static __initdata char *collected;
+static __initdata char __user *vcollected;
+static __initdata char __user *collected;
static __initdata int remains;
-static __initdata char *collect;
+static __initdata char __user *collect;
static void __init read_into(char *buf, unsigned size, enum state next)
{
if (count >= size) {
- collected = victim;
+ collected = (char __user __force *) victim;
eat(size);
state = next;
} else {
- collect = collected = buf;
+ collect = collected = (char __user __force *) buf;
remains = size;
next_state = next;
state = Collect;
@@ -206,7 +206,7 @@ static int __init do_collect(void)
unsigned n = remains;
if (count < n)
n = count;
- memcpy(collect, victim, n);
+ copy_to_user(collect, victim, n);
eat(n);
collect += n;
if ((remains -= n) != 0)
@@ -217,15 +217,15 @@ static int __init do_collect(void)
static int __init do_header(void)
{
- if (memcmp(collected, "070707", 6)==0) {
+ if (memcmp((char __force *)collected, "070707", 6)==0) {
error("incorrect cpio method used: use -H newc option");
return 1;
}
- if (memcmp(collected, "070701", 6)) {
+ if (memcmp((char __force *)collected, "070701", 6)) {
error("no cpio magic");
return 1;
}
- parse_header(collected);
+ parse_header((char __force *)collected);
next_header = this_header + N_ALIGN(name_len) + body_len;
next_header = (next_header + 3) & ~3;
state = SkipIt;
@@ -234,7 +234,7 @@ static int __init do_header(void)
if (S_ISLNK(mode)) {
if (body_len > PATH_MAX)
return 0;
- collect = collected = symlink_buf;
+ collect = collected = (char __user __force *) symlink_buf;
remains = N_ALIGN(name_len) + body_len;
next_state = GotSymlink;
state = Collect;
@@ -269,9 +269,12 @@ static int __init do_reset(void)
static int __init maybe_link(void)
{
if (nlink >= 2) {
- char *old = find_link(major, minor, ino, mode, collected);
- if (old)
- return (sys_link(old, collected) < 0) ? -1 : 1;
+ char *old = find_link(major, minor, ino, mode,
+ (char __force *) collected);
+ if (old) {
+ char __user *uold = (char __user __force *) old;
+ return (sys_link(uold, collected) < 0) ? -1 : 1;
+ }
}
return 0;
}
@@ -295,7 +298,7 @@ static int __init do_name(void)
{
state = SkipIt;
next_state = Reset;
- if (strcmp(collected, "TRAILER!!!") == 0) {
+ if (strcmp((char __force *)collected, "TRAILER!!!") == 0) {
free_hash();
return 0;
}
@@ -313,7 +316,9 @@ static int __init do_name(void)
sys_fchmod(wfd, mode);
if (body_len)
sys_ftruncate(wfd, body_len);
- vcollected = kstrdup(collected, GFP_KERNEL);
+ vcollected = (char __user __force *)
+ kstrdup((char __force *)collected,
+ GFP_KERNEL);
state = CopyFile;
}
}
@@ -321,7 +326,7 @@ static int __init do_name(void)
sys_mkdir(collected, mode);
sys_chown(collected, uid, gid);
sys_chmod(collected, mode);
- dir_add(collected, mtime);
+ dir_add((char __force *)collected, mtime);
} else if (S_ISBLK(mode) || S_ISCHR(mode) ||
S_ISFIFO(mode) || S_ISSOCK(mode)) {
if (maybe_link() == 0) {
@@ -337,15 +342,15 @@ static int __init do_name(void)
static int __init do_copy(void)
{
if (count >= body_len) {
- sys_write(wfd, victim, body_len);
+ sys_write(wfd, (char __user __force *)victim, body_len);
sys_close(wfd);
do_utime(vcollected, mtime);
- kfree(vcollected);
+ kfree((void __force *)vcollected);
eat(body_len);
state = SkipIt;
return 0;
} else {
- sys_write(wfd, victim, count);
+ sys_write(wfd, (char __user __force *)victim, count);
body_len -= count;
eat(count);
return 1;
@@ -354,7 +359,7 @@ static int __init do_copy(void)
static int __init do_symlink(void)
{
- collected[N_ALIGN(name_len) + body_len] = '\0';
+ put_user('\0', collected + N_ALIGN(name_len) + body_len);
clean_path(collected, 0);
sys_symlink(collected + N_ALIGN(name_len), collected);
sys_lchown(collected, uid, gid);
--
1.7.0.4
next prev 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 ` [PATCH 2/4] initramfs: mark dirp as a __user pointer on clean_rootfs() Namhyung Kim
2010-08-19 3:37 ` Namhyung Kim [this message]
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-4-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).