librtas/librtas-check-warning-null-pointer.patch
Than Ngo 4699201fa1 - Use new lockdown-compatible ABI when available
- Add plan for CI test
  Resolves: RHEL-101976
2025-11-11 16:51:33 +01:00

64 lines
2.7 KiB
Diff

commit d871069621209a6acc0c2ff6eaaba88c8583d6b1
Author: Tyrel Datwyler <tyreld@linux.ibm.com>
Date: Fri Jun 20 16:46:29 2025 -0700
physical-attestation: check work_area_bytes for null prior to dereference
CI static checker warns of possible NULL pointer dereference.
librtas_src/physical-attestation.c:133:14: warning: Either the condition 'work_area_bytes' is redundant or there is possible null pointer dereference: work_area_bytes. [nullPointerRedundantCheck]
int size = *work_area_bytes;
^
librtas_src/physical-attestation.c:166:7: note: Assuming that condition 'work_area_bytes' is not redundant
if (work_area_bytes)
^
librtas_src/physical-attestation.c:133:14: note: Null pointer dereference
int size = *work_area_bytes;
^
librtas_src/physical-attestation.c:157:36: warning: Either the condition 'work_area_bytes' is redundant or there is possible null pointer dereference: work_area_bytes. [nullPointerRedundantCheck]
ssize_t res = read(fd, workarea, *work_area_bytes);
^
librtas_src/physical-attestation.c:166:7: note: Assuming that condition 'work_area_bytes' is not redundant
if (work_area_bytes)
^
librtas_src/physical-attestation.c:157:36: note: Null pointer dereference
ssize_t res = read(fd, workarea, *work_area_bytes);
Fix by testing work_area_bytes prior to the first pointer dereference.
The later pointer checks are redundant and can be removed as size=0 will
result in RTAS_IO_ASSERT error being returned prior.
Fixes: cac1c292be56a ("librtas: Use kernel interface when available for ibm,physical-attestation")
Signed-off-by: Tyrel Datwyler <tyreld@linux.ibm.com>
diff --git a/librtas_src/physical-attestation.c b/librtas_src/physical-attestation.c
index 48108a0..0d3975c 100644
--- a/librtas_src/physical-attestation.c
+++ b/librtas_src/physical-attestation.c
@@ -130,7 +130,7 @@ static int
phy_attestation_kernel(char *workarea, int seq_num, int *next_seq_num,
int *work_area_bytes)
{
- int size = *work_area_bytes;
+ int size = (work_area_bytes) ? *work_area_bytes : 0;
int fd = (seq_num == 1) ? phy_attest_fd_new(workarea, size)
: (int)seq_num;
@@ -163,14 +163,12 @@ phy_attestation_kernel(char *workarea, int seq_num, int *next_seq_num,
close(fd);
if (next_seq_num)
*next_seq_num = 1;
- if (work_area_bytes)
- *work_area_bytes = res;
+ *work_area_bytes = res;
} else {
rtas_status = 1; /* More data available, call again */
if (next_seq_num)
*next_seq_num = fd;
- if (work_area_bytes)
- *work_area_bytes = res;
+ *work_area_bytes = res;
}
return rtas_status;