[PATCH] read_ldt() neglects to check clear_user() return value

From: Jesper Juhl
Date: Mon Aug 30 2004 - 18:07:52 EST



Hi,

I just noticed a small warning when building 2.6.9-rc1-bk6 :

arch/i386/kernel/ldt.c: In function read_ldt':
arch/i386/kernel/ldt.c:148: warning: ignoring return value of clear_user', declared with attribute warn_unused_result

So I went to investigate, and indeed, read_ldt() does neglect to check the
return value from clear_user().
I propose the patch below to fix it, but I'm not 100% sure that returning
-EFAULT is the correct thing to do here, so please review.
It /seems/ to me that -EFAULT is appropriate in this case, it would make
sense to me - if we can't clear the rest of the memory pointed to by the
user*, surely that should generate a FAULT - or?
The kernel builds fine with this change applied (and does kill the warning
of course).
The kernel boots fine with this change (running it at the moment and so
far I've not noticed any ill effects).

Signed-off-by: Jesper Juhl <juhl-lkml@xxxxxx>

diff -up linux-2.6.9-rc1-bk6/arch/i386/kernel/ldt.c~ linux-2.6.9-rc1-bk6/arch/i386/kernel/ldt.c
--- linux-2.6.9-rc1-bk6/arch/i386/kernel/ldt.c~ 2004-08-31 00:36:22.000000000 +0200
+++ linux-2.6.9-rc1-bk6/arch/i386/kernel/ldt.c 2004-08-31 00:36:22.000000000 +0200
@@ -142,12 +142,17 @@ static int read_ldt(void __user * ptr, u
err = -EFAULT;
up(&mm->context.sem);
if (err < 0)
- return err;
+ goto error_return;
if (size != bytecount) {
/* zero-fill the rest */
- clear_user(ptr+size, bytecount-size);
+ if (clear_user(ptr+size, bytecount-size) != 0) {
+ err = -EFAULT;
+ goto error_return;
+ }
}
return bytecount;
+error_return:
+ return err;
}

static int read_default_ldt(void __user * ptr, unsigned long bytecount)


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/