Whamcloud - gitweb
LU-17000 ptlrpc: fix string overflow warnings
authorAndreas Dilger <adilger@whamcloud.com>
Thu, 31 Aug 2023 20:50:56 +0000 (14:50 -0600)
committerAndreas Dilger <adilger@whamcloud.com>
Thu, 30 May 2024 00:39:57 +0000 (00:39 +0000)
commit251e627b764d0223e66fcedf040c93c7dce8921c
treea1e57caab762de1ca2055bc30ba690369922a34b
parent250cf16133917320c3268bfa622dd87d11fe38ac
LU-17000 ptlrpc: fix string overflow warnings

Fix potential string overflow warnings in sptlrpc_flavor2name()
calling strncat() with the full size of the target buffer
instead of the *remaining* space in the target buffer.

Fix potential string overflow warning in sepol_seq_write_old()
and sepol_seq_write() potentially copying an unterminated string
from userspace via strncpy() and not terminating it afterward.

Since the maximum incoming parameter size is known in advance,
is reasonably small (~342 bytes), and is only used temporarily,
reorganize the code to avoid two buffer allocations and copies.
Use memcpy() to copy the string since its length is known, and
always add a NUL terminator to the string afterward.

Improvements to error messages and code style in these functions.

Addresses-Coverity: 199034 ("Out-of-bounds access")
Addresses-Coverity: 199063 ("Out-of-bounds access")
Addresses-Coverity: 199108 ("Out-of-bounds access")
Addresses-Coverity: 397374 ("String not null terminated")
Addresses-Coverity: 397394 ("String not null terminated")

Lustre-change: https://review.whamcloud.com/52210
Lustre-commit: ff62700fa8ee717a71de13baec25f0d69640ae7c

Test-Parameters: trivial testlist=sanity-sec,sanity-selinux
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: Ia810ce9f07b663a90049bb78af21c06f0e3ebbe5
Reviewed-by: Sebastien Buisson <sbuisson@ddn.com>
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/55210
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/ptlrpc/sec.c
lustre/ptlrpc/sec_lproc.c