[dovecot-cvs] dovecot/src/lib-index mail-index-lock.c, 1.34, 1.35 mail-index-private.h, 1.31, 1.32 mail-index-view-private.h, 1.10, 1.11 mail-index-view-sync.c, 1.22, 1.23 mail-index-view.c, 1.24, 1.25 mail-index.c, 1.153, 1.154

cras at dovecot.org cras at dovecot.org
Sun Oct 17 19:42:23 EEST 2004


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv15683

Modified Files:
	mail-index-lock.c mail-index-private.h 
	mail-index-view-private.h mail-index-view-sync.c 
	mail-index-view.c mail-index.c 
Log Message:
Removed mmap() memory area protections. They weren't always set correctly.
Also grsec crashed with them anyway.



Index: mail-index-lock.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-lock.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- mail-index-lock.c	10 Oct 2004 22:58:00 -0000	1.34
+++ mail-index-lock.c	17 Oct 2004 16:42:20 -0000	1.35
@@ -107,32 +107,6 @@
 	i_unreached();
 }
 
-int mail_index_map_lock_mprotect(struct mail_index *index,
-				 struct mail_index_map *map, int lock_type)
-{
-	int prot;
-
-	if (!MAIL_INDEX_MAP_IS_IN_MEMORY(map)) {
-		i_assert(map->mmap_size != 0);
-		prot = lock_type == F_UNLCK ? PROT_NONE :
-			lock_type == F_WRLCK ? (PROT_READ|PROT_WRITE) :
-			PROT_READ;
-		if (mprotect(map->mmap_base, map->mmap_size, prot) < 0) {
-			mail_index_set_syscall_error(index, "mprotect()");
-			return -1;
-		}
-	}
-	return 0;
-}
-
-static int mail_index_lock_mprotect(struct mail_index *index, int lock_type)
-{
-	if (index->map == NULL)
-		return 0;
-
-	return mail_index_map_lock_mprotect(index, index->map, lock_type);
-}
-
 static int mail_index_lock(struct mail_index *index, int lock_type,
 			   unsigned int timeout_secs, int update_index,
 			   unsigned int *lock_id_r)
@@ -160,8 +134,6 @@
 		if (ret > 0 && ret2 == 0) {
 			i_assert(lock_type == F_RDLCK);
 			i_assert(index->lock_type == F_RDLCK);
-			if (mail_index_lock_mprotect(index, lock_type) < 0)
-				return -1;
 			return 1;
 		}
 		ret = 0;
@@ -180,8 +152,6 @@
 			if (mail_index_refresh(index) < 0)
 				return -1;
 		}
-		if (mail_index_lock_mprotect(index, lock_type) < 0)
-			return -1;
 
 		index->shared_lock_count++;
 		index->lock_type = F_RDLCK;
@@ -228,8 +198,6 @@
 		*lock_id_r = index->lock_id + 1;
 	}
 
-	if (mail_index_lock_mprotect(index, lock_type) < 0)
-		return -1;
 	return 1;
 }
 
@@ -261,14 +229,6 @@
 	if (fd == -1)
 		return -1;
 
-	if (index->lock_type == F_UNLCK) {
-		if (mail_index_lock_mprotect(index, F_RDLCK) < 0) {
-			(void)close(fd);
-			(void)unlink(path);
-			return -1;
-		}
-	}
-
 	if (index->map->hdr->base_header_size >= sizeof(*index->map->hdr)) {
 		/* header size is what's expected */
 		ret = write_full(fd, index->map->hdr,
@@ -301,8 +261,6 @@
 		index->copy_lock_path = i_strdup(path);
 	}
 
-	if (index->lock_type == F_UNLCK)
-		(void)mail_index_lock_mprotect(index, F_UNLCK);
 	return fd;
 }
 
@@ -344,7 +302,6 @@
 		return -1;
 	}
 
-	(void)mail_index_lock_mprotect(index, F_WRLCK);
 	return 0;
 }
 
@@ -424,7 +381,6 @@
 		}
 		i_assert(index->lock_type == F_WRLCK);
 		index->lock_type = F_RDLCK;
-                (void)mail_index_lock_mprotect(index, F_RDLCK);
 	}
 
 	if (index->copy_lock_path != NULL) {
@@ -458,7 +414,6 @@
 	if (index->shared_lock_count == 0 && index->excl_lock_count == 0) {
 		index->lock_id += 2;
 		index->lock_type = F_UNLCK;
-		(void)mail_index_lock_mprotect(index, F_UNLCK);
 		if (index->lock_method != MAIL_INDEX_LOCK_DOTLOCK) {
 			if (mail_index_lock_fd(index, index->fd,
 					       F_UNLCK, 0) < 0) {

Index: mail-index-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-private.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- mail-index-private.h	10 Oct 2004 17:25:44 -0000	1.31
+++ mail-index-private.h	17 Oct 2004 16:42:20 -0000	1.32
@@ -130,8 +130,6 @@
 void mail_index_unlock(struct mail_index *index, unsigned int lock_id);
 /* Returns 1 if given lock_id is valid, 0 if not. */
 int mail_index_is_locked(struct mail_index *index, unsigned int lock_id);
-int mail_index_map_lock_mprotect(struct mail_index *index,
-				 struct mail_index_map *map, int lock_type);
 
 int mail_index_lock_fd(struct mail_index *index, int fd, int lock_type,
 		       unsigned int timeout_secs);

Index: mail-index-view-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-view-private.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- mail-index-view-private.h	26 Sep 2004 14:15:54 -0000	1.10
+++ mail-index-view-private.h	17 Oct 2004 16:42:20 -0000	1.11
@@ -45,7 +45,6 @@
 	unsigned int inconsistent:1;
 	unsigned int syncing:1;
 	unsigned int external:1;
-	unsigned int map_protected:1;
 };
 
 void mail_index_view_clone(struct mail_index_view *dest,

Index: mail-index-view-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-view-sync.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- mail-index-view-sync.c	8 Oct 2004 17:51:48 -0000	1.22
+++ mail-index-view-sync.c	17 Oct 2004 16:42:20 -0000	1.23
@@ -339,7 +339,6 @@
 		mail_index_unmap(view->index, view->map);
 		view->map = view->new_map;
 		view->new_map = NULL;
-		view->map_protected = FALSE;
 	}
 
 	if ((ctx->trans_sync_mask & MAIL_TRANSACTION_APPEND) != 0)

Index: mail-index-view.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-view.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- mail-index-view.c	10 Oct 2004 17:25:44 -0000	1.24
+++ mail-index-view.c	17 Oct 2004 16:42:20 -0000	1.25
@@ -36,18 +36,6 @@
 	i_free(view);
 }
 
-static int mail_index_view_map_protect(struct mail_index_view *view)
-{
-	/* not head mapping, no need to lock */
-	if (!view->map_protected) {
-		if (mail_index_map_lock_mprotect(view->index, view->map,
-						 F_RDLCK) < 0)
-			return -1;
-		view->map_protected = TRUE;
-	}
-	return 0;
-}
-
 int mail_index_view_lock_head(struct mail_index_view *view, int update_index)
 {
 	unsigned int lock_id;
@@ -80,13 +68,6 @@
 
 	i_assert(view->index->lock_type != F_UNLCK);
 
-	/* mail_index_lock_shared() may have reopened the file,
-	   so do this after it. */
-	if (view->map != view->index->map) {
-		if (mail_index_view_map_protect(view) < 0)
-			return -1;
-	}
-
 	return 0;
 }
 
@@ -95,23 +76,11 @@
 	if (mail_index_view_is_inconsistent(view))
 		return -1;
 
-	if (view->map != view->index->map) {
-		if (mail_index_view_map_protect(view) < 0)
-			return -1;
-		return 0;
-	}
-
 	return mail_index_view_lock_head(view, FALSE);
 }
 
 void mail_index_view_unlock(struct mail_index_view *view)
 {
-	if (view->map_protected) {
-		(void)mail_index_map_lock_mprotect(view->index, view->map,
-						   F_UNLCK);
-		view->map_protected = FALSE;
-	}
-
 	if (view->lock_id != 0) {
 		mail_index_unlock(view->index, view->lock_id);
 		view->lock_id = 0;

Index: mail-index.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.153
retrieving revision 1.154
diff -u -d -r1.153 -r1.154
--- mail-index.c	10 Oct 2004 17:25:44 -0000	1.153
+++ mail-index.c	17 Oct 2004 16:42:20 -0000	1.154
@@ -347,7 +347,7 @@
 		map->buffer = NULL;
 	}
 
-	map->mmap_base = index->lock_type != F_WRLCK ?
+	map->mmap_base = index->readonly ?
 		mmap_ro_file(index->fd, &map->mmap_size) :
 		mmap_rw_file(index->fd, &map->mmap_size);
 	if (map->mmap_base == MAP_FAILED) {
@@ -1161,15 +1161,6 @@
 	if (index->readonly)
 		return;
 
-	/* make sure we can write the header */
-	if (!MAIL_INDEX_MAP_IS_IN_MEMORY(index->map)) {
-		if (mprotect(index->map->mmap_base, sizeof(hdr),
-			     PROT_READ | PROT_WRITE) < 0) {
-			mail_index_set_syscall_error(index, "mprotect()");
-			return;
-		}
-	}
-
 	hdr = *index->hdr;
 	hdr.flags |= MAIL_INDEX_HDR_FLAG_CORRUPTED;
 	if (mail_index_write_base_header(index, &hdr) == 0) {



More information about the dovecot-cvs mailing list