Re: [OE-core] [PATCH] sanity.bbclass: raise_sanity_error if /tmp is noexec

Ross Burton
2024-02-09T15:57:57Z

On 9 Feb 2024, at 14:09, Michal Sieron via lists.openembedded.org <michalwsieron=gmail.com@lists.openembedded.org> wrote:
> + # Ensure /tmp is NOT mounted with noexec
> + with open("/proc/mounts", "r") as f:
> + for line in f:
> + # format is described in fstab(5)
> + _, fs_file, _, fs_mntops, *_ = line.split()
> +
> + # we only want to check /tmp
> + if fs_file != "/tmp":
> + continue
> +
> + # iterate through the options from the end
> + for opt in reversed(fs_mntops.split(",")):
> + if opt == "noexec":
> + raise_sanity_error("/tmp shouldn't be mounted with noexec.", d)
> +

Alternatively, this is neater:

os.statvfs("/tmp").f_flag & os.ST_NOEXEC

Ross