aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux
diff options
context:
space:
mode:
authorMathias Kresin <dev@kresin.me>2018-07-08 23:18:15 +0200
committerJo-Philipp Wich <jo@mein.io>2018-12-18 09:50:54 +0100
commit031d5cf248490b1e5aedac63ac8ac3c49932912f (patch)
treee72bf8fb96d2c41373c6b30c5bb5286b0be12533 /target/linux
parente6945262642a3c83c4f9593286e0c7b794c211f0 (diff)
downloadupstream-031d5cf248490b1e5aedac63ac8ac3c49932912f.tar.gz
upstream-031d5cf248490b1e5aedac63ac8ac3c49932912f.tar.bz2
upstream-031d5cf248490b1e5aedac63ac8ac3c49932912f.zip
kernel: don't auto attach ubi on read error
With a10a204aab26cc ("kernel: make ubi auto-attach check for a tar file magic") the check for the magic was added without considering a failing mtd_read(). If the read fails, no check is done and the mount code is called straight away. Failing with an error message for such cases seems to me the cleaner way, as it would allow to spot hidden/workaround issues. Signed-off-by: Mathias Kresin <dev@kresin.me> (backported from 3716b5e4e6374883c80e61021923733b14cdb011) (rebased patches) Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'target/linux')
-rw-r--r--target/linux/generic/pending-4.14/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch15
-rw-r--r--target/linux/generic/pending-4.9/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch15
2 files changed, 20 insertions, 10 deletions
diff --git a/target/linux/generic/pending-4.14/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch b/target/linux/generic/pending-4.14/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch
index ff3490bf9e..992aa4662e 100644
--- a/target/linux/generic/pending-4.14/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch
+++ b/target/linux/generic/pending-4.14/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch
@@ -8,7 +8,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
-@@ -1172,6 +1172,68 @@ static struct mtd_info * __init open_mtd
+@@ -1172,6 +1172,73 @@ static struct mtd_info * __init open_mtd
return mtd;
}
@@ -44,10 +44,15 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ }
+ }
+
-+ /* check for a valid ubi magic if read from flash was successful */
++ /* check if the read from flash was successful */
+ err = mtd_read(mtd, offset, 4, &len, (void *) magic);
-+ if ((!err || mtd_is_bitflip(err)) &&
-+ len == 4 && strncmp(magic, "UBI#", 4)) {
++ if ((err && !mtd_is_bitflip(err)) || len != 4) {
++ pr_err("UBI error: unable to read from mtd%d\n", mtd->index);
++ goto cleanup;
++ }
++
++ /* check for a valid ubi magic */
++ if (strncmp(magic, "UBI#", 4)) {
+ pr_err("UBI error: no valid UBI magic found inside mtd%d\n", mtd->index);
+ goto cleanup;
+ }
@@ -77,7 +82,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
static int __init ubi_init(void)
{
int err, i, k;
-@@ -1255,6 +1317,12 @@ static int __init ubi_init(void)
+@@ -1255,6 +1322,12 @@ static int __init ubi_init(void)
}
}
diff --git a/target/linux/generic/pending-4.9/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch b/target/linux/generic/pending-4.9/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch
index 8b923d17d6..168cfe50ee 100644
--- a/target/linux/generic/pending-4.9/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch
+++ b/target/linux/generic/pending-4.9/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch
@@ -8,7 +8,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
-@@ -1226,6 +1226,68 @@ static struct mtd_info * __init open_mtd
+@@ -1226,6 +1226,73 @@ static struct mtd_info * __init open_mtd
return mtd;
}
@@ -44,10 +44,15 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ }
+ }
+
-+ /* check for a valid ubi magic if read from flash was successful */
++ /* check if the read from flash was successful */
+ err = mtd_read(mtd, offset, 4, &len, (void *) magic);
-+ if ((!err || mtd_is_bitflip(err)) &&
-+ len == 4 && strncmp(magic, "UBI#", 4)) {
++ if ((err && !mtd_is_bitflip(err)) || len != 4) {
++ pr_err("UBI error: unable to read from mtd%d\n", mtd->index);
++ goto cleanup;
++ }
++
++ /* check for a valid ubi magic */
++ if (strncmp(magic, "UBI#", 4)) {
+ pr_err("UBI error: no valid UBI magic found inside mtd%d\n", mtd->index);
+ goto cleanup;
+ }
@@ -77,7 +82,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
static int __init ubi_init(void)
{
int err, i, k;
-@@ -1309,6 +1371,12 @@ static int __init ubi_init(void)
+@@ -1309,6 +1376,12 @@ static int __init ubi_init(void)
}
}