1

I wrote a small program in C, that compiles without errors or warnings. Testing the program on other systems worked perfectly. I was a little surprised then to see that I could not execute it on my RPi (v1 model B). I have confirmed that the permissions are set to executable for the user, but even when I try to sudo the binary, I get a permission denied message.

If I copy the binary off of the drive (located at /mnt/usb) to my home drive (located in the default location on the sd card) it runs perfectly without an issue. Could this be something to do with how my fstab is setup?

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that
/dev/sda1       /mnt/usb        ext3    defaults,user     0       3
2

Looks like the issue was in fact with the fstab. A colleague had me run mount which showed that /dev/sda1 had noexec applied to it. Changing the last line to:

/dev/sda1       /mnt/usb        ext3    defaults,user,exec     0       3

and doing a restart fixed my problem.

  • Coming from a sys admin background, I would question the fact that you want to allow exec permissions to ALL of /mnt/usb, since it seems you want to use that drive amongst several systems. Generally this isn't advised from a security standpoint, since it will allow any executable to run from the usb drive, including various malware. It is more secure to explicitly copy the desired file(s) to the RPi, than allow arbitrary execution on a removable drive. Which is why you ran in to the problem in the first place ;) – Peter Feb 18 '15 at 4:55
  • @Peter while this is a removable drive, it's being used as fixed storage. Since I'm experimenting with systems programming, I'm trying to keep most of my projects off the SD card in case I need to reformat the sd card again. I don't want any binary file to be executable, I simply want to be able to run what I've given +x rights. – Jacobm001 Feb 18 '15 at 4:58
  • While from a practicality point of view I fully understand, it is much easier to pop a usb drive in and run your program, I just wanted to say that this set-up does leave an attack vector open. I am (self admittedly) a bit of a security nut. Perhaps something like svn would work for you here. When I used to admin for a university, this is the method I would allow for student written execs. (since universities are huge targets, allowing exec on a usb key is very compromising to overall security). Just a thought :) – Peter Feb 18 '15 at 5:09
  • Is it a risk when it is only a single drive, mounted to a single point in the file system? This isn't setting the default for all usb drives, just this one. Is there a difference between how this is setup and hooking up a hard drive? – Jacobm001 Feb 18 '15 at 5:13
  • It is a risk, since as the fstab you mentioned says, the device it's looking at is /dev/sda1, which is any device that reports as sda1, is mounted at /mnt/usb with exec permissions. This means, I can pull out your usb key, swap it with mine, and reboot. It would respond as /dev/sda1, it will be mounted at /mnt/usb, with full exec permissions, and if my usb key isn't as nice as yours, I'll write my badness to your sd card, and until you reformat it, I've got control. – Peter Feb 18 '15 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.