From 4a7db8f29b7f3e9962b5260b3bd51a4f3685dcbb Mon Sep 17 00:00:00 2001 From: Etienne AUJAMES Date: Tue, 10 Dec 2024 12:11:50 +0100 Subject: [PATCH] LU-18170 obdclass: replace round_up(*_inllenX*) with ALIGN This patch fixes the following Coverity error: 2648 bufs = ioc_data->ioc_inllen4 + 2649 round_up(ioc_data->ioc_inllen1, 8) + CID 451715: Integer handling issues (INTEGER_OVERFLOW) Expression "ioc_data->ioc_inllen2 - 1U", which is equal to 4294967295, where "ioc_data->ioc_inllen2" is known to be equal to 0, underflows the type that receives it, an unsigned integer 32 bits wide. 2650 round_up(ioc_data->ioc_inllen2, 8) + 2651 round_up(ioc_data->ioc_inllen3, 8); ioc_inllenX are unsigned so round_up() macro can underflow if the value is set to 0. #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) So this patch replaces round_up() with ALIGN() to align ioctl buffer sizes to 8 bytes. Fixes: 5ad117fc6f ("LU-18170 obdclass: fix llog_print_cb()") Signed-off-by: Etienne AUJAMES Change-Id: I47e42f581aa76b71c23c7cfec42b9f2589f23f2b Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57354 Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lnet/lnet/module.c | 2 +- lustre/lod/lod_dev.c | 6 +++--- lustre/obdclass/class_obd.c | 6 +++--- lustre/obdclass/llog_ioctl.c | 14 +++++++------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lnet/lnet/module.c b/lnet/lnet/module.c index 946abc6..d6438ce 100644 --- a/lnet/lnet/module.c +++ b/lnet/lnet/module.c @@ -288,7 +288,7 @@ static int lnet_ioctl_data_adjust(struct libcfs_ioctl_data *data) if (data->ioc_inllen2 != 0) data->ioc_inlbuf2 = (&data->ioc_bulk[0] + - round_up(data->ioc_inllen1, 8)); + ALIGN(data->ioc_inllen1, 8)); RETURN(0); } diff --git a/lustre/lod/lod_dev.c b/lustre/lod/lod_dev.c index 4e7daf2..15e11ec 100644 --- a/lustre/lod/lod_dev.c +++ b/lustre/lod/lod_dev.c @@ -2646,9 +2646,9 @@ static int lod_llog_print(const struct lu_env *env, struct lod_device *lod, } bufs = ioc_data->ioc_inllen4 + - round_up(ioc_data->ioc_inllen1, 8) + - round_up(ioc_data->ioc_inllen2, 8) + - round_up(ioc_data->ioc_inllen3, 8); + ALIGN(ioc_data->ioc_inllen1, 8) + + ALIGN(ioc_data->ioc_inllen2, 8) + + ALIGN(ioc_data->ioc_inllen3, 8); ioc_data->ioc_inllen1 = 0; ioc_data->ioc_inllen2 = 0; diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index fe24857..fb79c30 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -283,17 +283,17 @@ int obd_ioctl_getdata(struct obd_ioctl_data **datap, int *len, void __user *arg) if (data->ioc_inllen1) { data->ioc_inlbuf1 = &data->ioc_bulk[0]; - offset += round_up(data->ioc_inllen1, 8); + offset += ALIGN(data->ioc_inllen1, 8); } if (data->ioc_inllen2) { data->ioc_inlbuf2 = &data->ioc_bulk[0] + offset; - offset += round_up(data->ioc_inllen2, 8); + offset += ALIGN(data->ioc_inllen2, 8); } if (data->ioc_inllen3) { data->ioc_inlbuf3 = &data->ioc_bulk[0] + offset; - offset += round_up(data->ioc_inllen3, 8); + offset += ALIGN(data->ioc_inllen3, 8); } if (data->ioc_inllen4) diff --git a/lustre/obdclass/llog_ioctl.c b/lustre/obdclass/llog_ioctl.c index 624059e..6be1372 100644 --- a/lustre/obdclass/llog_ioctl.c +++ b/lustre/obdclass/llog_ioctl.c @@ -106,9 +106,9 @@ static int llog_check_cb(const struct lu_env *env, struct llog_handle *handle, if (ioc_data && ioc_data->ioc_inllen1 > 0) { l = 0; remains = ioc_data->ioc_inllen4 + - round_up(ioc_data->ioc_inllen1, 8) + - round_up(ioc_data->ioc_inllen2, 8) + - round_up(ioc_data->ioc_inllen3, 8); + ALIGN(ioc_data->ioc_inllen1, 8) + + ALIGN(ioc_data->ioc_inllen2, 8) + + ALIGN(ioc_data->ioc_inllen3, 8); rc = kstrtol(ioc_data->ioc_inlbuf2, 0, &from); if (rc) @@ -340,7 +340,7 @@ int llog_ioctl(const struct lu_env *env, struct llog_ctxt *ctxt, case OBD_IOC_LLOG_INFO: { int l; int remains = data->ioc_inllen2 + - round_up(data->ioc_inllen1, 8); + ALIGN(data->ioc_inllen1, 8); char *out = data->ioc_bulk; l = snprintf(out, remains, @@ -383,9 +383,9 @@ int llog_ioctl(const struct lu_env *env, struct llog_ctxt *ctxt, GOTO(out_close, rc = -EINVAL); bufs = data->ioc_inllen4 + - round_up(data->ioc_inllen1, 8) + - round_up(data->ioc_inllen2, 8) + - round_up(data->ioc_inllen3, 8); + ALIGN(data->ioc_inllen1, 8) + + ALIGN(data->ioc_inllen2, 8) + + ALIGN(data->ioc_inllen3, 8); rc = kstrtol(data->ioc_inlbuf2, 0, &lprd.lprd_from); if (rc) -- 1.8.3.1