Re: [PATCH] Kill a sparse warning in binfmt_elf.c

From: Valdis . Kletnieks
Date: Thu Oct 07 2004 - 14:26:01 EST


On Thu, 07 Oct 2004 12:01:19 PDT, Arun Sharma said:

> Many callers in binfmt_elf.c are passing pointers that are kernel addresses.
> But file_operations->write() is expecting a __user pointer. The intention of
> the cast is to explicitly say that's an okay thing to do.

Right. My point was that if you're fixing the warning, you should do the
*whole* job by making sure that what *you* got in that 'void *' is a __user
pointer, rather than just saying "we know write() wants a __user".

So for instance, up a level in writenote():

#define DUMP_WRITE(addr, nr) do { if (!dump_write(file, (addr), (nr))) return 0; } while(0)
#define DUMP_SEEK(off) do { if (!dump_seek(file, (off))) return 0; } while(0)

static int writenote(struct memelfnote *men, struct file *file)
{
struct elf_note en;

en.n_namesz = strlen(men->name) + 1;
en.n_descsz = men->datasz;
en.n_type = men->type;

DUMP_WRITE(&en, sizeof(en));
DUMP_WRITE(men->name, en.n_namesz);

Is men->name a __user pointer? Should it be? Can it be something else?

struct memelfnote
{
const char *name;
int type;
unsigned int datasz;
void *data;
};

Hmm.. there it's a 'const char *name', but we feed it to a 'const void *'
and then you cast it to a __user. Either that *name should be __user
as well, or you tagged something as a __user that might not be.

*That*s what I'm talking about....

Attachment: pgp00000.pgp
Description: PGP signature