Re: [PATCH 2/2] um: Use race-free temporary file creation
On 28/11/2015 23:07, Richard Weinberger wrote: > Am 28.11.2015 um 22:32 schrieb Mickaël Salaün: >> Open the memory mapped file with the O_TMPFILE flag when available. >> >> Signed-off-by: Mickaël Salaün >> --- >> arch/um/os-Linux/mem.c | 12 >> 1 file changed, 12 insertions(+) >> >> diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c >> index 798aeb4..fe52e2d 100644 >> --- a/arch/um/os-Linux/mem.c >> +++ b/arch/um/os-Linux/mem.c >> @@ -106,6 +106,18 @@ static int __init make_tempfile(const char *template) >> } >> } >> >> +#ifdef O_TMPFILE >> +fd = open(tempdir, O_CLOEXEC | O_RDWR | O_EXCL | O_TMPFILE, 0700); >> +/* >> + * If the running system does not support O_TMPFILE flag then retry >> + * without it. >> + */ >> +if (fd != -1 || (errno != EINVAL && errno != EISDIR && > > Why are you handling EISDIR? I follow the man page for open [1], I think it was a workaround needed for some kernel versions just after the O_TMPFILE was added but before the support for EOPNOTSUPP. We may need to add the EACCES too for some version of glibc [2, 3]? 1. http://man7.org/linux/man-pages/man2/openat.2.html#BUGS 2. Commit 69a91c237ab0ebe4e9fdeaf6d0090c85275594ec and https://sourceware.org/bugzilla/show_bug.cgi?id=17523 3. https://bugs.gentoo.org/529044 > >> +errno != EOPNOTSUPP)) >> +return fd; >> +errno = 0; > > Why are you resetting errno? It's to ignore/reset the error code from open, but it may not be needed because of the next call to malloc? Mickaël signature.asc Description: OpenPGP digital signature
Re: [PATCH 2/2] um: Use race-free temporary file creation
+ errno != EOPNOTSUPP)) + return fd; + errno = 0; >>> >>> Why are you resetting errno? >> >> It's to ignore/reset the error code from open, but it may not be needed >> because of the next call to malloc? > > But then you'd have to reset errno after every syscall. :-) OK, I will remove it then :) Mickaël signature.asc Description: OpenPGP digital signature
Re: [PATCH 2/2] um: Use race-free temporary file creation
Am 28.11.2015 um 23:56 schrieb Mickaël Salaün: > > On 28/11/2015 23:07, Richard Weinberger wrote: >> Am 28.11.2015 um 22:32 schrieb Mickaël Salaün: >>> Open the memory mapped file with the O_TMPFILE flag when available. >>> >>> Signed-off-by: Mickaël Salaün >>> --- >>> arch/um/os-Linux/mem.c | 12 >>> 1 file changed, 12 insertions(+) >>> >>> diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c >>> index 798aeb4..fe52e2d 100644 >>> --- a/arch/um/os-Linux/mem.c >>> +++ b/arch/um/os-Linux/mem.c >>> @@ -106,6 +106,18 @@ static int __init make_tempfile(const char *template) >>> } >>> } >>> >>> +#ifdef O_TMPFILE >>> + fd = open(tempdir, O_CLOEXEC | O_RDWR | O_EXCL | O_TMPFILE, 0700); >>> + /* >>> +* If the running system does not support O_TMPFILE flag then retry >>> +* without it. >>> +*/ >>> + if (fd != -1 || (errno != EINVAL && errno != EISDIR && >> >> Why are you handling EISDIR? > > I follow the man page for open [1], I think it was a workaround needed for > some kernel versions just after the O_TMPFILE was added but before the > support for EOPNOTSUPP. > We may need to add the EACCES too for some version of glibc [2, 3]? Makes sense! :) > 1. http://man7.org/linux/man-pages/man2/openat.2.html#BUGS > 2. Commit 69a91c237ab0ebe4e9fdeaf6d0090c85275594ec and > https://sourceware.org/bugzilla/show_bug.cgi?id=17523 > 3. https://bugs.gentoo.org/529044 > >> >>> + errno != EOPNOTSUPP)) >>> + return fd; >>> + errno = 0; >> >> Why are you resetting errno? > > It's to ignore/reset the error code from open, but it may not be needed > because of the next call to malloc? But then you'd have to reset errno after every syscall. :-) Thanks, //richard -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 2/2] um: Use race-free temporary file creation
Open the memory mapped file with the O_TMPFILE flag when available. Signed-off-by: Mickaël Salaün --- arch/um/os-Linux/mem.c | 12 1 file changed, 12 insertions(+) diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c index 798aeb4..fe52e2d 100644 --- a/arch/um/os-Linux/mem.c +++ b/arch/um/os-Linux/mem.c @@ -106,6 +106,18 @@ static int __init make_tempfile(const char *template) } } +#ifdef O_TMPFILE + fd = open(tempdir, O_CLOEXEC | O_RDWR | O_EXCL | O_TMPFILE, 0700); + /* +* If the running system does not support O_TMPFILE flag then retry +* without it. +*/ + if (fd != -1 || (errno != EINVAL && errno != EISDIR && + errno != EOPNOTSUPP)) + return fd; + errno = 0; +#endif + tempname = malloc(strlen(tempdir) + strlen(template) + 1); if (tempname == NULL) return -1; -- 2.6.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 2/2] um: Use race-free temporary file creation
Am 28.11.2015 um 22:32 schrieb Mickaël Salaün: > Open the memory mapped file with the O_TMPFILE flag when available. > > Signed-off-by: Mickaël Salaün > --- > arch/um/os-Linux/mem.c | 12 > 1 file changed, 12 insertions(+) > > diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c > index 798aeb4..fe52e2d 100644 > --- a/arch/um/os-Linux/mem.c > +++ b/arch/um/os-Linux/mem.c > @@ -106,6 +106,18 @@ static int __init make_tempfile(const char *template) > } > } > > +#ifdef O_TMPFILE > + fd = open(tempdir, O_CLOEXEC | O_RDWR | O_EXCL | O_TMPFILE, 0700); > + /* > + * If the running system does not support O_TMPFILE flag then retry > + * without it. > + */ > + if (fd != -1 || (errno != EINVAL && errno != EISDIR && Why are you handling EISDIR? > + errno != EOPNOTSUPP)) > + return fd; > + errno = 0; Why are you resetting errno? Thanks, //richard -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 2/2] um: Use race-free temporary file creation
Open the memory mapped file with the O_TMPFILE flag when available. Signed-off-by: Mickaël Salaün--- arch/um/os-Linux/mem.c | 12 1 file changed, 12 insertions(+) diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c index 798aeb4..fe52e2d 100644 --- a/arch/um/os-Linux/mem.c +++ b/arch/um/os-Linux/mem.c @@ -106,6 +106,18 @@ static int __init make_tempfile(const char *template) } } +#ifdef O_TMPFILE + fd = open(tempdir, O_CLOEXEC | O_RDWR | O_EXCL | O_TMPFILE, 0700); + /* +* If the running system does not support O_TMPFILE flag then retry +* without it. +*/ + if (fd != -1 || (errno != EINVAL && errno != EISDIR && + errno != EOPNOTSUPP)) + return fd; + errno = 0; +#endif + tempname = malloc(strlen(tempdir) + strlen(template) + 1); if (tempname == NULL) return -1; -- 2.6.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 2/2] um: Use race-free temporary file creation
Am 28.11.2015 um 23:56 schrieb Mickaël Salaün: > > On 28/11/2015 23:07, Richard Weinberger wrote: >> Am 28.11.2015 um 22:32 schrieb Mickaël Salaün: >>> Open the memory mapped file with the O_TMPFILE flag when available. >>> >>> Signed-off-by: Mickaël Salaün>>> --- >>> arch/um/os-Linux/mem.c | 12 >>> 1 file changed, 12 insertions(+) >>> >>> diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c >>> index 798aeb4..fe52e2d 100644 >>> --- a/arch/um/os-Linux/mem.c >>> +++ b/arch/um/os-Linux/mem.c >>> @@ -106,6 +106,18 @@ static int __init make_tempfile(const char *template) >>> } >>> } >>> >>> +#ifdef O_TMPFILE >>> + fd = open(tempdir, O_CLOEXEC | O_RDWR | O_EXCL | O_TMPFILE, 0700); >>> + /* >>> +* If the running system does not support O_TMPFILE flag then retry >>> +* without it. >>> +*/ >>> + if (fd != -1 || (errno != EINVAL && errno != EISDIR && >> >> Why are you handling EISDIR? > > I follow the man page for open [1], I think it was a workaround needed for > some kernel versions just after the O_TMPFILE was added but before the > support for EOPNOTSUPP. > We may need to add the EACCES too for some version of glibc [2, 3]? Makes sense! :) > 1. http://man7.org/linux/man-pages/man2/openat.2.html#BUGS > 2. Commit 69a91c237ab0ebe4e9fdeaf6d0090c85275594ec and > https://sourceware.org/bugzilla/show_bug.cgi?id=17523 > 3. https://bugs.gentoo.org/529044 > >> >>> + errno != EOPNOTSUPP)) >>> + return fd; >>> + errno = 0; >> >> Why are you resetting errno? > > It's to ignore/reset the error code from open, but it may not be needed > because of the next call to malloc? But then you'd have to reset errno after every syscall. :-) Thanks, //richard -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 2/2] um: Use race-free temporary file creation
Am 28.11.2015 um 22:32 schrieb Mickaël Salaün: > Open the memory mapped file with the O_TMPFILE flag when available. > > Signed-off-by: Mickaël Salaün> --- > arch/um/os-Linux/mem.c | 12 > 1 file changed, 12 insertions(+) > > diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c > index 798aeb4..fe52e2d 100644 > --- a/arch/um/os-Linux/mem.c > +++ b/arch/um/os-Linux/mem.c > @@ -106,6 +106,18 @@ static int __init make_tempfile(const char *template) > } > } > > +#ifdef O_TMPFILE > + fd = open(tempdir, O_CLOEXEC | O_RDWR | O_EXCL | O_TMPFILE, 0700); > + /* > + * If the running system does not support O_TMPFILE flag then retry > + * without it. > + */ > + if (fd != -1 || (errno != EINVAL && errno != EISDIR && Why are you handling EISDIR? > + errno != EOPNOTSUPP)) > + return fd; > + errno = 0; Why are you resetting errno? Thanks, //richard -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 2/2] um: Use race-free temporary file creation
+ errno != EOPNOTSUPP)) + return fd; + errno = 0; >>> >>> Why are you resetting errno? >> >> It's to ignore/reset the error code from open, but it may not be needed >> because of the next call to malloc? > > But then you'd have to reset errno after every syscall. :-) OK, I will remove it then :) Mickaël signature.asc Description: OpenPGP digital signature
Re: [PATCH 2/2] um: Use race-free temporary file creation
On 28/11/2015 23:07, Richard Weinberger wrote: > Am 28.11.2015 um 22:32 schrieb Mickaël Salaün: >> Open the memory mapped file with the O_TMPFILE flag when available. >> >> Signed-off-by: Mickaël Salaün>> --- >> arch/um/os-Linux/mem.c | 12 >> 1 file changed, 12 insertions(+) >> >> diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c >> index 798aeb4..fe52e2d 100644 >> --- a/arch/um/os-Linux/mem.c >> +++ b/arch/um/os-Linux/mem.c >> @@ -106,6 +106,18 @@ static int __init make_tempfile(const char *template) >> } >> } >> >> +#ifdef O_TMPFILE >> +fd = open(tempdir, O_CLOEXEC | O_RDWR | O_EXCL | O_TMPFILE, 0700); >> +/* >> + * If the running system does not support O_TMPFILE flag then retry >> + * without it. >> + */ >> +if (fd != -1 || (errno != EINVAL && errno != EISDIR && > > Why are you handling EISDIR? I follow the man page for open [1], I think it was a workaround needed for some kernel versions just after the O_TMPFILE was added but before the support for EOPNOTSUPP. We may need to add the EACCES too for some version of glibc [2, 3]? 1. http://man7.org/linux/man-pages/man2/openat.2.html#BUGS 2. Commit 69a91c237ab0ebe4e9fdeaf6d0090c85275594ec and https://sourceware.org/bugzilla/show_bug.cgi?id=17523 3. https://bugs.gentoo.org/529044 > >> +errno != EOPNOTSUPP)) >> +return fd; >> +errno = 0; > > Why are you resetting errno? It's to ignore/reset the error code from open, but it may not be needed because of the next call to malloc? Mickaël signature.asc Description: OpenPGP digital signature