Whamcloud - gitweb
LU-18170 obdclass: replace round_up(*_inllenX*) with ALIGN 54/57354/2
authorEtienne AUJAMES <etienne.aujames@cea.fr>
Tue, 10 Dec 2024 11:11:50 +0000 (12:11 +0100)
committerOleg Drokin <green@whamcloud.com>
Wed, 22 Jan 2025 18:42:55 +0000 (18:42 +0000)
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 <eaujames@ddn.com>
Change-Id: I47e42f581aa76b71c23c7cfec42b9f2589f23f2b
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57354
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/lnet/module.c
lustre/lod/lod_dev.c
lustre/obdclass/class_obd.c
lustre/obdclass/llog_ioctl.c

index 946abc6..d6438ce 100644 (file)
@@ -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);
 }
index 4e7daf2..15e11ec 100644 (file)
@@ -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;
index fe24857..fb79c30 100644 (file)
@@ -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)
index 624059e..6be1372 100644 (file)
@@ -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)