<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-toradex.git/drivers/mtd/ubi, branch v4.9.111</title>
<subtitle>Linux kernel for Apalis and Colibri modules</subtitle>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/'/>
<entry>
<title>ubi: fastmap: Correctly handle interrupted erasures in EBA</title>
<updated>2018-07-03T09:23:14+00:00</updated>
<author>
<name>Richard Weinberger</name>
<email>richard@nod.at</email>
</author>
<published>2018-05-28T20:04:32+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=df15c6eeab46aac3622821e2659677c3eb4abf9d'/>
<id>df15c6eeab46aac3622821e2659677c3eb4abf9d</id>
<content type='text'>
commit 781932375ffc6411713ee0926ccae8596ed0261c upstream.

Fastmap cannot track the LEB unmap operation, therefore it can
happen that after an interrupted erasure the mapping still looks
good from Fastmap's point of view, while reading from the PEB will
cause an ECC error and confuses the upper layer.

Instead of teaching users of UBI how to deal with that, we read back
the VID header and check for errors. If the PEB is empty or shows ECC
errors we fixup the mapping and schedule the PEB for erasure.

Fixes: dbb7d2a88d2a ("UBI: Add fastmap core")
Cc: &lt;stable@vger.kernel.org&gt;
Reported-by: martin bayern &lt;Martinbayern@outlook.com&gt;
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 781932375ffc6411713ee0926ccae8596ed0261c upstream.

Fastmap cannot track the LEB unmap operation, therefore it can
happen that after an interrupted erasure the mapping still looks
good from Fastmap's point of view, while reading from the PEB will
cause an ECC error and confuses the upper layer.

Instead of teaching users of UBI how to deal with that, we read back
the VID header and check for errors. If the PEB is empty or shows ECC
errors we fixup the mapping and schedule the PEB for erasure.

Fixes: dbb7d2a88d2a ("UBI: Add fastmap core")
Cc: &lt;stable@vger.kernel.org&gt;
Reported-by: martin bayern &lt;Martinbayern@outlook.com&gt;
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>ubi: fastmap: Cancel work upon detach</title>
<updated>2018-07-03T09:23:14+00:00</updated>
<author>
<name>Richard Weinberger</name>
<email>richard@nod.at</email>
</author>
<published>2018-05-16T20:17:03+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=9eb99e738beb405cb69ce0c244e6bb0ee9666588'/>
<id>9eb99e738beb405cb69ce0c244e6bb0ee9666588</id>
<content type='text'>
commit 6e7d80161066c99d12580d1b985cb1408bb58cf1 upstream.

Ben Hutchings pointed out that 29b7a6fa1ec0 ("ubi: fastmap: Don't flush
fastmap work on detach") does not really fix the problem, it just
reduces the risk to hit the race window where fastmap work races against
free()'ing ubi-&gt;volumes[].

The correct approach is making sure that no more fastmap work is in
progress before we free ubi data structures.
So we cancel fastmap work right after the ubi background thread is
stopped.
By setting ubi-&gt;thread_enabled to zero we make sure that no further work
tries to wake the thread.

Fixes: 29b7a6fa1ec0 ("ubi: fastmap: Don't flush fastmap work on detach")
Fixes: 74cdaf24004a ("UBI: Fastmap: Fix memory leaks while closing the WL sub-system")
Cc: stable@vger.kernel.org
Cc: Ben Hutchings &lt;ben.hutchings@codethink.co.uk&gt;
Cc: Martin Townsend &lt;mtownsend1973@gmail.com&gt;

Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 6e7d80161066c99d12580d1b985cb1408bb58cf1 upstream.

Ben Hutchings pointed out that 29b7a6fa1ec0 ("ubi: fastmap: Don't flush
fastmap work on detach") does not really fix the problem, it just
reduces the risk to hit the race window where fastmap work races against
free()'ing ubi-&gt;volumes[].

The correct approach is making sure that no more fastmap work is in
progress before we free ubi data structures.
So we cancel fastmap work right after the ubi background thread is
stopped.
By setting ubi-&gt;thread_enabled to zero we make sure that no further work
tries to wake the thread.

Fixes: 29b7a6fa1ec0 ("ubi: fastmap: Don't flush fastmap work on detach")
Fixes: 74cdaf24004a ("UBI: Fastmap: Fix memory leaks while closing the WL sub-system")
Cc: stable@vger.kernel.org
Cc: Ben Hutchings &lt;ben.hutchings@codethink.co.uk&gt;
Cc: Martin Townsend &lt;mtownsend1973@gmail.com&gt;

Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>ubi: Reject MLC NAND</title>
<updated>2018-04-24T07:34:09+00:00</updated>
<author>
<name>Richard Weinberger</name>
<email>richard@nod.at</email>
</author>
<published>2018-03-03T10:45:54+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=c64c4c81aed52fc84be225ce47863a41eb4f7bb6'/>
<id>c64c4c81aed52fc84be225ce47863a41eb4f7bb6</id>
<content type='text'>
commit b5094b7f135be34630e3ea8a98fa215715d0f29d upstream.

While UBI and UBIFS seem to work at first sight with MLC NAND, you will
most likely lose all your data upon a power-cut or due to read/write
disturb.
In order to protect users from bad surprises, refuse to attach to MLC
NAND.

Cc: stable@vger.kernel.org
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Acked-by: Boris Brezillon &lt;boris.brezillon@bootlin.com&gt;
Acked-by: Artem Bityutskiy &lt;dedekind1@gmail.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit b5094b7f135be34630e3ea8a98fa215715d0f29d upstream.

While UBI and UBIFS seem to work at first sight with MLC NAND, you will
most likely lose all your data upon a power-cut or due to read/write
disturb.
In order to protect users from bad surprises, refuse to attach to MLC
NAND.

Cc: stable@vger.kernel.org
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Acked-by: Boris Brezillon &lt;boris.brezillon@bootlin.com&gt;
Acked-by: Artem Bityutskiy &lt;dedekind1@gmail.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>ubi: Fix error for write access</title>
<updated>2018-04-24T07:34:09+00:00</updated>
<author>
<name>Romain Izard</name>
<email>romain.izard.pro@gmail.com</email>
</author>
<published>2018-01-29T10:18:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=434a1dd2c0e4f6af3fa4ca9cc3e88bbf07b8f41c'/>
<id>434a1dd2c0e4f6af3fa4ca9cc3e88bbf07b8f41c</id>
<content type='text'>
commit 78a8dfbabbece22bee58ac4cb26cab10e7a19c5d upstream.

When opening a device with write access, ubiblock_open returns an error
code. Currently, this error code is -EPERM, but this is not the right
value.

The open function for other block devices returns -EROFS when opening
read-only devices with FMODE_WRITE set. When used with dm-verity, the
veritysetup userspace tool is expecting EROFS, and refuses to use the
ubiblock device.

Use -EROFS for ubiblock as well. As a result, veritysetup accepts the
ubiblock device as valid.

Cc: stable@vger.kernel.org
Fixes: 9d54c8a33eec (UBI: R/O block driver on top of UBI volumes)
Signed-off-by: Romain Izard &lt;romain.izard.pro@gmail.com&gt;
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 78a8dfbabbece22bee58ac4cb26cab10e7a19c5d upstream.

When opening a device with write access, ubiblock_open returns an error
code. Currently, this error code is -EPERM, but this is not the right
value.

The open function for other block devices returns -EROFS when opening
read-only devices with FMODE_WRITE set. When used with dm-verity, the
veritysetup userspace tool is expecting EROFS, and refuses to use the
ubiblock device.

Use -EROFS for ubiblock as well. As a result, veritysetup accepts the
ubiblock device as valid.

Cc: stable@vger.kernel.org
Fixes: 9d54c8a33eec (UBI: R/O block driver on top of UBI volumes)
Signed-off-by: Romain Izard &lt;romain.izard.pro@gmail.com&gt;
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>ubi: fastmap: Don't flush fastmap work on detach</title>
<updated>2018-04-24T07:34:09+00:00</updated>
<author>
<name>Richard Weinberger</name>
<email>richard@nod.at</email>
</author>
<published>2018-01-17T22:15:57+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=00f308c0eea4d2f7bc5bb3b9d0947f2219f53760'/>
<id>00f308c0eea4d2f7bc5bb3b9d0947f2219f53760</id>
<content type='text'>
commit 29b7a6fa1ec07e8480b0d9caf635a4498a438bf4 upstream.

At this point UBI volumes have already been free()'ed and fastmap can no
longer access these data structures.

Reported-by: Martin Townsend &lt;mtownsend1973@gmail.com&gt;
Fixes: 74cdaf24004a ("UBI: Fastmap: Fix memory leaks while closing the WL sub-system")
Cc: stable@vger.kernel.org
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 29b7a6fa1ec07e8480b0d9caf635a4498a438bf4 upstream.

At this point UBI volumes have already been free()'ed and fastmap can no
longer access these data structures.

Reported-by: Martin Townsend &lt;mtownsend1973@gmail.com&gt;
Fixes: 74cdaf24004a ("UBI: Fastmap: Fix memory leaks while closing the WL sub-system")
Cc: stable@vger.kernel.org
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>ubi: fastmap: Fix slab corruption</title>
<updated>2018-04-13T17:47:52+00:00</updated>
<author>
<name>Rabin Vincent</name>
<email>rabinv@axis.com</email>
</author>
<published>2017-04-03T11:44:11+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=0d84e3b5a64ac3405a103e579d8a903fad916798'/>
<id>0d84e3b5a64ac3405a103e579d8a903fad916798</id>
<content type='text'>
[ Upstream commit 8a1435880f452430b41374d27ac4a33e7bd381ea ]

Booting with UBI fastmap and SLUB debugging enabled results in the
following splats.  The problem is that ubi_scan_fastmap() moves the
fastmap blocks from the scan_ai (allocated in scan_fast()) to the ai
allocated in ubi_attach().  This results in two problems:

 - When the scan_ai is freed, aebs which were allocated from its slab
   cache are still in use.

 - When the other ai is being destroyed in destroy_ai(), the
   arguments to kmem_cache_free() call are incorrect since aebs on its
   -&gt;fastmap list were allocated with a slab cache from a differnt ai.

Fix this by making a copy of the aebs in ubi_scan_fastmap() instead of
moving them.

 =============================================================================
 BUG ubi_aeb_slab_cache (Not tainted): Objects remaining in ubi_aeb_slab_cache on __kmem_cache_shutdown()
 -----------------------------------------------------------------------------

 INFO: Slab 0xbfd2da3c objects=17 used=1 fp=0xb33d7748 flags=0x40000080
 CPU: 1 PID: 118 Comm: ubiattach Tainted: G    B           4.9.15 #3
 [&lt;80111910&gt;] (unwind_backtrace) from [&lt;8010d498&gt;] (show_stack+0x18/0x1c)
 [&lt;8010d498&gt;] (show_stack) from [&lt;804a3274&gt;] (dump_stack+0xb4/0xe0)
 [&lt;804a3274&gt;] (dump_stack) from [&lt;8026c47c&gt;] (slab_err+0x78/0x88)
 [&lt;8026c47c&gt;] (slab_err) from [&lt;802735bc&gt;] (__kmem_cache_shutdown+0x180/0x3e0)
 [&lt;802735bc&gt;] (__kmem_cache_shutdown) from [&lt;8024e13c&gt;] (shutdown_cache+0x1c/0x60)
 [&lt;8024e13c&gt;] (shutdown_cache) from [&lt;8024ed64&gt;] (kmem_cache_destroy+0x19c/0x20c)
 [&lt;8024ed64&gt;] (kmem_cache_destroy) from [&lt;8057cc14&gt;] (destroy_ai+0x1dc/0x1e8)
 [&lt;8057cc14&gt;] (destroy_ai) from [&lt;8057f04c&gt;] (ubi_attach+0x3f4/0x450)
 [&lt;8057f04c&gt;] (ubi_attach) from [&lt;8056fe70&gt;] (ubi_attach_mtd_dev+0x60c/0xff8)
 [&lt;8056fe70&gt;] (ubi_attach_mtd_dev) from [&lt;80571d78&gt;] (ctrl_cdev_ioctl+0x110/0x2b8)
 [&lt;80571d78&gt;] (ctrl_cdev_ioctl) from [&lt;8029c77c&gt;] (do_vfs_ioctl+0xac/0xa00)
 [&lt;8029c77c&gt;] (do_vfs_ioctl) from [&lt;8029d10c&gt;] (SyS_ioctl+0x3c/0x64)
 [&lt;8029d10c&gt;] (SyS_ioctl) from [&lt;80108860&gt;] (ret_fast_syscall+0x0/0x1c)
 INFO: Object 0xb33d7e88 @offset=3720
 INFO: Allocated in scan_peb+0x608/0x81c age=72 cpu=1 pid=118
 	kmem_cache_alloc+0x3b0/0x43c
 	scan_peb+0x608/0x81c
 	ubi_attach+0x124/0x450
 	ubi_attach_mtd_dev+0x60c/0xff8
 	ctrl_cdev_ioctl+0x110/0x2b8
 	do_vfs_ioctl+0xac/0xa00
 	SyS_ioctl+0x3c/0x64
 	ret_fast_syscall+0x0/0x1c
 kmem_cache_destroy ubi_aeb_slab_cache: Slab cache still has objects
 CPU: 1 PID: 118 Comm: ubiattach Tainted: G    B           4.9.15 #3
 [&lt;80111910&gt;] (unwind_backtrace) from [&lt;8010d498&gt;] (show_stack+0x18/0x1c)
 [&lt;8010d498&gt;] (show_stack) from [&lt;804a3274&gt;] (dump_stack+0xb4/0xe0)
 [&lt;804a3274&gt;] (dump_stack) from [&lt;8024ed80&gt;] (kmem_cache_destroy+0x1b8/0x20c)
 [&lt;8024ed80&gt;] (kmem_cache_destroy) from [&lt;8057cc14&gt;] (destroy_ai+0x1dc/0x1e8)
 [&lt;8057cc14&gt;] (destroy_ai) from [&lt;8057f04c&gt;] (ubi_attach+0x3f4/0x450)
 [&lt;8057f04c&gt;] (ubi_attach) from [&lt;8056fe70&gt;] (ubi_attach_mtd_dev+0x60c/0xff8)
 [&lt;8056fe70&gt;] (ubi_attach_mtd_dev) from [&lt;80571d78&gt;] (ctrl_cdev_ioctl+0x110/0x2b8)
 [&lt;80571d78&gt;] (ctrl_cdev_ioctl) from [&lt;8029c77c&gt;] (do_vfs_ioctl+0xac/0xa00)
 [&lt;8029c77c&gt;] (do_vfs_ioctl) from [&lt;8029d10c&gt;] (SyS_ioctl+0x3c/0x64)
 [&lt;8029d10c&gt;] (SyS_ioctl) from [&lt;80108860&gt;] (ret_fast_syscall+0x0/0x1c)
 cache_from_obj: Wrong slab cache. ubi_aeb_slab_cache but object is from ubi_aeb_slab_cache
 ------------[ cut here ]------------
 WARNING: CPU: 1 PID: 118 at mm/slab.h:354 kmem_cache_free+0x39c/0x450
 Modules linked in:
 CPU: 1 PID: 118 Comm: ubiattach Tainted: G    B           4.9.15 #3
 [&lt;80111910&gt;] (unwind_backtrace) from [&lt;8010d498&gt;] (show_stack+0x18/0x1c)
 [&lt;8010d498&gt;] (show_stack) from [&lt;804a3274&gt;] (dump_stack+0xb4/0xe0)
 [&lt;804a3274&gt;] (dump_stack) from [&lt;80120e40&gt;] (__warn+0xf4/0x10c)
 [&lt;80120e40&gt;] (__warn) from [&lt;80120f20&gt;] (warn_slowpath_null+0x28/0x30)
 [&lt;80120f20&gt;] (warn_slowpath_null) from [&lt;80271fe0&gt;] (kmem_cache_free+0x39c/0x450)
 [&lt;80271fe0&gt;] (kmem_cache_free) from [&lt;8057cb88&gt;] (destroy_ai+0x150/0x1e8)
 [&lt;8057cb88&gt;] (destroy_ai) from [&lt;8057ef1c&gt;] (ubi_attach+0x2c4/0x450)
 [&lt;8057ef1c&gt;] (ubi_attach) from [&lt;8056fe70&gt;] (ubi_attach_mtd_dev+0x60c/0xff8)
 [&lt;8056fe70&gt;] (ubi_attach_mtd_dev) from [&lt;80571d78&gt;] (ctrl_cdev_ioctl+0x110/0x2b8)
 [&lt;80571d78&gt;] (ctrl_cdev_ioctl) from [&lt;8029c77c&gt;] (do_vfs_ioctl+0xac/0xa00)
 [&lt;8029c77c&gt;] (do_vfs_ioctl) from [&lt;8029d10c&gt;] (SyS_ioctl+0x3c/0x64)
 [&lt;8029d10c&gt;] (SyS_ioctl) from [&lt;80108860&gt;] (ret_fast_syscall+0x0/0x1c)
 ---[ end trace 2bd8396277fd0a0b ]---
 =============================================================================
 BUG ubi_aeb_slab_cache (Tainted: G    B   W      ): page slab pointer corrupt.
 -----------------------------------------------------------------------------

 INFO: Allocated in scan_peb+0x608/0x81c age=104 cpu=1 pid=118
 	kmem_cache_alloc+0x3b0/0x43c
 	scan_peb+0x608/0x81c
 	ubi_attach+0x124/0x450
 	ubi_attach_mtd_dev+0x60c/0xff8
 	ctrl_cdev_ioctl+0x110/0x2b8
 	do_vfs_ioctl+0xac/0xa00
 	SyS_ioctl+0x3c/0x64
 	ret_fast_syscall+0x0/0x1c
 INFO: Slab 0xbfd2da3c objects=17 used=1 fp=0xb33d7748 flags=0x40000081
 INFO: Object 0xb33d7e88 @offset=3720 fp=0xb33d7da0

 Redzone b33d7e80: cc cc cc cc cc cc cc cc                          ........
 Object b33d7e88: 02 00 00 00 01 00 00 00 00 f0 ff 7f ff ff ff ff  ................
 Object b33d7e98: 00 00 00 00 00 00 00 00 bd 16 00 00 00 00 00 00  ................
 Object b33d7ea8: 00 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00  ................
 Redzone b33d7eb8: cc cc cc cc                                      ....
 Padding b33d7f60: 5a 5a 5a 5a 5a 5a 5a 5a                          ZZZZZZZZ
 CPU: 1 PID: 118 Comm: ubiattach Tainted: G    B   W       4.9.15 #3
 [&lt;80111910&gt;] (unwind_backtrace) from [&lt;8010d498&gt;] (show_stack+0x18/0x1c)
 [&lt;8010d498&gt;] (show_stack) from [&lt;804a3274&gt;] (dump_stack+0xb4/0xe0)
 [&lt;804a3274&gt;] (dump_stack) from [&lt;80271770&gt;] (free_debug_processing+0x320/0x3c4)
 [&lt;80271770&gt;] (free_debug_processing) from [&lt;80271ad0&gt;] (__slab_free+0x2bc/0x430)
 [&lt;80271ad0&gt;] (__slab_free) from [&lt;80272024&gt;] (kmem_cache_free+0x3e0/0x450)
 [&lt;80272024&gt;] (kmem_cache_free) from [&lt;8057cb88&gt;] (destroy_ai+0x150/0x1e8)
 [&lt;8057cb88&gt;] (destroy_ai) from [&lt;8057ef1c&gt;] (ubi_attach+0x2c4/0x450)
 [&lt;8057ef1c&gt;] (ubi_attach) from [&lt;8056fe70&gt;] (ubi_attach_mtd_dev+0x60c/0xff8)
 [&lt;8056fe70&gt;] (ubi_attach_mtd_dev) from [&lt;80571d78&gt;] (ctrl_cdev_ioctl+0x110/0x2b8)
 [&lt;80571d78&gt;] (ctrl_cdev_ioctl) from [&lt;8029c77c&gt;] (do_vfs_ioctl+0xac/0xa00)
 [&lt;8029c77c&gt;] (do_vfs_ioctl) from [&lt;8029d10c&gt;] (SyS_ioctl+0x3c/0x64)
 [&lt;8029d10c&gt;] (SyS_ioctl) from [&lt;80108860&gt;] (ret_fast_syscall+0x0/0x1c)
 FIX ubi_aeb_slab_cache: Object at 0xb33d7e88 not freed

Signed-off-by: Rabin Vincent &lt;rabinv@axis.com&gt;
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Sasha Levin &lt;alexander.levin@microsoft.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 8a1435880f452430b41374d27ac4a33e7bd381ea ]

Booting with UBI fastmap and SLUB debugging enabled results in the
following splats.  The problem is that ubi_scan_fastmap() moves the
fastmap blocks from the scan_ai (allocated in scan_fast()) to the ai
allocated in ubi_attach().  This results in two problems:

 - When the scan_ai is freed, aebs which were allocated from its slab
   cache are still in use.

 - When the other ai is being destroyed in destroy_ai(), the
   arguments to kmem_cache_free() call are incorrect since aebs on its
   -&gt;fastmap list were allocated with a slab cache from a differnt ai.

Fix this by making a copy of the aebs in ubi_scan_fastmap() instead of
moving them.

 =============================================================================
 BUG ubi_aeb_slab_cache (Not tainted): Objects remaining in ubi_aeb_slab_cache on __kmem_cache_shutdown()
 -----------------------------------------------------------------------------

 INFO: Slab 0xbfd2da3c objects=17 used=1 fp=0xb33d7748 flags=0x40000080
 CPU: 1 PID: 118 Comm: ubiattach Tainted: G    B           4.9.15 #3
 [&lt;80111910&gt;] (unwind_backtrace) from [&lt;8010d498&gt;] (show_stack+0x18/0x1c)
 [&lt;8010d498&gt;] (show_stack) from [&lt;804a3274&gt;] (dump_stack+0xb4/0xe0)
 [&lt;804a3274&gt;] (dump_stack) from [&lt;8026c47c&gt;] (slab_err+0x78/0x88)
 [&lt;8026c47c&gt;] (slab_err) from [&lt;802735bc&gt;] (__kmem_cache_shutdown+0x180/0x3e0)
 [&lt;802735bc&gt;] (__kmem_cache_shutdown) from [&lt;8024e13c&gt;] (shutdown_cache+0x1c/0x60)
 [&lt;8024e13c&gt;] (shutdown_cache) from [&lt;8024ed64&gt;] (kmem_cache_destroy+0x19c/0x20c)
 [&lt;8024ed64&gt;] (kmem_cache_destroy) from [&lt;8057cc14&gt;] (destroy_ai+0x1dc/0x1e8)
 [&lt;8057cc14&gt;] (destroy_ai) from [&lt;8057f04c&gt;] (ubi_attach+0x3f4/0x450)
 [&lt;8057f04c&gt;] (ubi_attach) from [&lt;8056fe70&gt;] (ubi_attach_mtd_dev+0x60c/0xff8)
 [&lt;8056fe70&gt;] (ubi_attach_mtd_dev) from [&lt;80571d78&gt;] (ctrl_cdev_ioctl+0x110/0x2b8)
 [&lt;80571d78&gt;] (ctrl_cdev_ioctl) from [&lt;8029c77c&gt;] (do_vfs_ioctl+0xac/0xa00)
 [&lt;8029c77c&gt;] (do_vfs_ioctl) from [&lt;8029d10c&gt;] (SyS_ioctl+0x3c/0x64)
 [&lt;8029d10c&gt;] (SyS_ioctl) from [&lt;80108860&gt;] (ret_fast_syscall+0x0/0x1c)
 INFO: Object 0xb33d7e88 @offset=3720
 INFO: Allocated in scan_peb+0x608/0x81c age=72 cpu=1 pid=118
 	kmem_cache_alloc+0x3b0/0x43c
 	scan_peb+0x608/0x81c
 	ubi_attach+0x124/0x450
 	ubi_attach_mtd_dev+0x60c/0xff8
 	ctrl_cdev_ioctl+0x110/0x2b8
 	do_vfs_ioctl+0xac/0xa00
 	SyS_ioctl+0x3c/0x64
 	ret_fast_syscall+0x0/0x1c
 kmem_cache_destroy ubi_aeb_slab_cache: Slab cache still has objects
 CPU: 1 PID: 118 Comm: ubiattach Tainted: G    B           4.9.15 #3
 [&lt;80111910&gt;] (unwind_backtrace) from [&lt;8010d498&gt;] (show_stack+0x18/0x1c)
 [&lt;8010d498&gt;] (show_stack) from [&lt;804a3274&gt;] (dump_stack+0xb4/0xe0)
 [&lt;804a3274&gt;] (dump_stack) from [&lt;8024ed80&gt;] (kmem_cache_destroy+0x1b8/0x20c)
 [&lt;8024ed80&gt;] (kmem_cache_destroy) from [&lt;8057cc14&gt;] (destroy_ai+0x1dc/0x1e8)
 [&lt;8057cc14&gt;] (destroy_ai) from [&lt;8057f04c&gt;] (ubi_attach+0x3f4/0x450)
 [&lt;8057f04c&gt;] (ubi_attach) from [&lt;8056fe70&gt;] (ubi_attach_mtd_dev+0x60c/0xff8)
 [&lt;8056fe70&gt;] (ubi_attach_mtd_dev) from [&lt;80571d78&gt;] (ctrl_cdev_ioctl+0x110/0x2b8)
 [&lt;80571d78&gt;] (ctrl_cdev_ioctl) from [&lt;8029c77c&gt;] (do_vfs_ioctl+0xac/0xa00)
 [&lt;8029c77c&gt;] (do_vfs_ioctl) from [&lt;8029d10c&gt;] (SyS_ioctl+0x3c/0x64)
 [&lt;8029d10c&gt;] (SyS_ioctl) from [&lt;80108860&gt;] (ret_fast_syscall+0x0/0x1c)
 cache_from_obj: Wrong slab cache. ubi_aeb_slab_cache but object is from ubi_aeb_slab_cache
 ------------[ cut here ]------------
 WARNING: CPU: 1 PID: 118 at mm/slab.h:354 kmem_cache_free+0x39c/0x450
 Modules linked in:
 CPU: 1 PID: 118 Comm: ubiattach Tainted: G    B           4.9.15 #3
 [&lt;80111910&gt;] (unwind_backtrace) from [&lt;8010d498&gt;] (show_stack+0x18/0x1c)
 [&lt;8010d498&gt;] (show_stack) from [&lt;804a3274&gt;] (dump_stack+0xb4/0xe0)
 [&lt;804a3274&gt;] (dump_stack) from [&lt;80120e40&gt;] (__warn+0xf4/0x10c)
 [&lt;80120e40&gt;] (__warn) from [&lt;80120f20&gt;] (warn_slowpath_null+0x28/0x30)
 [&lt;80120f20&gt;] (warn_slowpath_null) from [&lt;80271fe0&gt;] (kmem_cache_free+0x39c/0x450)
 [&lt;80271fe0&gt;] (kmem_cache_free) from [&lt;8057cb88&gt;] (destroy_ai+0x150/0x1e8)
 [&lt;8057cb88&gt;] (destroy_ai) from [&lt;8057ef1c&gt;] (ubi_attach+0x2c4/0x450)
 [&lt;8057ef1c&gt;] (ubi_attach) from [&lt;8056fe70&gt;] (ubi_attach_mtd_dev+0x60c/0xff8)
 [&lt;8056fe70&gt;] (ubi_attach_mtd_dev) from [&lt;80571d78&gt;] (ctrl_cdev_ioctl+0x110/0x2b8)
 [&lt;80571d78&gt;] (ctrl_cdev_ioctl) from [&lt;8029c77c&gt;] (do_vfs_ioctl+0xac/0xa00)
 [&lt;8029c77c&gt;] (do_vfs_ioctl) from [&lt;8029d10c&gt;] (SyS_ioctl+0x3c/0x64)
 [&lt;8029d10c&gt;] (SyS_ioctl) from [&lt;80108860&gt;] (ret_fast_syscall+0x0/0x1c)
 ---[ end trace 2bd8396277fd0a0b ]---
 =============================================================================
 BUG ubi_aeb_slab_cache (Tainted: G    B   W      ): page slab pointer corrupt.
 -----------------------------------------------------------------------------

 INFO: Allocated in scan_peb+0x608/0x81c age=104 cpu=1 pid=118
 	kmem_cache_alloc+0x3b0/0x43c
 	scan_peb+0x608/0x81c
 	ubi_attach+0x124/0x450
 	ubi_attach_mtd_dev+0x60c/0xff8
 	ctrl_cdev_ioctl+0x110/0x2b8
 	do_vfs_ioctl+0xac/0xa00
 	SyS_ioctl+0x3c/0x64
 	ret_fast_syscall+0x0/0x1c
 INFO: Slab 0xbfd2da3c objects=17 used=1 fp=0xb33d7748 flags=0x40000081
 INFO: Object 0xb33d7e88 @offset=3720 fp=0xb33d7da0

 Redzone b33d7e80: cc cc cc cc cc cc cc cc                          ........
 Object b33d7e88: 02 00 00 00 01 00 00 00 00 f0 ff 7f ff ff ff ff  ................
 Object b33d7e98: 00 00 00 00 00 00 00 00 bd 16 00 00 00 00 00 00  ................
 Object b33d7ea8: 00 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00  ................
 Redzone b33d7eb8: cc cc cc cc                                      ....
 Padding b33d7f60: 5a 5a 5a 5a 5a 5a 5a 5a                          ZZZZZZZZ
 CPU: 1 PID: 118 Comm: ubiattach Tainted: G    B   W       4.9.15 #3
 [&lt;80111910&gt;] (unwind_backtrace) from [&lt;8010d498&gt;] (show_stack+0x18/0x1c)
 [&lt;8010d498&gt;] (show_stack) from [&lt;804a3274&gt;] (dump_stack+0xb4/0xe0)
 [&lt;804a3274&gt;] (dump_stack) from [&lt;80271770&gt;] (free_debug_processing+0x320/0x3c4)
 [&lt;80271770&gt;] (free_debug_processing) from [&lt;80271ad0&gt;] (__slab_free+0x2bc/0x430)
 [&lt;80271ad0&gt;] (__slab_free) from [&lt;80272024&gt;] (kmem_cache_free+0x3e0/0x450)
 [&lt;80272024&gt;] (kmem_cache_free) from [&lt;8057cb88&gt;] (destroy_ai+0x150/0x1e8)
 [&lt;8057cb88&gt;] (destroy_ai) from [&lt;8057ef1c&gt;] (ubi_attach+0x2c4/0x450)
 [&lt;8057ef1c&gt;] (ubi_attach) from [&lt;8056fe70&gt;] (ubi_attach_mtd_dev+0x60c/0xff8)
 [&lt;8056fe70&gt;] (ubi_attach_mtd_dev) from [&lt;80571d78&gt;] (ctrl_cdev_ioctl+0x110/0x2b8)
 [&lt;80571d78&gt;] (ctrl_cdev_ioctl) from [&lt;8029c77c&gt;] (do_vfs_ioctl+0xac/0xa00)
 [&lt;8029c77c&gt;] (do_vfs_ioctl) from [&lt;8029d10c&gt;] (SyS_ioctl+0x3c/0x64)
 [&lt;8029d10c&gt;] (SyS_ioctl) from [&lt;80108860&gt;] (ret_fast_syscall+0x0/0x1c)
 FIX ubi_aeb_slab_cache: Object at 0xb33d7e88 not freed

Signed-off-by: Rabin Vincent &lt;rabinv@axis.com&gt;
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Sasha Levin &lt;alexander.levin@microsoft.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>ubi: Fix race condition between ubi volume creation and udev</title>
<updated>2018-03-18T10:18:54+00:00</updated>
<author>
<name>Clay McClure</name>
<email>clay@daemons.net</email>
</author>
<published>2017-09-22T02:01:34+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=cde0b3af90c7edc198956a45a66e5fc92bd04b6c'/>
<id>cde0b3af90c7edc198956a45a66e5fc92bd04b6c</id>
<content type='text'>
commit a51a0c8d213594bc094cb8e54aad0cb6d7f7b9a6 upstream.

Similar to commit 714fb87e8bc0 ("ubi: Fix race condition between ubi
device creation and udev"), we should make the volume active before
registering it.

Signed-off-by: Clay McClure &lt;clay@daemons.net&gt;
Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit a51a0c8d213594bc094cb8e54aad0cb6d7f7b9a6 upstream.

Similar to commit 714fb87e8bc0 ("ubi: Fix race condition between ubi
device creation and udev"), we should make the volume active before
registering it.

Signed-off-by: Clay McClure &lt;clay@daemons.net&gt;
Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>ubi: block: Fix locking for idr_alloc/idr_remove</title>
<updated>2018-02-17T12:21:14+00:00</updated>
<author>
<name>Bradley Bolen</name>
<email>bradleybolen@gmail.com</email>
</author>
<published>2018-01-18T13:55:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=de14d0c124ca496381872a42cd32a53433ed28b2'/>
<id>de14d0c124ca496381872a42cd32a53433ed28b2</id>
<content type='text'>
commit 7f29ae9f977bcdc3654e68bc36d170223c52fd48 upstream.

This fixes a race with idr_alloc where gd-&gt;first_minor can be set to the
same value for two simultaneous calls to ubiblock_create.  Each instance
calls device_add_disk with the same first_minor.  device_add_disk calls
bdi_register_owner which generates several warnings.

WARNING: CPU: 1 PID: 179 at kernel-source/fs/sysfs/dir.c:31
sysfs_warn_dup+0x68/0x88
sysfs: cannot create duplicate filename '/devices/virtual/bdi/252:2'

WARNING: CPU: 1 PID: 179 at kernel-source/lib/kobject.c:240
kobject_add_internal+0x1ec/0x2f8
kobject_add_internal failed for 252:2 with -EEXIST, don't try to
register things with the same name in the same directory

WARNING: CPU: 1 PID: 179 at kernel-source/fs/sysfs/dir.c:31
sysfs_warn_dup+0x68/0x88
sysfs: cannot create duplicate filename '/dev/block/252:2'

However, device_add_disk does not error out when bdi_register_owner
returns an error.  Control continues until reaching blk_register_queue.
It then BUGs.

kernel BUG at kernel-source/fs/sysfs/group.c:113!
[&lt;c01e26cc&gt;] (internal_create_group) from [&lt;c01e2950&gt;]
(sysfs_create_group+0x20/0x24)
[&lt;c01e2950&gt;] (sysfs_create_group) from [&lt;c00e3d38&gt;]
(blk_trace_init_sysfs+0x18/0x20)
[&lt;c00e3d38&gt;] (blk_trace_init_sysfs) from [&lt;c02bdfbc&gt;]
(blk_register_queue+0xd8/0x154)
[&lt;c02bdfbc&gt;] (blk_register_queue) from [&lt;c02cec84&gt;]
(device_add_disk+0x194/0x44c)
[&lt;c02cec84&gt;] (device_add_disk) from [&lt;c0436ec8&gt;]
(ubiblock_create+0x284/0x2e0)
[&lt;c0436ec8&gt;] (ubiblock_create) from [&lt;c0427bb8&gt;]
(vol_cdev_ioctl+0x450/0x554)
[&lt;c0427bb8&gt;] (vol_cdev_ioctl) from [&lt;c0189110&gt;] (vfs_ioctl+0x30/0x44)
[&lt;c0189110&gt;] (vfs_ioctl) from [&lt;c01892e0&gt;] (do_vfs_ioctl+0xa0/0x790)
[&lt;c01892e0&gt;] (do_vfs_ioctl) from [&lt;c0189a14&gt;] (SyS_ioctl+0x44/0x68)
[&lt;c0189a14&gt;] (SyS_ioctl) from [&lt;c0010640&gt;] (ret_fast_syscall+0x0/0x34)

Locking idr_alloc/idr_remove removes the race and keeps gd-&gt;first_minor
unique.

Fixes: 2bf50d42f3a4 ("UBI: block: Dynamically allocate minor numbers")
Signed-off-by: Bradley Bolen &lt;bradleybolen@gmail.com&gt;
Reviewed-by: Boris Brezillon &lt;boris.brezillon@free-electrons.com&gt;
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 7f29ae9f977bcdc3654e68bc36d170223c52fd48 upstream.

This fixes a race with idr_alloc where gd-&gt;first_minor can be set to the
same value for two simultaneous calls to ubiblock_create.  Each instance
calls device_add_disk with the same first_minor.  device_add_disk calls
bdi_register_owner which generates several warnings.

WARNING: CPU: 1 PID: 179 at kernel-source/fs/sysfs/dir.c:31
sysfs_warn_dup+0x68/0x88
sysfs: cannot create duplicate filename '/devices/virtual/bdi/252:2'

WARNING: CPU: 1 PID: 179 at kernel-source/lib/kobject.c:240
kobject_add_internal+0x1ec/0x2f8
kobject_add_internal failed for 252:2 with -EEXIST, don't try to
register things with the same name in the same directory

WARNING: CPU: 1 PID: 179 at kernel-source/fs/sysfs/dir.c:31
sysfs_warn_dup+0x68/0x88
sysfs: cannot create duplicate filename '/dev/block/252:2'

However, device_add_disk does not error out when bdi_register_owner
returns an error.  Control continues until reaching blk_register_queue.
It then BUGs.

kernel BUG at kernel-source/fs/sysfs/group.c:113!
[&lt;c01e26cc&gt;] (internal_create_group) from [&lt;c01e2950&gt;]
(sysfs_create_group+0x20/0x24)
[&lt;c01e2950&gt;] (sysfs_create_group) from [&lt;c00e3d38&gt;]
(blk_trace_init_sysfs+0x18/0x20)
[&lt;c00e3d38&gt;] (blk_trace_init_sysfs) from [&lt;c02bdfbc&gt;]
(blk_register_queue+0xd8/0x154)
[&lt;c02bdfbc&gt;] (blk_register_queue) from [&lt;c02cec84&gt;]
(device_add_disk+0x194/0x44c)
[&lt;c02cec84&gt;] (device_add_disk) from [&lt;c0436ec8&gt;]
(ubiblock_create+0x284/0x2e0)
[&lt;c0436ec8&gt;] (ubiblock_create) from [&lt;c0427bb8&gt;]
(vol_cdev_ioctl+0x450/0x554)
[&lt;c0427bb8&gt;] (vol_cdev_ioctl) from [&lt;c0189110&gt;] (vfs_ioctl+0x30/0x44)
[&lt;c0189110&gt;] (vfs_ioctl) from [&lt;c01892e0&gt;] (do_vfs_ioctl+0xa0/0x790)
[&lt;c01892e0&gt;] (do_vfs_ioctl) from [&lt;c0189a14&gt;] (SyS_ioctl+0x44/0x68)
[&lt;c0189a14&gt;] (SyS_ioctl) from [&lt;c0010640&gt;] (ret_fast_syscall+0x0/0x34)

Locking idr_alloc/idr_remove removes the race and keeps gd-&gt;first_minor
unique.

Fixes: 2bf50d42f3a4 ("UBI: block: Dynamically allocate minor numbers")
Signed-off-by: Bradley Bolen &lt;bradleybolen@gmail.com&gt;
Reviewed-by: Boris Brezillon &lt;boris.brezillon@free-electrons.com&gt;
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>ubi: fastmap: Erase outdated anchor PEBs during attach</title>
<updated>2018-02-17T12:21:14+00:00</updated>
<author>
<name>Sascha Hauer</name>
<email>s.hauer@pengutronix.de</email>
</author>
<published>2017-12-05T15:01:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=84f9d8536c8bf440d84093eb749290d88f7e1d76'/>
<id>84f9d8536c8bf440d84093eb749290d88f7e1d76</id>
<content type='text'>
commit f78e5623f45bab2b726eec29dc5cefbbab2d0b1c upstream.

The fastmap update code might erase the current fastmap anchor PEB
in case it doesn't find any new free PEB. When a power cut happens
in this situation we must not have any outdated fastmap anchor PEB
on the device, because that would be used to attach during next
boot.
The easiest way to make that sure is to erase all outdated fastmap
anchor PEBs synchronously during attach.

Signed-off-by: Sascha Hauer &lt;s.hauer@pengutronix.de&gt;
Reviewed-by: Richard Weinberger &lt;richard@nod.at&gt;
Fixes: dbb7d2a88d2a ("UBI: Add fastmap core")
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit f78e5623f45bab2b726eec29dc5cefbbab2d0b1c upstream.

The fastmap update code might erase the current fastmap anchor PEB
in case it doesn't find any new free PEB. When a power cut happens
in this situation we must not have any outdated fastmap anchor PEB
on the device, because that would be used to attach during next
boot.
The easiest way to make that sure is to erase all outdated fastmap
anchor PEBs synchronously during attach.

Signed-off-by: Sascha Hauer &lt;s.hauer@pengutronix.de&gt;
Reviewed-by: Richard Weinberger &lt;richard@nod.at&gt;
Fixes: dbb7d2a88d2a ("UBI: Add fastmap core")
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>ubi/upd: Always flush after prepared for an update</title>
<updated>2017-04-27T07:10:38+00:00</updated>
<author>
<name>Sebastian Siewior</name>
<email>bigeasy@linutronix.de</email>
</author>
<published>2017-02-22T16:15:21+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=790b2b5a01cea4ee4284d52ea995e2af06f4f8d7'/>
<id>790b2b5a01cea4ee4284d52ea995e2af06f4f8d7</id>
<content type='text'>
commit 9cd9a21ce070be8a918ffd3381468315a7a76ba6 upstream.

In commit 6afaf8a484cb ("UBI: flush wl before clearing update marker") I
managed to trigger and fix a similar bug. Now here is another version of
which I assumed it wouldn't matter back then but it turns out UBI has a
check for it and will error out like this:

|ubi0 warning: validate_vid_hdr: inconsistent used_ebs
|ubi0 error: validate_vid_hdr: inconsistent VID header at PEB 592

All you need to trigger this is? "ubiupdatevol /dev/ubi0_0 file" + a
powercut in the middle of the operation.
ubi_start_update() sets the update-marker and puts all EBs on the erase
list. After that userland can proceed to write new data while the old EB
aren't erased completely. A powercut at this point is usually not that
much of a tragedy. UBI won't give read access to the static volume
because it has the update marker. It will most likely set the corrupted
flag because it misses some EBs.
So we are all good. Unless the size of the image that has been written
differs from the old image in the magnitude of at least one EB. In that
case UBI will find two different values for `used_ebs' and refuse to
attach the image with the error message mentioned above.

So in order not to get in the situation, the patch will ensure that we
wait until everything is removed before it tries to write any data.
The alternative would be to detect such a case and remove all EBs at the
attached time after we processed the volume-table and see the
update-marker set. The patch looks bigger and I doubt it is worth it
since usually the write() will wait from time to time for a new EB since
usually there not that many spare EB that can be used.

Signed-off-by: Sebastian Andrzej Siewior &lt;bigeasy@linutronix.de&gt;
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 9cd9a21ce070be8a918ffd3381468315a7a76ba6 upstream.

In commit 6afaf8a484cb ("UBI: flush wl before clearing update marker") I
managed to trigger and fix a similar bug. Now here is another version of
which I assumed it wouldn't matter back then but it turns out UBI has a
check for it and will error out like this:

|ubi0 warning: validate_vid_hdr: inconsistent used_ebs
|ubi0 error: validate_vid_hdr: inconsistent VID header at PEB 592

All you need to trigger this is? "ubiupdatevol /dev/ubi0_0 file" + a
powercut in the middle of the operation.
ubi_start_update() sets the update-marker and puts all EBs on the erase
list. After that userland can proceed to write new data while the old EB
aren't erased completely. A powercut at this point is usually not that
much of a tragedy. UBI won't give read access to the static volume
because it has the update marker. It will most likely set the corrupted
flag because it misses some EBs.
So we are all good. Unless the size of the image that has been written
differs from the old image in the magnitude of at least one EB. In that
case UBI will find two different values for `used_ebs' and refuse to
attach the image with the error message mentioned above.

So in order not to get in the situation, the patch will ensure that we
wait until everything is removed before it tries to write any data.
The alternative would be to detect such a case and remove all EBs at the
attached time after we processed the volume-table and see the
update-marker set. The patch looks bigger and I doubt it is worth it
since usually the write() will wait from time to time for a new EB since
usually there not that many spare EB that can be used.

Signed-off-by: Sebastian Andrzej Siewior &lt;bigeasy@linutronix.de&gt;
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
</feed>
