Bug 249

Summary: findfs finds the wrong partition
Product: Busybox Reporter: Sam Varshavchik <mrsam>
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: enhancement CC: busybox-cvs
Priority: P5    
Version: 1.13.x   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Host: Target:
Build:
Attachments: Fix

Description Sam Varshavchik 2009-03-31 01:48:11 UTC
A lengthy debugging session with kexec-tools identified what looks like a bug in busybox's internal implementation of findfs.

See the 2-3 comments starting with https://bugzilla.redhat.com/show_bug.cgi?id=476368#c38

I'm looking at the following code in busybox:

char *get_devname_from_label(const char *spec)
{
        struct uuidCache_s *uc;
        int spec_len = strlen(spec);

        uuidcache_init();
        uc = uuidCache;
        while (uc) {
// FIXME: empty label ("LABEL=") matches anything??!
                if (uc->label[0] && strncmp(spec, uc->label, spec_len) == 0) {
                        return xstrdup(uc->device);
                }
                uc = uc->next;
        }
        return NULL;
}


My existing partitions have the following labels, "/", "/home", and "/boot" (I use their mountpoints as labels, which is perfectly kosher).

The command "findfs LABEL=/" in busybox ends up returning the wrong partition to me. It looks to me like that strncmp is the culprit. The loop iterates over another partition first. strncmp("/", "/boot", 1) == 0, so this loop returns the partition that carries the "/boot" label, instead of "/". Chaos ensues...
Comment 1 Denys Vlasenko 2009-03-31 19:46:11 UTC
Created attachment 225 [details]
Fix

Try attached patch
Comment 2 Denys Vlasenko 2009-03-31 19:47:52 UTC
Applied as rev 25912.