clk_register_clkdev: handle callers needing format string
Subsystems (11)
PATCH 1/1 clk_register_clkdev: handle callers needing format string
Many callers either use NULL or const strings for the third argument of clk_register_clkdev. For those that do not, this is a risk for format strings being accidentally processed (for example in device names). This adds the missing "%s" arguments to make sure format strings will not leak into the clkdev.
--- arch/arm/mach-vexpress/spc.c | 2 +- arch/powerpc/platforms/512x/clock-commonclk.c | 4 ++-- drivers/acpi/acpi_apd.c | 3 ++- drivers/acpi/acpi_lpss.c | 2 +- drivers/clk/clk-mb86s7x.c | 2 +- drivers/clk/clk-moxart.c | 4 ++-- drivers/clk/samsung/clk-pll.c | 2 +- drivers/clk/samsung/clk.c | 9 +++++---- drivers/clk/tegra/clk-tegra-pmc.c | 2 +- drivers/clk/tegra/clk.c | 2 +- 10 files changed, 17 insertions(+), 15 deletions(-)
arch/arm/mach-vexpress/spc.c +1 -1
@@ -577,7 +577,7 @@ static int __init ve_spc_clk_init(void)pr_warn ("failed to register cpu%d clock\n" , cpu);continue ; } -if (clk_register_clkdev (clk,NULL ,dev_name (cpu_dev))) { +if (clk_register_clkdev (clk,NULL ,"%s" ,dev_name (cpu_dev))) {pr_warn ("failed to register cpu%d clock lookup\n" , cpu);continue ; }
arch/powerpc/platforms/512x/clock-commonclk.c +2 -2
@@ -992,9 +992,9 @@ static void mpc5121_clk_provide_migration_support(void) clk =of_clk_get_by_name (np, clkname); \if (IS_ERR (clk)) { \ clk = clkitem; \ -clk_register_clkdev (clk, clkname, devname); \ +clk_register_clkdev (clk, clkname,"%s" , devname); \if (regnode) \ -clk_register_clkdev (clk, clkname, np->name); \ +clk_register_clkdev (clk, clkname,"%s" , np->name); \ did_register |= DID_REG_ ## regflag; \pr_debug ("clock alias name '%s' for dev '%s' pointer %p\n" , \ clkname, devname, clk); \
drivers/acpi/acpi_apd.c +2 -1
@@ -65,7 +65,8 @@ static int acpi_apd_setup(struct apd_private_data *pdata)dev_name (&pdata->adev->dev),NULL ,CLK_IS_ROOT , dev_desc->fixed_clk_rate); -clk_register_clkdev (clk,NULL ,dev_name (&pdata->adev->dev)); +clk_register_clkdev (clk,NULL ,"%s" , +dev_name (&pdata->adev->dev)); pdata->clk = clk; }
drivers/acpi/acpi_lpss.c +1 -1
@@ -316,7 +316,7 @@ out:return PTR_ERR (clk); pdata->clk = clk; -clk_register_clkdev (clk, dev_desc->clk_con_id, devname); +clk_register_clkdev (clk, dev_desc->clk_con_id,"%s" , devname);return 0 ; }
drivers/clk/clk-mb86s7x.c +1 -1
@@ -370,7 +370,7 @@ static int mb86s7x_clclk_of_init(void)pr_err ("failed to register cpu%d clock\n" , cpu);continue ; } -if (clk_register_clkdev (clk,NULL ,dev_name (cpu_dev))) { +if (clk_register_clkdev (clk,NULL ,"%s" ,dev_name (cpu_dev))) {pr_err ("failed to register cpu%d clock lookup\n" , cpu);continue ; }
drivers/clk/clk-moxart.c +2 -2
@@ -47,7 +47,7 @@ static void __init moxart_of_pll_clk_init(struct device_node *node)return ; } -clk_register_clkdev (clk,NULL , name); +clk_register_clkdev (clk,NULL ,"%s" , name);of_clk_add_provider (node, of_clk_src_simple_get, clk); } CLK_OF_DECLARE(moxart_pll_clock, "moxa,moxart-pll-clock",
@@ -90,7 +90,7 @@ static void __init moxart_of_apb_clk_init(struct device_node *node)return ; } -clk_register_clkdev (clk,NULL , name); +clk_register_clkdev (clk,NULL ,"%s" , name);of_clk_add_provider (node, of_clk_src_simple_get, clk); } CLK_OF_DECLARE(moxart_apb_clock, "moxa,moxart-apb-clock",
drivers/clk/samsung/clk-pll.c +1 -1
@@ -1296,7 +1296,7 @@ static void __init _samsung_clk_register_pll(struct samsung_clk_provider *ctx,if (!pll_clk->alias)return ; - ret =clk_register_clkdev (clk, pll_clk->alias, pll_clk->dev_name); + ret =clk_register_clkdev (clk, pll_clk->alias,"%s" , pll_clk->dev_name);if (ret)pr_err ("%s: failed to register lookup for %s : %d" , __func__, pll_clk->name, ret);
drivers/clk/samsung/clk.c +5 -4
@@ -123,7 +123,8 @@ void __init samsung_clk_register_alias(struct samsung_clk_provider *ctx,continue ; } - ret =clk_register_clkdev (clk, list->alias, list->dev_name); + ret =clk_register_clkdev (clk, list->alias,"%s" , + list->dev_name);if (ret)pr_err ("%s: failed to register lookup %s\n" , __func__, list->alias);
@@ -203,7 +204,7 @@ void __init samsung_clk_register_mux(struct samsung_clk_provider *ctx,/* register a clock lookup only if a clock alias is specified */ if (list->alias) { - ret =clk_register_clkdev (clk, list->alias, + ret =clk_register_clkdev (clk, list->alias,"%s" , list->dev_name);if (ret) pr_err("%s: failed to register lookup %s\n",
@@ -242,7 +243,7 @@ void __init samsung_clk_register_div(struct samsung_clk_provider *ctx,/* register a clock lookup only if a clock alias is specified */ if (list->alias) { - ret =clk_register_clkdev (clk, list->alias, + ret =clk_register_clkdev (clk, list->alias,"%s" , list->dev_name);if (ret) pr_err("%s: failed to register lookup %s\n",
@@ -271,7 +272,7 @@ void __init samsung_clk_register_gate(struct samsung_clk_provider *ctx,/* register a clock lookup only if a clock alias is specified */ if (list->alias) { - ret =clk_register_clkdev (clk, list->alias, + ret =clk_register_clkdev (clk, list->alias,"%s" , list->dev_name);if (ret) pr_err("%s: failed to register lookup %s\n",
drivers/clk/tegra/clk-tegra-pmc.c +1 -1
@@ -110,7 +110,7 @@ void __init tegra_pmc_clk_init(void __iomem *pmc_base,0 , pmc_base +PMC_CLK_OUT_CNTRL , data->gate_shift, 0, &clk_out_lock); *dt_clk = clk; -clk_register_clkdev (clk, data->dev_name, data->gate_name); +clk_register_clkdev (clk, data->dev_name,"%s" , data->gate_name); }/* blink */
drivers/clk/tegra/clk.c +1 -1
@@ -296,7 +296,7 @@ void __init tegra_register_devclks(struct tegra_devclk *dev_clks, int num)for (i =0 ; i < num; i++, dev_clks++)clk_register_clkdev (clks[dev_clks->dt_id], dev_clks->con_id, - dev_clks->dev_id); +"%s" , dev_clks->dev_id);for (i =0 ; i < clk_num; i++) {if (!IS_ERR_OR_NULL (clks[i]))
Signature · 6 lines
1.9.1 -- Kees Cook Chrome OS Security
Quoted 8 lines · Kees Cook
Many callers either use NULL or const strings for the third argument of
clk_register_clkdev. For those that do not, this is a risk for format strings being accidentally processed (for example in device names). This adds the missing "%s" arguments to make sure format strings will not leak into the clkdev.Signed-off-by Kees Cook <[email protected]>---
[...]
drivers/clk/tegra/clk.c void __init tegra_register_devclks(struct tegra_devclk *dev_clks, int num) · line 299
Quoted 10 lines
drivers/clk/tegra/clk.c +1
-1@@ -296,7 +296,7 @@ void __init tegra_register_devclks(struct tegra_devclk *dev_clks, int num)for (i =0 ; i < num; i++, dev_clks++)clk_register_clkdev (clks[dev_clks->dt_id], dev_clks->con_id, - dev_clks->dev_id); +"%s" , dev_clks->dev_id);
This causes clocks to be registered with a dev_id string of "(null)", which is causing lookups that used to succeed before to fail.
Regards,
Tomeu
Quoted 18 lines · Tomeu Vizoso
Quoted 8 lines · Kees Cook
Many callers either use NULL or const strings for the third argument of
clk_register_clkdev. For those that do not, this is a risk for format strings being accidentally processed (for example in device names). This adds the missing "%s" arguments to make sure format strings will not leak into the clkdev.Signed-off-by Kees Cook <[email protected]>---
[...]
Quoted 6 lines
drivers/clk/tegra/clk.c +0
-0@@ -296,7 +296,7 @@ void __init tegra_register_devclks(struct tegra_devclk *dev_clks, int num)
Quoted 7 lines
drivers/clk/tegra/clk.c void __init tegra_register_devclks(struct tegra_devclk *dev_clks, int num) · line 299
Quoted 4 lines
drivers/clk/tegra/clk.c +1
-1for (i =0 ; i < num; i++, dev_clks++)clk_register_clkdev (clks[dev_clks->dt_id], dev_clks->con_id, - dev_clks->dev_id); +"%s" , dev_clks->dev_id);This causes clocks to be registered with a
dev_idstring of "(null)", which is causing lookups that used to succeed before to fail.
Oh yuck. Yeah, clk_register_clkdev handles a NULL argument differently than other format-string style functions. Using clk_register_clkdev(..., dev_clks->dev_id ? "%s" : NULL, dev_clks->dev_id) seems really ugly to work around this, though. Perhaps the format string capability should be removed?
-Kees
Signature · 2 lines
Kees Cook Chrome OS Security
Quoted 27 lines · Kees Cook
Quoted 18 lines · Tomeu Vizoso
Quoted 8 lines · Kees Cook
Many callers either use NULL or const strings for the third argument of
clk_register_clkdev. For those that do not, this is a risk for format strings being accidentally processed (for example in device names). This adds the missing "%s" arguments to make sure format strings will not leak into the clkdev.Signed-off-by Kees Cook <[email protected]>---
[...]
Quoted 6 lines
drivers/clk/tegra/clk.c +0
-0@@ -296,7 +296,7 @@ void __init tegra_register_devclks(struct tegra_devclk *dev_clks, int num)Quoted 7 lines
drivers/clk/tegra/clk.c void __init tegra_register_devclks(struct tegra_devclk *dev_clks, int num) · line 299
Quoted 4 lines
drivers/clk/tegra/clk.c +1
-1for (i =0 ; i < num; i++, dev_clks++)clk_register_clkdev (clks[dev_clks->dt_id], dev_clks->con_id, - dev_clks->dev_id); +"%s" , dev_clks->dev_id);This causes clocks to be registered with a
dev_idstring of "(null)", which is causing lookups that used to succeed before to fail.
Quoted 5 lines
Oh yuck. Yeah,
clk_register_clkdevhandles a NULL argument differently than other format-string style functions. Usingclk_register_clkdev(..., dev_clks->dev_id ? "%s" : NULL, dev_clks->dev_id)seems really ugly to work around this, though. Perhaps the format string capability should be removed?
Yeah, that sounds good to me. At least, I don't see as that good of an idea to save a few lines of code by making the API so prone to mistakes.
Could this patch be removed from linux-next in the meantime?
Thanks,
Tomeu
Quoted 5 lines
-Kees
--
Kees Cook
Chrome OS Security
Quoted 34 lines · Tomeu Vizoso
Quoted 27 lines · Kees Cook
Quoted 18 lines · Tomeu Vizoso
Quoted 8 lines · Kees Cook
Many callers either use NULL or const strings for the third argument of
clk_register_clkdev. For those that do not, this is a risk for format strings being accidentally processed (for example in device names). This adds the missing "%s" arguments to make sure format strings will not leak into the clkdev.Signed-off-by Kees Cook <[email protected]>---
[...]
Quoted 6 lines
drivers/clk/tegra/clk.c +0
-0@@ -296,7 +296,7 @@ void __init tegra_register_devclks(struct tegra_devclk *dev_clks, int num)Quoted 7 lines
drivers/clk/tegra/clk.c void __init tegra_register_devclks(struct tegra_devclk *dev_clks, int num) · line 299
Quoted 4 lines
drivers/clk/tegra/clk.c +1
-1for (i =0 ; i < num; i++, dev_clks++)clk_register_clkdev (clks[dev_clks->dt_id], dev_clks->con_id, - dev_clks->dev_id); +"%s" , dev_clks->dev_id);This causes clocks to be registered with a
dev_idstring of "(null)", which is causing lookups that used to succeed before to fail.Quoted 5 lines
Oh yuck. Yeah,
clk_register_clkdevhandles a NULL argument differently than other format-string style functions. Usingclk_register_clkdev(..., dev_clks->dev_id ? "%s" : NULL, dev_clks->dev_id)seems really ugly to work around this, though. Perhaps the format string capability should be removed?
Quoted 5 lines
Yeah, that sounds good to me. At least, I don't see as that good of an idea to save a few lines of code by making the API so prone to mistakes.
Could this patch be removed from linux-next in the meantime?
Stephen, Mike,
the Tegra portion of this patch is wrong because it registers some clocks with a dev_id of "(null)", which is really inconvenient when debugging because one cannot tell from the logs if it's NULL or that actual string.
Could this be reverted?
Thanks,
Tomeu
Quoted 9 lines
Thanks,
Tomeu
Quoted 5 lines
-Kees
--
Kees Cook
Chrome OS Security
Quoted 4 lines · Tomeu Vizoso
Quoted 2 lines · Tomeu Vizoso
Could this patch be removed from linux-next in the meantime?
Quoted 8 lines
Stephen, Mike,
the Tegra portion of this patch is wrong because it registers some clocks with a
dev_idof "(null)", which is really inconvenient when debugging because one cannot tell from the logs if it's NULL or that actual string.Could this be reverted?
Was this patch applied somewhere? clkdev is maintained by Russell, so Mike and I didn't apply this patch to begin with.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Quoted 12 lines · Stephen Boyd
Quoted 11 lines · Tomeu Vizoso
Quoted 2 lines · Tomeu Vizoso
Could this patch be removed from linux-next in the meantime?
Stephen, Mike,
the Tegra portion of this patch is wrong because it registers some clocks with a
dev_idof "(null)", which is really inconvenient when debugging because one cannot tell from the logs if it's NULL or that actual string.
Quoted 4 lines
Quoted 1 line
Could this be reverted?
Was this patch applied somewhere? clkdev is maintained by Russell, so Mike and I didn't apply this patch to begin with.
Sorry about that, it came into -next via mmotm.
Regards,
Tomeu
Quoted 3 lines
--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project