hugetlbfs: fix null-ptr-deref in hugetlbfs_parse_param()
Subsystems (2)
Sasha Levin
maintainerPATCH 2/5 drm/fsl-dcu: Fix return type of fsl_dcu_drm_connector_mode_valid()
In reply to Sasha LevinFrom: Nathan Chancellor <[email protected]>
[ Upstream commit 96d845a67b7e406cfed7880a724c8ca6121e022e ]
With clang's kernel control flow integrity (kCFI, CONFIG_CFI_CLANG), indirect call targets are validated against the expected function pointer prototype to make sure the call target is valid to help mitigate ROP attacks. If they are not identical, there is a failure at run time, which manifests as either a kernel panic or thread getting killed. A proposed warning in clang aims to catch these at compile time, which reveals:
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c:74:16: error: incompatible function pointer types initializing 'enum drm_mode_status (*)(struct drm_connector *, struct drm_display_mode *)' with an expression of type 'int (struct drm_connector *, struct drm_display_mode *)' [-Werror,-Wincompatible-function-pointer-types-strict]
.mode_valid = fsl_dcu_drm_connector_mode_valid,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
->mode_valid() in 'struct drm_connector_helper_funcs' expects a return type of 'enum drm_mode_status', not 'int'. Adjust the return type of fsl_dcu_drm_connector_mode_valid() to match the prototype's to resolve the warning and CFI failure.
--- drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c +3 -2
@@ -70,8 +70,9 @@ static int fsl_dcu_drm_connector_get_modes(struct drm_connector *connector)return drm_panel_get_modes (fsl_connector->panel); } -static int fsl_dcu_drm_connector_mode_valid (struct drm_connector *connector, -struct drm_display_mode *mode) +static enum drm_mode_status +fsl_dcu_drm_connector_mode_valid (struct drm_connector *connector, +struct drm_display_mode *mode) {if (mode->hdisplay &0xf )return MODE_ERROR ;
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 1/5 hugetlbfs: fix null-ptr-deref in hugetlbfs_parse_param()
From: Hawkins Jiawei <[email protected]>
[ Upstream commit 26215b7ee923b9251f7bb12c4e5f09dc465d35f2 ]
Syzkaller reports a null-ptr-deref bug as follows:
======================================================
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] RIP: 0010:hugetlbfs_parse_param+0x1dd/0x8e0 fs/hugetlbfs/inode.c:1380 [...] Call Trace: <TASK> vfs_parse_fs_param fs/fs_context.c:148 [inline] vfs_parse_fs_param+0x1f9/0x3c0 fs/fs_context.c:129 vfs_parse_fs_string+0xdb/0x170 fs/fs_context.c:191 generic_parse_monolithic+0x16f/0x1f0 fs/fs_context.c:231 do_new_mount fs/namespace.c:3036 [inline] path_mount+0x12de/0x1e20 fs/namespace.c:3370 do_mount fs/namespace.c:3383 [inline] __do_sys_mount fs/namespace.c:3591 [inline] __se_sys_mount fs/namespace.c:3568 [inline] __x64_sys_mount+0x27f/0x300 fs/namespace.c:3568 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd [...] </TASK> ======================================================
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, hugetlbfs_parse_param() will dereference the param->string, without checking whether it is a null pointer. To be more specific, if hugetlbfs_parse_param() parses an illegal mount parameter, such as "size=,", kernel will constructs struct fs_parameter with null pointer in vfs_parse_fs_string(), then passes this struct fs_parameter to hugetlbfs_parse_param(), which triggers the above null-ptr-deref bug.
This patch solves it by adding sanity check on param->string in hugetlbfs_parse_param().
--- fs/hugetlbfs/inode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/hugetlbfs/inode.c +3 -3
@@ -1232,7 +1232,7 @@ static int hugetlbfs_parse_param(struct fs_context *fc, struct fs_parameter *parcase Opt_size:/* memparse() will accept a K/M/G without a digit */ -if (!isdigit (param->string[0 ])) +if (!param->string || !isdigit (param->string[0 ])) goto bad_val; ctx->max_size_opt =memparse (param->string, &rest); ctx->max_val_type =SIZE_STD ;
@@ -1242,7 +1242,7 @@ static int hugetlbfs_parse_param(struct fs_context *fc, struct fs_parameter *parcase Opt_nr_inodes:/* memparse() will accept a K/M/G without a digit */ -if (!isdigit (param->string[0 ])) +if (!param->string || !isdigit (param->string[0 ])) goto bad_val; ctx->nr_inodes =memparse (param->string, &rest);return 0 ;
@@ -1258,7 +1258,7 @@ static int hugetlbfs_parse_param(struct fs_context *fc, struct fs_parameter *parcase Opt_min_size:/* memparse() will accept a K/M/G without a digit */ -if (!isdigit (param->string[0 ])) +if (!param->string || !isdigit (param->string[0 ])) goto bad_val; ctx->min_size_opt =memparse (param->string, &rest); ctx->min_val_type =SIZE_STD ;
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 3/5 drm/sti: Fix return type of sti_{dvo,hda,hdmi}_connector_mode_valid()
From: Nathan Chancellor <[email protected]>
[ Upstream commit 0ad811cc08a937d875cbad0149c1bab17f84ba05 ]
With clang's kernel control flow integrity (kCFI, CONFIG_CFI_CLANG), indirect call targets are validated against the expected function pointer prototype to make sure the call target is valid to help mitigate ROP attacks. If they are not identical, there is a failure at run time, which manifests as either a kernel panic or thread getting killed. A proposed warning in clang aims to catch these at compile time, which reveals:
drivers/gpu/drm/sti/sti_hda.c:637:16: error: incompatible function pointer types initializing 'enum drm_mode_status (*)(struct drm_connector *, struct drm_display_mode *)' with an expression of type 'int (struct drm_connector *, struct drm_display_mode *)' [-Werror,-Wincompatible-function-pointer-types-strict]
.mode_valid = sti_hda_connector_mode_valid,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/sti/sti_dvo.c:376:16: error: incompatible function pointer types initializing 'enum drm_mode_status (*)(struct drm_connector *, struct drm_display_mode *)' with an expression of type 'int (struct drm_connector *, struct drm_display_mode *)' [-Werror,-Wincompatible-function-pointer-types-strict]
.mode_valid = sti_dvo_connector_mode_valid,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/sti/sti_hdmi.c:1035:16: error: incompatible function pointer types initializing 'enum drm_mode_status (*)(struct drm_connector *, struct drm_display_mode *)' with an expression of type 'int (struct drm_connector *, struct drm_display_mode *)' [-Werror,-Wincompatible-function-pointer-types-strict]
.mode_valid = sti_hdmi_connector_mode_valid,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
->mode_valid() in 'struct drm_connector_helper_funcs' expects a return type of 'enum drm_mode_status', not 'int'. Adjust the return type of sti_{dvo,hda,hdmi}_connector_mode_valid() to match the prototype's to resolve the warning and CFI failure.
--- drivers/gpu/drm/sti/sti_dvo.c | 5 +++-- drivers/gpu/drm/sti/sti_hda.c | 5 +++-- drivers/gpu/drm/sti/sti_hdmi.c | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-)
drivers/gpu/drm/sti/sti_dvo.c +3 -2
@@ -345,8 +345,9 @@ static int sti_dvo_connector_get_modes(struct drm_connector *connector)#define CLK_TOLERANCE_HZ 50 -static int sti_dvo_connector_mode_valid (struct drm_connector *connector, -struct drm_display_mode *mode) +static enum drm_mode_status +sti_dvo_connector_mode_valid (struct drm_connector *connector, +struct drm_display_mode *mode) {int target = mode->clock *1000 ;int target_min = target -CLK_TOLERANCE_HZ ;
drivers/gpu/drm/sti/sti_hda.c +3 -2
@@ -600,8 +600,9 @@ static int sti_hda_connector_get_modes(struct drm_connector *connector)#define CLK_TOLERANCE_HZ 50 -static int sti_hda_connector_mode_valid (struct drm_connector *connector, -struct drm_display_mode *mode) +static enum drm_mode_status +sti_hda_connector_mode_valid (struct drm_connector *connector, +struct drm_display_mode *mode) {int target = mode->clock *1000 ;int target_min = target -CLK_TOLERANCE_HZ ;
drivers/gpu/drm/sti/sti_hdmi.c +3 -2
@@ -996,8 +996,9 @@ static int sti_hdmi_connector_get_modes(struct drm_connector *connector)#define CLK_TOLERANCE_HZ 50 -static int sti_hdmi_connector_mode_valid (struct drm_connector *connector, -struct drm_display_mode *mode) +static enum drm_mode_status +sti_hdmi_connector_mode_valid (struct drm_connector *connector, +struct drm_display_mode *mode) {int target = mode->clock *1000 ;int target_min = target -CLK_TOLERANCE_HZ ;
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 4/5 orangefs: Fix kmemleak in orangefs_prepare_debugfs_help_string()
In reply to Sasha LevinFrom: Zhang Xiaoxu <[email protected]>
[ Upstream commit d23417a5bf3a3afc55de5442eb46e1e60458b0a1 ]
When insert and remove the orangefs module, then debug_help_string will be leaked:
unreferenced object 0xffff8881652ba000 (size 4096):
comm "insmod", pid 1701, jiffies 4294893639 (age 13218.530s)
hex dump (first 32 bytes):
43 6c 69 65 6e 74 20 44 65 62 75 67 20 4b 65 79 Client Debug Key
77 6f 72 64 73 20 61 72 65 20 75 6e 6b 6e 6f 77 words are unknow
backtrace:
[<0000000004e6f8e3>] kmalloc_trace+0x27/0xa0
[<0000000006f75d85>] orangefs_prepare_debugfs_help_string+0x5e/0x480 [orangefs]
[<0000000091270a2a>] _sub_I_65535_1+0x57/0xf70 [crc_itu_t]
[<000000004b1ee1a3>] do_one_initcall+0x87/0x2a0
[<000000001d0614ae>] do_init_module+0xdf/0x320
[<00000000efef068c>] load_module+0x2f98/0x3330
[<000000006533b44d>] __do_sys_finit_module+0x113/0x1b0
[<00000000a0da6f99>] do_syscall_64+0x35/0x80
[<000000007790b19b>] entry_SYSCALL_64_after_hwframe+0x46/0xb0When remove the module, should always free debug_help_string. Should always free the allocated buffer when change the free_debug_help_string.
--- fs/orangefs/orangefs-debugfs.c | 3 +++ 1 file changed, 3 insertions(+)
fs/orangefs/orangefs-debugfs.c +3 -0
@@ -222,6 +222,8 @@ static void orangefs_kernel_debug_init(void)void orangefs_debugfs_cleanup (void ) {debugfs_remove_recursive (debug_dir); +kfree (debug_help_string); + debug_help_string =NULL ; }/* open ORANGEFS_KMOD_DEBUG_HELP_FILE */
@@ -671,6 +673,7 @@ int orangefs_prepare_debugfs_help_string(int at_boot)memset (debug_help_string,0 ,DEBUG_HELP_STRING_SIZE );strlcat (debug_help_string, new, string_size);mutex_unlock (&orangefs_help_file_lock); +kfree (new); } rc =0 ;
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 5/5 orangefs: Fix kmemleak in orangefs_{kernel,client}_debug_init()
In reply to Sasha LevinFrom: Zhang Xiaoxu <[email protected]>
[ Upstream commit 31720a2b109b3080eb77e97b8f6f50a27b4ae599 ]
When insert and remove the orangefs module, there are memory leaked as below:
unreferenced object 0xffff88816b0cc000 (size 2048):
comm "insmod", pid 783, jiffies 4294813439 (age 65.512s) hex dump (first 32 bytes):
6e 6f 6e 65 0a 00 00 00 00 00 00 00 00 00 00 00 none............
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace:
[<0000000031ab7788>] kmalloc_trace+0x27/0xa0
[<000000005b405fee>] orangefs_debugfs_init.cold+0xaf/0x17f
[<00000000e5a0085b>] 0xffffffffa02780f9
[<000000004232d9f7>] do_one_initcall+0x87/0x2a0
[<0000000054f22384>] do_init_module+0xdf/0x320
[<000000003263bdea>] load_module+0x2f98/0x3330
[<0000000052cd4153>] __do_sys_finit_module+0x113/0x1b0
[<00000000250ae02b>] do_syscall_64+0x35/0x80
[<00000000f11c03c7>] entry_SYSCALL_64_after_hwframe+0x46/0xb0Use the golbal variable as the buffer rather than dynamic allocate to slove the problem.
--- fs/orangefs/orangefs-debugfs.c | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-)
fs/orangefs/orangefs-debugfs.c +3 -23
@@ -194,15 +194,10 @@ void orangefs_debugfs_init(int debug_mask)*/ static void orangefs_kernel_debug_init (void ) { -int rc = -ENOMEM ; -char *k_buffer =NULL ; +static char k_buffer[ORANGEFS_MAX_DEBUG_STRING_LEN ] = { };gossip_debug (GOSSIP_DEBUGFS_DEBUG ,"%s: start\n" , __func__); - k_buffer =kzalloc (ORANGEFS_MAX_DEBUG_STRING_LEN ,GFP_KERNEL ); -if (!k_buffer) - goto out; -if (strlen (kernel_debug_string) +1 <ORANGEFS_MAX_DEBUG_STRING_LEN ) {strcpy (k_buffer, kernel_debug_string);strcat (k_buffer,"\n" );
@@ -213,9 +208,6 @@ static void orangefs_kernel_debug_init(void)debugfs_create_file (ORANGEFS_KMOD_DEBUG_FILE ,0444 , debug_dir, k_buffer, &kernel_debug_fops); - -out: -gossip_debug (GOSSIP_DEBUGFS_DEBUG ,"%s: rc:%d:\n" , __func__, rc); }
@@ -299,18 +291,13 @@ static int help_show(struct seq_file *m, void *v)/* * initialize the client-debug file. */ -static int orangefs_client_debug_init (void ) +static void orangefs_client_debug_init (void ) { -int rc = -ENOMEM ; -char *c_buffer =NULL ; +static char c_buffer[ORANGEFS_MAX_DEBUG_STRING_LEN ] = { };gossip_debug (GOSSIP_DEBUGFS_DEBUG ,"%s: start\n" , __func__); - c_buffer =kzalloc (ORANGEFS_MAX_DEBUG_STRING_LEN ,GFP_KERNEL ); -if (!c_buffer) - goto out; -if (strlen (client_debug_string) +1 <ORANGEFS_MAX_DEBUG_STRING_LEN ) {strcpy (c_buffer, client_debug_string);strcat (c_buffer,"\n" );
@@ -324,13 +311,6 @@ static int orangefs_client_debug_init(void) debug_dir, c_buffer, &kernel_debug_fops); - - rc =0 ; - -out: - -gossip_debug (GOSSIP_DEBUGFS_DEBUG ,"%s: rc:%d:\n" , __func__, rc); -return rc; }/* open ORANGEFS_KMOD_DEBUG_FILE or ORANGEFS_CLIENT_DEBUG_FILE.*/
Signature · 1 line
2.35.1