From mboxrd@z Thu Jan 1 00:00:00 1970 From: James Simmons Date: Tue, 11 Aug 2020 08:20:08 -0400 Subject: [lustre-devel] [PATCH 12/23] lustre: sysfs: error-check value stored in jobid_var In-Reply-To: <1597148419-20629-1-git-send-email-jsimmons@infradead.org> References: <1597148419-20629-1-git-send-email-jsimmons@infradead.org> Message-ID: <1597148419-20629-13-git-send-email-jsimmons@infradead.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: lustre-devel@lists.lustre.org From: Mr NeilBrown The jobid_var sysfs attribute only has 3 meaningful values. Other values cause lustre_get_jobid() to return an error which is uniformly ignored. To improve usability and resilience, check that the value written is acceptable before storing it. Reviewed-by: James Simmons Signed-off-by: Mr NeilBrown --- fs/lustre/obdclass/obd_sysfs.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/fs/lustre/obdclass/obd_sysfs.c b/fs/lustre/obdclass/obd_sysfs.c index cb2f0a9..5fc638f 100644 --- a/fs/lustre/obdclass/obd_sysfs.c +++ b/fs/lustre/obdclass/obd_sysfs.c @@ -225,16 +225,26 @@ static ssize_t jobid_var_store(struct kobject *kobj, struct attribute *attr, const char *buffer, size_t count) { + static const char * const valid[] = { + JOBSTATS_DISABLE, + JOBSTATS_PROCNAME_UID, + JOBSTATS_NODELOCAL, + JOBSTATS_SESSION, + NULL + }; + int i; + if (!count || count > JOBSTATS_JOBID_VAR_MAX_LEN) return -EINVAL; - memset(obd_jobid_var, 0, JOBSTATS_JOBID_VAR_MAX_LEN + 1); - - memcpy(obd_jobid_var, buffer, count); + for (i = 0; valid[i]; i++) + if (sysfs_streq(buffer, valid[i])) + break; + if (!valid[i]) + return -EINVAL; - /* Trim the trailing '\n' if any */ - if (obd_jobid_var[count - 1] == '\n') - obd_jobid_var[count - 1] = 0; + memset(obd_jobid_var, 0, JOBSTATS_JOBID_VAR_MAX_LEN + 1); + strcpy(obd_jobid_var, valid[i]); return count; } -- 1.8.3.1