mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-12 13:55:32 +00:00
kselftest: arm64: Add a null pointer check
[ Upstream commit 80164282b3
]
There is a 'malloc' call, which can be unsuccessful.
This patch will add the malloc failure checking
to avoid possible null dereference and give more information
about test fail reasons.
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Link: https://lore.kernel.org/r/20240423082102.2018886-1-chentao@kylinos.cn
Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
bd230b5236
commit
f322f88a06
1 changed files with 4 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
|
#include "../../kselftest.h"
|
||||||
|
|
||||||
#define SHIFT_TAG(tag) ((uint64_t)(tag) << 56)
|
#define SHIFT_TAG(tag) ((uint64_t)(tag) << 56)
|
||||||
#define SET_TAG(ptr, tag) (((uint64_t)(ptr) & ~SHIFT_TAG(0xff)) | \
|
#define SET_TAG(ptr, tag) (((uint64_t)(ptr) & ~SHIFT_TAG(0xff)) | \
|
||||||
|
@ -21,6 +22,9 @@ int main(void)
|
||||||
if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == 0)
|
if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == 0)
|
||||||
tbi_enabled = 1;
|
tbi_enabled = 1;
|
||||||
ptr = (struct utsname *)malloc(sizeof(*ptr));
|
ptr = (struct utsname *)malloc(sizeof(*ptr));
|
||||||
|
if (!ptr)
|
||||||
|
ksft_exit_fail_msg("Failed to allocate utsname buffer\n");
|
||||||
|
|
||||||
if (tbi_enabled)
|
if (tbi_enabled)
|
||||||
tag = 0x42;
|
tag = 0x42;
|
||||||
ptr = (struct utsname *)SET_TAG(ptr, tag);
|
ptr = (struct utsname *)SET_TAG(ptr, tag);
|
||||||
|
|
Loading…
Reference in a new issue