Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

KunWuChan
Copy link

@KunWuChan KunWuChan commented Sep 20, 2023

Use the snprintf function instead of sprintf in the meltdown.c file to prevent buffer overflow.
Cause the length of the release in a struct utsname is unspecified.

struct utsname {
char sysname[]; /* Operating system name (e.g., "Linux") /
char nodename[]; /
Name within communications network
to which the node is attached, if any /
char release[]; /
Operating system release
(e.g., "2.6.28") /
char version[]; /
Operating system version /
char machine[]; /
Hardware type identifier /
#ifdef _GNU_SOURCE
char domainname[]; /
NIS or YP domain name */
#endif
};

Signed-off-by: Kunwu Chan chentao@kylinos.cn

Use the snprintf function instead of sprintf in the meltdown.c file to prevent buffer overflow.
Cause the  length of the release in a struct utsname is unspecified.
struct utsname {
               char sysname[];    /* Operating system name (e.g., "Linux") */
               char nodename[];   /* Name within communications network
                                     to which the node is attached, if any */
               char release[];    /* Operating system release
                                     (e.g., "2.6.28") */
               char version[];    /* Operating system version */
               char machine[];    /* Hardware type identifier */
           #ifdef _GNU_SOURCE
               char domainname[]; /* NIS or YP domain name */
           #endif
           };
@richiejp
Copy link
Contributor

It appears that the struct member in question has its length specified by the libc implementation and can be accessed with sizeof. This is stated in the man page.

if (uname(&utsname) < 0)
tst_brk(TBROK | TERRNO, "uname");
sprintf(systemmap, "/boot/System.map-%s", utsname.release);
snprintf(systemmap, sizeof(systemmap), "/boot/System.map-%s", utsname.release);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

systemmap is supposed to be null terminated. So you must reserve one byte for null and set it to zero.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually as far as I can tell snprintf() always null terminates the output buffer, unless of course the buffer size passed is 0. So this patch looks good to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, I've update the comment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi,this pr has not merged? Is any thing need to deal with? @metan-ucw

@pevik pevik force-pushed the master branch 6 times, most recently from acb468e to dc9ba89 Compare February 7, 2025 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.