2009-07-25 02:10:30

by Dave Jones

[permalink] [raw]
Subject: [PATCH] Don't export scsi kernel variables in userspace headers.

Found with make headers_check

/usr/include/scsi/scsi.h:159: userspace cannot call function or variable defined in the kernel
/usr/include/scsi/scsi.h:285: userspace cannot call function or variable defined in the kernel

Signed-off-by: Dave Jones <[email protected]>

diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index 084478e..689570e 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -156,7 +156,9 @@ scsi_varlen_cdb_length(const void *hdr)
return ((struct scsi_varlen_cdb_hdr *)hdr)->additional_cdb_length + 8;
}

+#ifdef __KERNEL__
extern const unsigned char scsi_command_size_tbl[8];
+#endif
#define COMMAND_SIZE(opcode) scsi_command_size_tbl[((opcode) >> 5) & 7]

static inline unsigned
@@ -281,8 +283,10 @@ enum scsi_protocol {
SCSI_PROTOCOL_UNSPEC = 0xf, /* No specific protocol */
};

+#ifdef __KERNEL__
/* Returns a human-readable name for the device */
extern const char * scsi_device_type(unsigned type);
+#endif

/*
* standard mode-select header prepended to all mode-select commands


2009-07-26 22:14:26

by Matthew Wilcox

[permalink] [raw]
Subject: Re: [PATCH] Don't export scsi kernel variables in userspace headers.

On Fri, Jul 24, 2009 at 10:10:26PM -0400, Dave Jones wrote:
> +++ b/include/scsi/scsi.h
> @@ -156,7 +156,9 @@ scsi_varlen_cdb_length(const void *hdr)
> return ((struct scsi_varlen_cdb_hdr *)hdr)->additional_cdb_length + 8;
> }
>
> +#ifdef __KERNEL__
> extern const unsigned char scsi_command_size_tbl[8];
> +#endif
> #define COMMAND_SIZE(opcode) scsi_command_size_tbl[((opcode) >> 5) & 7]
>
> static inline unsigned

Probably should move that #endif down -- it's not like userspace can
use the COMMAND_SIZE macro (should headers_check also check for this?)

Also scsi_command_size() isn't usable by userspace either, since it uses
COMMAND_SIZE.

--
Matthew Wilcox Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours. We can't possibly take such
a retrograde step."

2009-07-27 07:44:19

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH] Don't export scsi kernel variables in userspace headers.

On Fri, Jul 24, 2009 at 10:10:26PM -0400, Dave Jones wrote:
> Found with make headers_check
>
> /usr/include/scsi/scsi.h:159: userspace cannot call function or variable defined in the kernel
> /usr/include/scsi/scsi.h:285: userspace cannot call function or variable defined in the kernel

The headers shouldn't be exported at all because scsi/ headers are
exported from glibc.

2009-07-27 08:26:26

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH] Don't export scsi kernel variables in userspace headers.

On Mon, Jul 27, 2009 at 03:44:18AM -0400, Christoph Hellwig wrote:
> On Fri, Jul 24, 2009 at 10:10:26PM -0400, Dave Jones wrote:
> > Found with make headers_check
> >
> > /usr/include/scsi/scsi.h:159: userspace cannot call function or variable defined in the kernel
> > /usr/include/scsi/scsi.h:285: userspace cannot call function or variable defined in the kernel
>
> The headers shouldn't be exported at all because scsi/ headers are
> exported from glibc.
Where does glibc get these headers from?

If glibc have their own private copy then the headers should indeed be exported
so we avoid such mess.

Sam

2009-07-27 08:37:23

by Boaz Harrosh

[permalink] [raw]
Subject: Re: [PATCH] Don't export scsi kernel variables in userspace headers.

On 07/27/2009 11:26 AM, Sam Ravnborg wrote:
> On Mon, Jul 27, 2009 at 03:44:18AM -0400, Christoph Hellwig wrote:
>> On Fri, Jul 24, 2009 at 10:10:26PM -0400, Dave Jones wrote:
>>> Found with make headers_check
>>>
>>> /usr/include/scsi/scsi.h:159: userspace cannot call function or variable defined in the kernel
>>> /usr/include/scsi/scsi.h:285: userspace cannot call function or variable defined in the kernel
>> The headers shouldn't be exported at all because scsi/ headers are
>> exported from glibc.
> Where does glibc get these headers from?
>
> If glibc have their own private copy then the headers should indeed be exported
> so we avoid such mess.
>
> Sam

We never had a Kbuild file in include/scsi. It was only added recently by the fcoe patchset.
scsi.h is not the only problem. All of /usr/include/scsi/* come from glibc private snapshot.

I agree with Sam that this is a complete mess, and that Kernel should take control back.
But someone should do it in an orderly manner. Clean up all the headers to be safe for
user mode and send notifications/patches to glibc, and the distributions must know that
they might be geting same files from two packages for a while.

Would we want a Kconfig option for a while, like SCSI_EXPORT_HEADERS so it can be turned
off?

Boaz