lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <87vdfphmyn.fsf@erwin.mina86.com>
Date:	Tue, 29 Dec 2009 15:30:24 +0100
From:	Michal Nazarewicz <mina86@...n.pl>
To:	darshan.ghumare@...il.com
Cc:	linux-c-programming@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: Msync Invalid Arg

darshan.ghumare@...il.com writes:

> Whne I try to execute following code I get "Invalid Argumemt" error
> message in msync.

/* Code rewritten to be shorter */

> #include <fcntl.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <sys/mman.h>
> #include <unistd.h>
> 
> #define DIE_IF(cnd, msg) do{ if (cnd) { perror(msg); return 1; } }while(0)
> 
> int main(void)
> {
> 	char data[20];
> 	void *addr;
> 	int fd, ret;
> 
> 	fd = open("/dev/mem", O_RDWR | O_SYNC);
> 	DIE_IF(fd < 0, "open");
> 
> 	addr = mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
> 	DIE_IF(addr == MAP_FAILED, "mmap");
> 
> 	strcpy(data, "Test Msg");
> 	ret = write(fd, data, strlen(data));
> 	DIE_IF(ret < 0, "write");
> 
> 	ret = msync(addr, 4096, MS_SYNC);
> 	DIE_IF(ret < 0, "msync");
> 
> 	ret = lseek(fd, 0, SEEK_SET);
> 	DIE_IF(ret < 0, "lseek");
> 
> 	memset(data, 0, sizeof data);
> 	ret = read(fd, data, sizeof data);
> 	DIE_IF(ret < 0, "read");
> 	printf("Read: %s.\n", data);
> 
> 	return 0;
> }


The msync(2) fails because /dev/mem driver (drivers/char/mem.c) does not
implement fsync file operation which is used by msync(2) system call.

This sort of makes sense since there is no need to sync the /dev/mem
file -- there is no backing storage on hard drive or anywhere, when you
write data there you write directly to the memory and same goes for
reading.

Anyhow, I'm Ccing this to linux-kernel as maybe we need a dummy fsync
operation for /dev/mem which would do nothing and return zero?

--
Best regards,                                         _     _
 .o. | Liege of Serenly Enlightened Majesty of      o' \,=./ `o
 ..o | Computer Science,  Michal "mina86" Nazarewicz   (o o)
 ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--

Content of type "application/pgp-signature" skipped

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ