diff mbox series

[2/5] modpost: fix ishtp MODULE_DEVICE_TABLE built on big endian host

Message ID 20231007170448.505487-2-masahiroy@kernel.org (mailing list archive)
State New, archived
Headers show
Series [1/5] modpost: fix tee MODULE_DEVICE_TABLE built on big endian host | expand

Commit Message

Masahiro Yamada Oct. 7, 2023, 5:04 p.m. UTC
When MODULE_DEVICE_TABLE(ishtp, ) is built on a host with a different
endianness from the target architecture, it results in an incorrect
MODULE_ALIAS().

For example, see a case where drivers/platform/x86/intel/ishtp_eclite.c
is built as a module.

If you build it on a little endian host, you will get the correct
MODULE_ALIAS:

    $ grep MODULE_ALIAS drivers/platform/x86/intel/ishtp_eclite.mod.c
    MODULE_ALIAS("ishtp:{6A19CC4B-D760-4DE3-B14D-F25EBD0FBCD9}");

However, if you build it on a big endian host, you will get a wrong
MODULE_ALIAS:

    $ grep MODULE_ALIAS drivers/platform/x86/intel/ishtp_eclite.mod.c
    MODULE_ALIAS("ishtp:{BD0FBCD9-F25E-B14D-4DE3-D7606A19CC4B}");

This issue has been unnoticed because the x86 kernel is most likely built
natively on an x86 host.

The guid field must not be reversed because guid_t is an array of __u8.

Fixes: fa443bc3c1e4 ("HID: intel-ish-hid: add support for MODULE_DEVICE_TABLE()")
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/file2alias.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Thomas Weißschuh Oct. 8, 2023, 7:51 a.m. UTC | #1
On 2023-10-08 02:04:45+0900, Masahiro Yamada wrote:
> When MODULE_DEVICE_TABLE(ishtp, ) is built on a host with a different
> endianness from the target architecture, it results in an incorrect
> MODULE_ALIAS().
> 
> For example, see a case where drivers/platform/x86/intel/ishtp_eclite.c
> is built as a module.

Nitpick:

... [as a module] for x86.

So the statements below can be interpreted correctly.

> 
> If you build it on a little endian host, you will get the correct
> MODULE_ALIAS:
> 
>     $ grep MODULE_ALIAS drivers/platform/x86/intel/ishtp_eclite.mod.c
>     MODULE_ALIAS("ishtp:{6A19CC4B-D760-4DE3-B14D-F25EBD0FBCD9}");
> 
> However, if you build it on a big endian host, you will get a wrong
> MODULE_ALIAS:
> 
>     $ grep MODULE_ALIAS drivers/platform/x86/intel/ishtp_eclite.mod.c
>     MODULE_ALIAS("ishtp:{BD0FBCD9-F25E-B14D-4DE3-D7606A19CC4B}");
> 
> This issue has been unnoticed because the x86 kernel is most likely built
> natively on an x86 host.
> 
> The guid field must not be reversed because guid_t is an array of __u8.
> 
> Fixes: fa443bc3c1e4 ("HID: intel-ish-hid: add support for MODULE_DEVICE_TABLE()")

+ Cc: stable@vger.kernel.org

> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

Reviewed-by: Thomas Weißschuh <linux@weissschuh.net>

Thanks!

> ---
> 
>  scripts/mod/file2alias.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
> index 70bf6a2f585c..6583b36dbe69 100644
> --- a/scripts/mod/file2alias.c
> +++ b/scripts/mod/file2alias.c
> @@ -1401,10 +1401,10 @@ static int do_mhi_ep_entry(const char *filename, void *symval, char *alias)
>  /* Looks like: ishtp:{guid} */
>  static int do_ishtp_entry(const char *filename, void *symval, char *alias)
>  {
> -	DEF_FIELD(symval, ishtp_device_id, guid);
> +	DEF_FIELD_ADDR(symval, ishtp_device_id, guid);
>  
>  	strcpy(alias, ISHTP_MODULE_PREFIX "{");
> -	add_guid(alias, guid);
> +	add_guid(alias, *guid);
>  	strcat(alias, "}");
>  
>  	return 1;
> -- 
> 2.39.2
>
srinivas pandruvada Oct. 9, 2023, 4:50 p.m. UTC | #2
On Sun, 2023-10-08 at 09:51 +0200, Thomas Weißschuh wrote:
> On 2023-10-08 02:04:45+0900, Masahiro Yamada wrote:
> > When MODULE_DEVICE_TABLE(ishtp, ) is built on a host with a
> > different
> > endianness from the target architecture, it results in an incorrect
> > MODULE_ALIAS().
> > 
> > For example, see a case where
> > drivers/platform/x86/intel/ishtp_eclite.c
> > is built as a module.
> 
> Nitpick:
> 
> ... [as a module] for x86.
> 
> So the statements below can be interpreted correctly.
> 
> > 
> > If you build it on a little endian host, you will get the correct
> > MODULE_ALIAS:
> > 
> >     $ grep MODULE_ALIAS
> > drivers/platform/x86/intel/ishtp_eclite.mod.c
> >     MODULE_ALIAS("ishtp:{6A19CC4B-D760-4DE3-B14D-F25EBD0FBCD9}");
> > 
> > However, if you build it on a big endian host, you will get a wrong
> > MODULE_ALIAS:
> > 
> >     $ grep MODULE_ALIAS
> > drivers/platform/x86/intel/ishtp_eclite.mod.c
> >     MODULE_ALIAS("ishtp:{BD0FBCD9-F25E-B14D-4DE3-D7606A19CC4B}");
> > 
> > This issue has been unnoticed because the x86 kernel is most likely
> > built
> > natively on an x86 host.
> > 
> > The guid field must not be reversed because guid_t is an array of
> > __u8.
> > 
> > Fixes: fa443bc3c1e4 ("HID: intel-ish-hid: add support for
> > MODULE_DEVICE_TABLE()")
> 
> + Cc: stable@vger.kernel.org
> 
> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> 
> Reviewed-by: Thomas Weißschuh <linux@weissschuh.net>

Tested-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>

Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>

Thanks,
Srinivas

> 
> Thanks!
> 
> > ---
> > 
> >  scripts/mod/file2alias.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
> > index 70bf6a2f585c..6583b36dbe69 100644
> > --- a/scripts/mod/file2alias.c
> > +++ b/scripts/mod/file2alias.c
> > @@ -1401,10 +1401,10 @@ static int do_mhi_ep_entry(const char
> > *filename, void *symval, char *alias)
> >  /* Looks like: ishtp:{guid} */
> >  static int do_ishtp_entry(const char *filename, void *symval, char
> > *alias)
> >  {
> > -       DEF_FIELD(symval, ishtp_device_id, guid);
> > +       DEF_FIELD_ADDR(symval, ishtp_device_id, guid);
> >  
> >         strcpy(alias, ISHTP_MODULE_PREFIX "{");
> > -       add_guid(alias, guid);
> > +       add_guid(alias, *guid);
> >         strcat(alias, "}");
> >  
> >         return 1;
> > -- 
> > 2.39.2
> >
Masahiro Yamada Oct. 14, 2023, 2:38 p.m. UTC | #3
On Sun, Oct 8, 2023 at 4:51 PM Thomas Weißschuh <linux@weissschuh.net> wrote:
>
> On 2023-10-08 02:04:45+0900, Masahiro Yamada wrote:
> > When MODULE_DEVICE_TABLE(ishtp, ) is built on a host with a different
> > endianness from the target architecture, it results in an incorrect
> > MODULE_ALIAS().
> >
> > For example, see a case where drivers/platform/x86/intel/ishtp_eclite.c
> > is built as a module.
>
> Nitpick:
>
> ... [as a module] for x86.
>
> So the statements below can be interpreted correctly.


OK, I fixed up the comment when I applied the patch.
Thanks.
diff mbox series

Patch

diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 70bf6a2f585c..6583b36dbe69 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -1401,10 +1401,10 @@  static int do_mhi_ep_entry(const char *filename, void *symval, char *alias)
 /* Looks like: ishtp:{guid} */
 static int do_ishtp_entry(const char *filename, void *symval, char *alias)
 {
-	DEF_FIELD(symval, ishtp_device_id, guid);
+	DEF_FIELD_ADDR(symval, ishtp_device_id, guid);
 
 	strcpy(alias, ISHTP_MODULE_PREFIX "{");
-	add_guid(alias, guid);
+	add_guid(alias, *guid);
 	strcat(alias, "}");
 
 	return 1;