Skip to content

Commit efa8f1b

Browse files
fzago-craygregkh
authored andcommitted
staging: lustre: hsm: stack overrun in hai_dump_data_field
[ Upstream commit 22aadb91c0a0055935109c175f5446abfb130702 ] The function hai_dump_data_field will do a stack buffer overrun when cat'ing /sys/fs/lustre/.../hsm/actions if an action has some data in it. hai_dump_data_field uses snprintf. But there is no check for truncation, and the value returned by snprintf is used as-is. The coordinator code calls hai_dump_data_field with 12 bytes in the buffer. The 6th byte of data is printed incompletely to make room for the terminating NUL. However snprintf still returns 2, so when hai_dump_data_field writes the final NUL, it does it outside the reserved buffer, in the 13th byte of the buffer. This stack buffer overrun hangs my VM. Fix by checking that there is enough room for the next 2 characters plus the NUL terminator. Don't print half bytes. Change the format to 02X instead of .2X, which makes more sense. Signed-off-by: frank zago <fzago@cray.com> Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-8171 Reviewed-on: http://review.whamcloud.com/20338 Reviewed-by: John L. Hammond <john.hammond@intel.com> Reviewed-by: Jean-Baptiste Riaux <riaux.jb@intel.com> Reviewed-by: Oleg Drokin <oleg.drokin@intel.com> Signed-off-by: James Simmons <jsimmons@infradead.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2d1d453 commit efa8f1b

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

drivers/staging/lustre/lustre/include/lustre/lustre_user.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,23 +1063,21 @@ struct hsm_action_item {
10631063
* \retval buffer
10641064
*/
10651065
static inline char *hai_dump_data_field(struct hsm_action_item *hai,
1066-
char *buffer, int len)
1066+
char *buffer, size_t len)
10671067
{
1068-
int i, sz, data_len;
1068+
int i, data_len;
10691069
char *ptr;
10701070

10711071
ptr = buffer;
1072-
sz = len;
10731072
data_len = hai->hai_len - sizeof(*hai);
1074-
for (i = 0 ; (i < data_len) && (sz > 0) ; i++) {
1075-
int cnt;
1076-
1077-
cnt = snprintf(ptr, sz, "%.2X",
1078-
(unsigned char)hai->hai_data[i]);
1079-
ptr += cnt;
1080-
sz -= cnt;
1073+
for (i = 0; (i < data_len) && (len > 2); i++) {
1074+
snprintf(ptr, 3, "%02X", (unsigned char)hai->hai_data[i]);
1075+
ptr += 2;
1076+
len -= 2;
10811077
}
1078+
10821079
*ptr = '\0';
1080+
10831081
return buffer;
10841082
}
10851083

0 commit comments

Comments
 (0)