[-next,5/5] proc: fix possible null-ptr-deref when parsing param

Message ID 20221023163945.39920-6-yin31149@gmail.com
State New
Headers
Series fs: fix possible null-ptr-deref when parsing param |

Commit Message

Hawkins Jiawei Oct. 23, 2022, 4:39 p.m. UTC
  According to commit "vfs: parse: deal with zero length string value",
kernel will set the param->string to null pointer in vfs_parse_fs_string()
if fs string has zero length.

Yet the problem is that, proc_parse_param() will dereferences the
param->string, without checking whether it is a null pointer, which may
trigger a null-ptr-deref bug.

This patch solves it by adding sanity check on param->string
in proc_parse_param().

Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
---
 fs/proc/root.c | 3 +++
 1 file changed, 3 insertions(+)
  

Patch

diff --git a/fs/proc/root.c b/fs/proc/root.c
index 3c2ee3eb1138..5346809dc3c3 100644
--- a/fs/proc/root.c
+++ b/fs/proc/root.c
@@ -130,6 +130,9 @@  static int proc_parse_param(struct fs_context *fc, struct fs_parameter *param)
 		break;
 
 	case Opt_subset:
+		if (!param->string)
+			return invalfc(fc, "Bad value '%s' for mount option '%s'\n",
+				       param->string, param->key);
 		if (proc_parse_subset_param(fc, param->string) < 0)
 			return -EINVAL;
 		break;