All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] mmc: sunxi: Prevent against null dereference for vmmc
@ 2016-10-19 13:33 ` Maxime Ripard
  0 siblings, 0 replies; 7+ messages in thread
From: Maxime Ripard @ 2016-10-19 13:33 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: linux-mmc, linux-kernel, Hans de Goede, Chen-Yu Tsai,
	Maxime Ripard, linux-arm-kernel

VMMC is an optional regulator, which means that mmc_regulator_get_supply
will only return an error in case of a deferred probe, but not when the
regulator is not set in the DT.

However, the sunxi driver assumes that VMMC is always there, and doesn't
check the value of the regulator pointer before using it, which obviously
leads to a (close to) null pointer dereference.

Add proper checks to prevent that.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>

---
Changes from v1:
  - remove redundant error message
---
 drivers/mmc/host/sunxi-mmc.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
index c0a5c676d0e8..b1d1303389a7 100644
--- a/drivers/mmc/host/sunxi-mmc.c
+++ b/drivers/mmc/host/sunxi-mmc.c
@@ -822,10 +822,13 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 		break;
 
 	case MMC_POWER_UP:
-		host->ferror = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc,
-						     ios->vdd);
-		if (host->ferror)
-			return;
+		if (!IS_ERR(mmc->supply.vmmc)) {
+			host->ferror = mmc_regulator_set_ocr(mmc,
+							     mmc->supply.vmmc,
+							     ios->vdd);
+			if (host->ferror)
+				return;
+		}
 
 		if (!IS_ERR(mmc->supply.vqmmc)) {
 			host->ferror = regulator_enable(mmc->supply.vqmmc);
@@ -847,7 +850,9 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 	case MMC_POWER_OFF:
 		dev_dbg(mmc_dev(mmc), "power off!\n");
 		sunxi_mmc_reset_host(host);
-		mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
+		if (!IS_ERR(mmc->supply.vmmc))
+			mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
+
 		if (!IS_ERR(mmc->supply.vqmmc) && host->vqmmc_enabled)
 			regulator_disable(mmc->supply.vqmmc);
 		host->vqmmc_enabled = false;
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2] mmc: sunxi: Prevent against null dereference for vmmc
@ 2016-10-19 13:33 ` Maxime Ripard
  0 siblings, 0 replies; 7+ messages in thread
From: Maxime Ripard @ 2016-10-19 13:33 UTC (permalink / raw)
  To: linux-arm-kernel

VMMC is an optional regulator, which means that mmc_regulator_get_supply
will only return an error in case of a deferred probe, but not when the
regulator is not set in the DT.

However, the sunxi driver assumes that VMMC is always there, and doesn't
check the value of the regulator pointer before using it, which obviously
leads to a (close to) null pointer dereference.

Add proper checks to prevent that.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>

---
Changes from v1:
  - remove redundant error message
---
 drivers/mmc/host/sunxi-mmc.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
index c0a5c676d0e8..b1d1303389a7 100644
--- a/drivers/mmc/host/sunxi-mmc.c
+++ b/drivers/mmc/host/sunxi-mmc.c
@@ -822,10 +822,13 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 		break;
 
 	case MMC_POWER_UP:
-		host->ferror = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc,
-						     ios->vdd);
-		if (host->ferror)
-			return;
+		if (!IS_ERR(mmc->supply.vmmc)) {
+			host->ferror = mmc_regulator_set_ocr(mmc,
+							     mmc->supply.vmmc,
+							     ios->vdd);
+			if (host->ferror)
+				return;
+		}
 
 		if (!IS_ERR(mmc->supply.vqmmc)) {
 			host->ferror = regulator_enable(mmc->supply.vqmmc);
@@ -847,7 +850,9 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 	case MMC_POWER_OFF:
 		dev_dbg(mmc_dev(mmc), "power off!\n");
 		sunxi_mmc_reset_host(host);
-		mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
+		if (!IS_ERR(mmc->supply.vmmc))
+			mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
+
 		if (!IS_ERR(mmc->supply.vqmmc) && host->vqmmc_enabled)
 			regulator_disable(mmc->supply.vqmmc);
 		host->vqmmc_enabled = false;
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] mmc: sunxi: Prevent against null dereference for vmmc
  2016-10-19 13:33 ` Maxime Ripard
@ 2016-10-21  2:52   ` Chen-Yu Tsai
  -1 siblings, 0 replies; 7+ messages in thread
From: Chen-Yu Tsai @ 2016-10-21  2:52 UTC (permalink / raw)
  To: Maxime Ripard
  Cc: Ulf Hansson, linux-mmc, linux-kernel, Hans de Goede,
	Chen-Yu Tsai, linux-arm-kernel

On Wed, Oct 19, 2016 at 9:33 PM, Maxime Ripard
<maxime.ripard@free-electrons.com> wrote:
> VMMC is an optional regulator, which means that mmc_regulator_get_supply
> will only return an error in case of a deferred probe, but not when the
> regulator is not set in the DT.
>
> However, the sunxi driver assumes that VMMC is always there, and doesn't
> check the value of the regulator pointer before using it, which obviously
> leads to a (close to) null pointer dereference.
>
> Add proper checks to prevent that.
>
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Acked-by: Chen-Yu Tsai <wens@csie.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] mmc: sunxi: Prevent against null dereference for vmmc
@ 2016-10-21  2:52   ` Chen-Yu Tsai
  0 siblings, 0 replies; 7+ messages in thread
From: Chen-Yu Tsai @ 2016-10-21  2:52 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Oct 19, 2016 at 9:33 PM, Maxime Ripard
<maxime.ripard@free-electrons.com> wrote:
> VMMC is an optional regulator, which means that mmc_regulator_get_supply
> will only return an error in case of a deferred probe, but not when the
> regulator is not set in the DT.
>
> However, the sunxi driver assumes that VMMC is always there, and doesn't
> check the value of the regulator pointer before using it, which obviously
> leads to a (close to) null pointer dereference.
>
> Add proper checks to prevent that.
>
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Acked-by: Chen-Yu Tsai <wens@csie.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] mmc: sunxi: Prevent against null dereference for vmmc
  2016-10-19 13:33 ` Maxime Ripard
  (?)
@ 2016-10-21  8:21   ` Ulf Hansson
  -1 siblings, 0 replies; 7+ messages in thread
From: Ulf Hansson @ 2016-10-21  8:21 UTC (permalink / raw)
  To: Maxime Ripard
  Cc: linux-mmc, linux-kernel, Hans de Goede, Chen-Yu Tsai, linux-arm-kernel

On 19 October 2016 at 15:33, Maxime Ripard
<maxime.ripard@free-electrons.com> wrote:
> VMMC is an optional regulator, which means that mmc_regulator_get_supply
> will only return an error in case of a deferred probe, but not when the
> regulator is not set in the DT.
>
> However, the sunxi driver assumes that VMMC is always there, and doesn't
> check the value of the regulator pointer before using it, which obviously
> leads to a (close to) null pointer dereference.
>
> Add proper checks to prevent that.
>
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Thanks, applied for next!

Kind regards
Uffe

>
> ---
> Changes from v1:
>   - remove redundant error message
> ---
>  drivers/mmc/host/sunxi-mmc.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
> index c0a5c676d0e8..b1d1303389a7 100644
> --- a/drivers/mmc/host/sunxi-mmc.c
> +++ b/drivers/mmc/host/sunxi-mmc.c
> @@ -822,10 +822,13 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
>                 break;
>
>         case MMC_POWER_UP:
> -               host->ferror = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc,
> -                                                    ios->vdd);
> -               if (host->ferror)
> -                       return;
> +               if (!IS_ERR(mmc->supply.vmmc)) {
> +                       host->ferror = mmc_regulator_set_ocr(mmc,
> +                                                            mmc->supply.vmmc,
> +                                                            ios->vdd);
> +                       if (host->ferror)
> +                               return;
> +               }
>
>                 if (!IS_ERR(mmc->supply.vqmmc)) {
>                         host->ferror = regulator_enable(mmc->supply.vqmmc);
> @@ -847,7 +850,9 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
>         case MMC_POWER_OFF:
>                 dev_dbg(mmc_dev(mmc), "power off!\n");
>                 sunxi_mmc_reset_host(host);
> -               mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
> +               if (!IS_ERR(mmc->supply.vmmc))
> +                       mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
> +
>                 if (!IS_ERR(mmc->supply.vqmmc) && host->vqmmc_enabled)
>                         regulator_disable(mmc->supply.vqmmc);
>                 host->vqmmc_enabled = false;
> --
> 2.9.3
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] mmc: sunxi: Prevent against null dereference for vmmc
@ 2016-10-21  8:21   ` Ulf Hansson
  0 siblings, 0 replies; 7+ messages in thread
From: Ulf Hansson @ 2016-10-21  8:21 UTC (permalink / raw)
  To: Maxime Ripard
  Cc: linux-mmc, linux-kernel, Hans de Goede, Chen-Yu Tsai, linux-arm-kernel

On 19 October 2016 at 15:33, Maxime Ripard
<maxime.ripard@free-electrons.com> wrote:
> VMMC is an optional regulator, which means that mmc_regulator_get_supply
> will only return an error in case of a deferred probe, but not when the
> regulator is not set in the DT.
>
> However, the sunxi driver assumes that VMMC is always there, and doesn't
> check the value of the regulator pointer before using it, which obviously
> leads to a (close to) null pointer dereference.
>
> Add proper checks to prevent that.
>
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Thanks, applied for next!

Kind regards
Uffe

>
> ---
> Changes from v1:
>   - remove redundant error message
> ---
>  drivers/mmc/host/sunxi-mmc.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
> index c0a5c676d0e8..b1d1303389a7 100644
> --- a/drivers/mmc/host/sunxi-mmc.c
> +++ b/drivers/mmc/host/sunxi-mmc.c
> @@ -822,10 +822,13 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
>                 break;
>
>         case MMC_POWER_UP:
> -               host->ferror = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc,
> -                                                    ios->vdd);
> -               if (host->ferror)
> -                       return;
> +               if (!IS_ERR(mmc->supply.vmmc)) {
> +                       host->ferror = mmc_regulator_set_ocr(mmc,
> +                                                            mmc->supply.vmmc,
> +                                                            ios->vdd);
> +                       if (host->ferror)
> +                               return;
> +               }
>
>                 if (!IS_ERR(mmc->supply.vqmmc)) {
>                         host->ferror = regulator_enable(mmc->supply.vqmmc);
> @@ -847,7 +850,9 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
>         case MMC_POWER_OFF:
>                 dev_dbg(mmc_dev(mmc), "power off!\n");
>                 sunxi_mmc_reset_host(host);
> -               mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
> +               if (!IS_ERR(mmc->supply.vmmc))
> +                       mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
> +
>                 if (!IS_ERR(mmc->supply.vqmmc) && host->vqmmc_enabled)
>                         regulator_disable(mmc->supply.vqmmc);
>                 host->vqmmc_enabled = false;
> --
> 2.9.3
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] mmc: sunxi: Prevent against null dereference for vmmc
@ 2016-10-21  8:21   ` Ulf Hansson
  0 siblings, 0 replies; 7+ messages in thread
From: Ulf Hansson @ 2016-10-21  8:21 UTC (permalink / raw)
  To: linux-arm-kernel

On 19 October 2016 at 15:33, Maxime Ripard
<maxime.ripard@free-electrons.com> wrote:
> VMMC is an optional regulator, which means that mmc_regulator_get_supply
> will only return an error in case of a deferred probe, but not when the
> regulator is not set in the DT.
>
> However, the sunxi driver assumes that VMMC is always there, and doesn't
> check the value of the regulator pointer before using it, which obviously
> leads to a (close to) null pointer dereference.
>
> Add proper checks to prevent that.
>
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Thanks, applied for next!

Kind regards
Uffe

>
> ---
> Changes from v1:
>   - remove redundant error message
> ---
>  drivers/mmc/host/sunxi-mmc.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
> index c0a5c676d0e8..b1d1303389a7 100644
> --- a/drivers/mmc/host/sunxi-mmc.c
> +++ b/drivers/mmc/host/sunxi-mmc.c
> @@ -822,10 +822,13 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
>                 break;
>
>         case MMC_POWER_UP:
> -               host->ferror = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc,
> -                                                    ios->vdd);
> -               if (host->ferror)
> -                       return;
> +               if (!IS_ERR(mmc->supply.vmmc)) {
> +                       host->ferror = mmc_regulator_set_ocr(mmc,
> +                                                            mmc->supply.vmmc,
> +                                                            ios->vdd);
> +                       if (host->ferror)
> +                               return;
> +               }
>
>                 if (!IS_ERR(mmc->supply.vqmmc)) {
>                         host->ferror = regulator_enable(mmc->supply.vqmmc);
> @@ -847,7 +850,9 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
>         case MMC_POWER_OFF:
>                 dev_dbg(mmc_dev(mmc), "power off!\n");
>                 sunxi_mmc_reset_host(host);
> -               mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
> +               if (!IS_ERR(mmc->supply.vmmc))
> +                       mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
> +
>                 if (!IS_ERR(mmc->supply.vqmmc) && host->vqmmc_enabled)
>                         regulator_disable(mmc->supply.vqmmc);
>                 host->vqmmc_enabled = false;
> --
> 2.9.3
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-10-21  8:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-19 13:33 [PATCH v2] mmc: sunxi: Prevent against null dereference for vmmc Maxime Ripard
2016-10-19 13:33 ` Maxime Ripard
2016-10-21  2:52 ` Chen-Yu Tsai
2016-10-21  2:52   ` Chen-Yu Tsai
2016-10-21  8:21 ` Ulf Hansson
2016-10-21  8:21   ` Ulf Hansson
2016-10-21  8:21   ` Ulf Hansson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.