input: misc: Validate input pattern count in pattern_s_dbgfs_write

Add a check for number of input patterns detected in string read from
userspace in pattern_s_dbgfs_write() API, to avoid out-of-bounds write
in a local array.

Change-Id: Ic35561ae34f95c67fbd54ae4db4a7174342f45f4
Signed-off-by: Jishnu Prakash <quic_jprakash@quicinc.com>
This commit is contained in:
Jishnu Prakash 2023-11-21 11:42:06 +05:30
commit 7ce6eef9ba

View file

@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
* Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
*/
#include <linux/atomic.h>
@ -3035,6 +3035,11 @@ static ssize_t pattern_s_dbgfs_write(struct file *fp,
goto exit;
}
if (i >= ARRAY_SIZE(tmp)) {
pr_err("too many patterns in input string\n");
rc = -EINVAL;
goto exit;
}
tmp[i++] = val;
}