| Summary: | Incorrect label/uuid may be returned for swap partitions | ||
|---|---|---|---|
| Product: | Busybox | Reporter: | Fedor Kozhevnikov <fktpa813> |
| Component: | Other | Assignee: | unassigned |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | busybox-cvs |
| Priority: | P5 | ||
| Version: | 1.16.x | ||
| Target Milestone: | --- | ||
| Hardware: | All | ||
| OS: | Linux | ||
| Host: | Target: | ||
| Build: | |||
| Attachments: | Suggested patch | ||
Well, if image does contain both vfat and swapspace signatures, volume_id_probe_all() inevitably will get confused. Why do you think swapspace signature should get preference? Isn't it admin's error to not clear swapspace before mkswap'ing it? Let's see whether "standard" mkswap clears 1st page: Here is 16 Mb image which was filled with 0a bytes and them "mkswap"ed by util-linux-ng 2.17.2: 00000000 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a |................| * 00000400 01 00 00 00 ff 0f 00 00 00 00 00 00 d8 74 24 f8 |.............t$.| 00000410 41 56 47 d1 b3 59 97 fa e9 64 f6 33 00 00 00 00 |AVG..Y...d.3....| 00000420 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00000ff0 00 00 00 00 00 00 53 57 41 50 53 50 41 43 45 32 |......SWAPSPACE2| 00001000 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a |................| * 01000000 And the same test with busybox: 00000000 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a |................| * 00000400 01 00 00 00 ff 0f 00 00 00 00 00 00 32 43 bd 3d |............2C.=| 00000410 79 d5 49 51 af 45 d2 11 b6 6b dd f2 00 00 00 00 |y.IQ.E...k......| 00000420 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00000600 00 00 00 00 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a |................| 00000610 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a |................| * 00000ff0 0a 0a 0a 0a 0a 0a 53 57 41 50 53 50 41 43 45 32 |......SWAPSPACE2| 00001000 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a |................| * 01000000 That is, 1st page was not erased in both cases. util-linux-ng 2.17.2 claims to erase it when it does not see any partition tables and is not run in whole disk (that is, is it works on /dev/XdYNN, not on /dev/XdY), or with -f flag. We can add -f flag, but then many users will forget to use it... (In reply to comment #1) >Why do you think swapspace signature should get preference? Well, why not? It already gets preference over any other file systems except fat, xfs, and mac... Actually, I suppose whatever you did with the partition the last, should take precedence. It automatically happens when you format drive, for example, as fat - because it overwrites the swap signature. But not when you use mkswap... When you create swap partition with a label (mkswap -L <LBL>), you probably intend to activate it later by label using "swapon LABEL=<LBL>" command. However, currently it doesn't work if this partition was previously formatted as fat/xfs/mac and had a different label. In this case, swapon picks up the old fat label instead of the new swap label, so it complains that there's no such device. The fact that the old file system signature is not wiped out is actually rather confusing - the partition still can be mounted and used as a fat partition, but at the same time the swap can be activated on it and overwrite/damage the data stored on a fat file system. However, this is the different issue (which exists in other Linux distros too) - not the one I was trying to solve. > We can add -f flag, but then many users will forget to use it... I agree - it probably won't be very useful because people will forget about it. Fixed in git: http://git.busybox.net/busybox/commit/?id=4e7dd3c363377aefd6ac60ab4335e773482bcca1 Will be in 1.18.x |
Created attachment 1771 [details] Suggested patch Function volume_id_probe_all() may return incorrect label/uuid for a swap partition if that partition was previously formatted as vfat (and possibly as xfs and mac partition as well - but I tested it with vfat only). This affects all applets using resolve_mount_spec() - blkid, swapon, mount etc. To reproduce the issue, format partition as vfat, give it a label, and then convert it to a swap partition using Busybox' mkswap applet with -L option to assign a different label. Run "blkid" and notice that the old label from vfat partition is displayed, along with the old uuid. This happens because mkswap does not zero out the first 1024 bytes of partition header, leaving information from the previous partition. But volume_id_probe_all() probes for fat, xfs, and mac partition first - before trying swap header - and picks up the wrong label/uuid. The easiest way to fix it is to combine fs1 and fs2 arrays in volume_id.c into a single array (as in the attached patch) making sure the volume_id_probe_linux_swap() is called first. However, that removes the small memory usage optimization from volume_id_probe_all() - possibly you can come up with a better alternative.