Skip to contentSkip to conversation

Android build project: Fix 'mkyaffs2image -f ...' selabel_lookup error

PATCH In review Richard Haines 2 participants 3 messages Jul 14, 2012 – Jul 16, 2012 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Android build project: Fix 'mkyaffs2image -f ...' selabel_lookup error

When building SE-Android, mkyaffs2image fails with an selabel_lookup error as the 'mountpoint' parameter does not match the file_context entry (requires a leading '/').

---
 tools/releasetools/build_image.py |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/releasetools/build_image.py +3 -3
index a615d1a..2b42d7d 100755
@@ -126,11 +126,11 @@ def main(argv):
   image_filename = os.path.basename(out_file)
   mount_point = ""
   if image_filename == "system.img":
-    mount_point = "system"
+    mount_point = "/system"
   elif image_filename == "userdata.img":
-    mount_point = "data"
+    mount_point = "/data"
   elif image_filename == "cache.img":
-    mount_point = "cache"
+    mount_point = "/cache"
   else:
     print >> sys.stderr, "error: unknown image file name ", image_filename
     exit(1)
Signature · 8 lines
1.7.10.4



--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#1 lore raw

Thanks for bringing this to our attention. I think we should instead make a change to the yaffs code. This will help with any other wrapper code. Try the attached patch (worked for me).

Quoted 34 lines · Richard Haines

When building SE-Android, mkyaffs2image fails with an selabel_lookup error as the 'mountpoint' parameter does not match the file_context entry (requires a leading '/').

---
 tools/releasetools/build_image.py |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/releasetools/build_image.py +3 -4
index a615d1a..2b42d7d 100755
@@ -126,11 +126,11 @@ def main(argv):
   image_filename = os.path.basename(out_file)
   mount_point = ""
   if image_filename == "system.img":
-    mount_point = "system"
+    mount_point = "/system"
   elif image_filename == "userdata.img":
-    mount_point = "data"
+    mount_point = "/data"
   elif image_filename == "cache.img":
-    mount_point = "cache"
+    mount_point = "/cache"
   else:
     print >> sys.stderr, "error: unknown image file name ", image_filename
     exit(1)
--

1.7.10.4

Quoted 5 lines

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] the words "unsubscribe selinux" without quotes as the message.

yaffs2/utils/mkyaffs2image.c +34 -7
index 2b152e6..a956256 100644
@@ -382,12 +382,25 @@ static int process_directory(int parent, const char *path, int fixstats)
 							mntpoint, suffix);
 						exit(1);
 					}
+
+					char *sepath = NULL;
+					if (dest_name[0] == '/')
+					        sepath = strdup(dest_name);
+					else
+					        asprintf(&sepath, "/%s", dest_name);
+					if (!sepath) {
+					        perror("malloc");
+					        exit(1);
+					}
+
 					if (selabel_lookup(sehnd, &secontext,
-							   dest_name,
+							   sepath,
 							   stats.st_mode) < 0) {
-						perror("selabel_lookup");
-						exit(1);
+					        perror("selabel_lookup");
+					        free(sepath);
+					        exit(1);
 					}
+					free(sepath);
 				}
 #endif
 
@@ -636,10 +649,24 @@ int main(int argc, char *argv[])
 	//printf("Processing directory %s into image file %s\n",dir,image);
 #ifdef HAVE_SELINUX
     if (sehnd) {
-	    if (selabel_lookup(sehnd, &secontext, mntpoint, stats.st_mode) < 0) {
-		    perror("selabel_lookup");
-		    exit(1);
-	    }
+
+        char *sepath = NULL;
+        if (mntpoint[0] == '/')
+	    sepath = strdup(mntpoint);
+        else
+	    asprintf(&sepath, "/%s", mntpoint);
+        if (!sepath) {
+	    perror("malloc");
+	    exit(1);
+	}
+
+	if (selabel_lookup(sehnd, &secontext, sepath, stats.st_mode) < 0) {
+	    perror("selabel_lookup");
+	    free(sepath);
+	    exit(1);
+	}
+
+	free(sepath);
     }
 #endif
 
#2 lore raw

Your yaffs patch worked okay and is the best solution.

Thanks
Richard

--- On Sun, 15/7/12, Robert Craig <[email protected]> wrote:

From: Robert Craig <[email protected]>
Subject: Re: [PATCH 1/1] Android build project: Fix 'mkyaffs2image -f ...' selabel_lookup error
To: "Richard Haines" <[email protected]>
Cc: [email protected]
Date: Sunday, 15 July, 2012, 16:31

Thanks for bringing this to our attention. I think we should instead make a change to the yaffs code. This will help with any other wrapper code. Try the attached patch (worked for me).

On Sat, Jul 14, 2012 at 2:59 PM, Richard Haines <[email protected]> wrote:
When building SE-Android, mkyaffs2image fails with an selabel_lookup error

as the 'mountpoint' parameter does not match the file_context entry

(requires a leading '/').

---

 tools/releasetools/build_image.py |    6 +++---

 1 file changed, 3 insertions(+), 3 deletions(-)
tools/releasetools/build_image.py +0 -0

index a615d1a..2b42d7d 100755

--- a/tools/releasetools/build_image.py

+++ b/tools/releasetools/build_image.py

@@ -126,11 +126,11 @@ def main(argv):

   image_filename = os.path.basename(out_file)

   mount_point = ""

   if image_filename == "system.img":

-    mount_point = "system"

+    mount_point = "/system"

   elif image_filename == "userdata.img":

-    mount_point = "data"

+    mount_point = "/data"

   elif image_filename == "cache.img":

-    mount_point = "cache"

+    mount_point = "/cache"

   else:

     print >> sys.stderr, "error: unknown image file name ", image_filename

     exit(1)

--

1.7.10.4

--

This message was distributed to subscribers of the selinux mailing list.

If you no longer wish to subscribe, send mail to [email protected] with

the words "unsubscribe selinux" without quotes as the message.