Whamcloud - gitweb
LU-17000 ptlrpc: fix string overflow warnings 10/52210/4
authorAndreas Dilger <adilger@whamcloud.com>
Thu, 31 Aug 2023 20:50:56 +0000 (14:50 -0600)
committerOleg Drokin <green@whamcloud.com>
Wed, 13 Sep 2023 04:06:56 +0000 (04:06 +0000)
commitff62700fa8ee717a71de13baec25f0d69640ae7c
tree7ccc48f98cf5b724ff913c266464c639292cb78d
parentde1c549814cdf5b9989f29b754cb0f94860b1223
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")

Test-Parameters: trivial testlist=sanity-sec,sanity-selinux
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: Ia810ce9f07b663a90049bb78af21c06f0e3ebbe5
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52210
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Sebastien Buisson <sbuisson@ddn.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/ptlrpc/sec.c
lustre/ptlrpc/sec_lproc.c