[lustre-devel] [PATCH 19/42] lustre: ptlrpc: NUL terminate long jobid strings

James Simmons jsimmons at infradead.org
Mon Jan 23 15:00:32 PST 2023


From: Andreas Dilger <adilger at whamcloud.com>

It appears that some jobid names can be sent that are using the full
32-byte size, rather than containing an embedded NUL terminator. This
caused errors in lprocfs_job_stats_log() server side when it overflowed.

If there is no NUL terminator in lustre_msg_get_jobid() then add one
if not found within the buffer, so that the rest of the code doesn't
have to deal with unterminated strings.

This potentially exposes a larger issue that other places may not be
handling the unterminated string properly either, which needs to be
addressed separately on both the client and server.  Terminating the
jobid to 31 chars only on the client does not totally solve the issue,
since there will still be older clients that are not doing this, so
the server needs to handle this in any case.

WC-bug-id: https://jira.whamcloud.com/browse/LU-16376
Lustre-commit: 9eba5d57297f807fd ("LU-16376 obdclass: NUL terminate long jobid strings")
Signed-off-by: Andreas Dilger <adilger at whamcloud.com>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49351
Reviewed-by: Feng Lei <flei at whamcloud.com>
Reviewed-by: James Simmons <jsimmons at infradead.org>
Reviewed-by: Neil Brown <neilb at suse.de>
Reviewed-by: Oleg Drokin <green at whamcloud.com>
Signed-off-by: James Simmons <jsimmons at infradead.org>
---
 fs/lustre/ptlrpc/pack_generic.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/lustre/ptlrpc/pack_generic.c b/fs/lustre/ptlrpc/pack_generic.c
index 9a0341c62702..3499611a0740 100644
--- a/fs/lustre/ptlrpc/pack_generic.c
+++ b/fs/lustre/ptlrpc/pack_generic.c
@@ -1198,6 +1198,12 @@ char *lustre_msg_get_jobid(struct lustre_msg *msg)
 		if (!pb)
 			return NULL;
 
+		/* If clients send unterminated jobids, terminate them here
+		 * so that there is no chance of string overflow later.
+		 */
+		if (unlikely(pb->pb_jobid[LUSTRE_JOBID_SIZE - 1] != '\0'))
+			pb->pb_jobid[LUSTRE_JOBID_SIZE - 1] = '\0';
+
 		return pb->pb_jobid;
 	}
 	default:
-- 
2.27.0



More information about the lustre-devel mailing list