better euidaccess.patch from Paolo Bonzini (#600636#c33)

This commit is contained in:
Jiri Popelka 2014-09-18 14:39:31 +02:00
parent 4c1a1b086d
commit 57cdd87cc5
2 changed files with 49 additions and 5 deletions

View File

@ -12,6 +12,17 @@ diff -up lockdev-scm-2011-10-07/src/lockdev.c.access lockdev-scm-2011-10-07/src/
#include <errno.h>
#include <signal.h>
#include <stdio.h>
@@ -125,6 +125,10 @@
#include "lockdev.h"
#include "ttylock.h"
+#ifndef LOCKDEV_ACCESS
+#define LOCKDEV_ACCESS euidaccess
+#endif
+
#define LOCKDEV_PATH SBINDIR "/lockdev"
/*
@@ -616,7 +620,10 @@ dev_lock (const char *devname)
if ( stat( device, &statbuf) == -1 ) {
close_n_return(-errno);
@ -20,7 +31,7 @@ diff -up lockdev-scm-2011-10-07/src/lockdev.c.access lockdev-scm-2011-10-07/src/
+ /* check that the caller has write permission to the device
+ * to prevent denial-of-service attack by unauthorized users
+ */
+ if ( euidaccess( device, W_OK ) == -1 ) {
+ if ( LOCKDEV_ACCESS( device, W_OK ) == -1 ) {
close_n_return(-errno);
}
@ -32,7 +43,7 @@ diff -up lockdev-scm-2011-10-07/src/lockdev.c.access lockdev-scm-2011-10-07/src/
+ /* check that the caller has write permission to the device
+ * to prevent denial-of-service attack by unauthorized users
+ */
+ if ( euidaccess( device, W_OK ) == -1 ) {
+ if ( LOCKDEV_ACCESS( device, W_OK ) == -1 ) {
close_n_return(-errno);
}
@ -44,7 +55,37 @@ diff -up lockdev-scm-2011-10-07/src/lockdev.c.access lockdev-scm-2011-10-07/src/
+ /* check that the caller has write permission to the device
+ * to prevent denial-of-service attack by unauthorized users
+ */
+ if ( euidaccess( device, W_OK ) == -1 ) {
+ if ( LOCKDEV_ACCESS( device, W_OK ) == -1 ) {
close_n_return(-errno);
}
diff -ru lockdev-save/src/Makefile.am lockdev-scm-2011-10-07/src/Makefile.am
--- lockdev-save/src/Makefile.am 2014-09-18 13:42:00.363741658 +0200
+++ lockdev-scm-2011-10-07/src/Makefile.am 2014-09-18 13:52:10.307868154 +0200
@@ -6,7 +6,6 @@
AM_CPPFLAGS = -include $(top_builddir)/config.h -DSBINDIR=\"$(sbindir)\"
lockdev_SOURCES = sample.c
-lockdev_LDADD = liblockdev.la
baudboy_SOURCES = baudboy_test.c
baudboy_LDADD = liblockdev.la
Solo in lockdev-scm-2011-10-07/src: Makefile.in
diff -ru lockdev-save/src/sample.c lockdev-scm-2011-10-07/src/sample.c
--- lockdev-save/src/sample.c 2014-09-18 13:42:00.363741658 +0200
+++ lockdev-scm-2011-10-07/src/sample.c 2014-09-18 14:06:03.769023380 +0200
@@ -6,6 +6,13 @@
#include <fcntl.h>
#include "lockdev.h"
+/* ttylock functions swap the real/effective uid/gid for us, so
+ * use access instead of euidaccess.
+ */
+#define LOCKDEV_ACCESS access
+#undef TTYLOCK_USE_HELPER
+#include "lockdev.c"
+
void
usage (void)
{
Solo in lockdev-scm-2011-10-07: VERSION

View File

@ -10,7 +10,7 @@
Summary: A library for locking devices
Name: lockdev
Version: 1.0.4
Release: 0.17.%{checkout}%{?dist}
Release: 0.18.%{checkout}%{?dist}
License: LGPLv2
Group: System Environment/Libraries
URL: https://alioth.debian.org/projects/lockdev/
@ -51,7 +51,7 @@ package contains the development headers.
%prep
%setup -q -n lockdev-scm-%{co_date}
# Replace access() calls with euidaccess() (600636#c9)
# Replace access() calls with euidaccess() (600636#c33)
%patch1 -p1 -b .access
%build
@ -105,6 +105,9 @@ fi
%{_includedir}/*
%changelog
* Thu Sep 18 2014 Jiri Popelka <jpopelka@redhat.com> - 1.0.4-0.18.20111007git
- better euidaccess.patch from Paolo Bonzini (#600636#c33)
* Sun Aug 17 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.0.4-0.17.20111007git
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild