Skip to content

Commit

Permalink
modpost: remove incorrect code in do_eisa_entry()
Browse files Browse the repository at this point in the history
[ Upstream commit 0c3e091319e4748cb36ac9a50848903dc6f54054 ]

This function contains multiple bugs after the following commits:

 - ac55182 ("modpost: i2c aliases need no trailing wildcard")
 - 6543bec ("mod/file2alias: make modalias generation safe for cross compiling")

Commit ac55182 inserted the following code to do_eisa_entry():

    else
            strcat(alias, "*");

This is incorrect because 'alias' is uninitialized. If it is not
NULL-terminated, strcat() could cause a buffer overrun.

Even if 'alias' happens to be zero-filled, it would output:

    MODULE_ALIAS("*");

This would match anything. As a result, the module could be loaded by
any unrelated uevent from an unrelated subsystem.

Commit ac55182 introduced another bug.            

Prior to that commit, the conditional check was:

    if (eisa->sig[0])

This checked if the first character of eisa_device_id::sig was not '\0'.

However, commit ac55182 changed it as follows:

    if (sig[0])

sig[0] is NOT the first character of the eisa_device_id::sig. The
type of 'sig' is 'char (*)[8]', meaning that the type of 'sig[0]' is
'char [8]' instead of 'char'. 'sig[0]' and 'symval' refer to the same
address, which never becomes NULL.

The correct conversion would have been:

    if ((*sig)[0])

However, this if-conditional was meaningless because the earlier change
in commit ac551828993e was incorrect.

This commit removes the entire incorrect code, which should never have
been executed.

Fixes: ac55182 ("modpost: i2c aliases need no trailing wildcard")
Fixes: 6543bec ("mod/file2alias: make modalias generation safe for cross compiling")
Signed-off-by: Masahiro Yamada <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
masahir0y authored and gregkh committed Dec 5, 2024
1 parent 692eb06 commit 94a6159
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions scripts/mod/file2alias.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,10 +763,7 @@ static int do_eisa_entry(const char *filename, void *symval,
char *alias)
{
DEF_FIELD_ADDR(symval, eisa_device_id, sig);
if (sig[0])
sprintf(alias, EISA_DEVICE_MODALIAS_FMT "*", *sig);
else
strcat(alias, "*");
sprintf(alias, EISA_DEVICE_MODALIAS_FMT "*", *sig);
return 1;
}

Expand Down

0 comments on commit 94a6159

Please sign in to comment.