Whamcloud - gitweb
LU-17911 obdclass: fix faked flexible arrays in jobid 95/55995/3
authorYang Sheng <ys@whamcloud.com>
Mon, 12 Aug 2024 05:04:55 +0000 (13:04 +0800)
committerOleg Drokin <green@whamcloud.com>
Fri, 23 Aug 2024 21:56:28 +0000 (21:56 +0000)
To fix the crash caused by issue of faked flexible arrays
in  jobid.

Signed-off-by: Yang Sheng <ys@whamcloud.com>
Change-Id: Iba88582e20dfe38ec060ed9a05ba3d65ee3e31e1
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55995
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
lustre/obdclass/jobid.c

index 87b167f..ae1fcdb 100644 (file)
@@ -80,7 +80,7 @@ struct session_jobid {
        struct pid              *sj_session;
        struct rhash_head       sj_linkage;
        struct rcu_head         sj_rcu;
-       char                    sj_jobid[1];
+       char                    sj_jobid[];
 };
 
 static const struct rhashtable_params jobid_params = {
@@ -120,13 +120,13 @@ int jobid_set_current(char *jobid)
        int ret;
        int len = strlen(jobid);
 
-       sj = kmalloc(sizeof(*sj) + len, GFP_KERNEL);
+       sj = kmalloc(sizeof(*sj) + len + 1, GFP_KERNEL);
        if (!sj)
                return -ENOMEM;
        rcu_read_lock();
        sid = task_session(current);
        sj->sj_session = get_pid(sid);
-       strncpy(sj->sj_jobid, jobid, len+1);
+       strncpy(sj->sj_jobid, jobid, len + 1);
        origsj = rhashtable_lookup_get_insert_fast(&session_jobids,
                                                   &sj->sj_linkage,
                                                   jobid_params);