/* ** CHECKEXE.C - checksum protection for executable files ** ** by: Bob Jarvis */ #include #include #include #include static struct { unsigned char marker[16]; unsigned long checksum; } marker_struct = {"CHECKEXE MARKER",0L}; void checkexe(char *fname) { FILE *fptr; unsigned int c; int first_time = 0, i; char buffer[14]; unsigned long chksum = 0L; unsigned long l; unsigned long marker_offset; unsigned char *charptr; time_t tm; fptr = fopen(fname,"r+b"); if(fptr == NULL) { fprintf(stderr,"checkexe : unable to open input file '%s'\n", fname); exit(99); } setvbuf(fptr, NULL, _IOFBF, 32767); /* try to get a 32K buffer */ /* * If this is the first time the check has been run, scan the entire file * to find the marker. Otherwise proceed. */ if(marker_struct.checksum == 0L) { first_time = 1; c = fgetc(fptr); while(!feof(fptr)) { if(c == (unsigned int)marker_struct.marker[0]) { fread(buffer,sizeof(buffer),1,fptr); if(memcmp(buffer,&marker_struct.marker[1], sizeof(buffer)) == 0) { marker_offset = ftell(fptr) + 1L; break; } fseek(fptr,-13L,SEEK_CUR); } c = fgetc(fptr); } if(feof(fptr)) { fprintf(stderr,"checkexe : unable to locate marker\n"); exit(99); } /* Change the marker field to random values */ tm = time(NULL); srand((unsigned int)tm); for(i = 0 ; i < sizeof(marker_struct.marker) ; ++i) marker_struct.marker[i] = (unsigned char) rand(); fseek(fptr,marker_offset - sizeof(marker_struct.marker),SEEK_SET); fwrite(marker_struct.marker,sizeof(marker_struct.marker),1,fptr); } /* Calculate the checksum for the entire file */ rewind(fptr); c = fgetc(fptr); for(l = 0 ; !feof(fptr) ; ++l) { chksum += (unsigned long)c; c = fgetc(fptr); } if(first_time) { marker_struct.checksum = chksum; fseek(fptr,marker_offset,SEEK_SET); fwrite(&marker_struct.checksum,sizeof(unsigned long),1,fptr); } else { charptr = (unsigned char*) &marker_struct.checksum; for(i = 0 ; i < sizeof(marker_struct.checksum) ; ++i) chksum -= (unsigned long)(charptr[i]); if(chksum != marker_struct.checksum) { fprintf(stderr, "\acheckexe : %s has been altered, " "possibly by a virus\n", fname); exit(99); } } fclose(fptr); return; } main(int argc, char *argv[]) { checkexe(argv[0]); return EXIT_SUCCESS; } n>space:mode:
authorMichal Hocko <mhocko@suse.com>2016-04-07 17:12:31 +0200
committerIngo Molnar <mingo@kernel.org>2016-04-22 08:58:33 +0200
commit916633a403702549d37ea353e63a68e5b0dc27ad (patch)
tree2e36d9a73b0b8781aac44e2b99fa749b7122d2ce /.mailmap
parent664b4e24c6145830885e854195376351b0eb3eee (diff)
locking/rwsem: Provide down_write_killable()
Now that all the architectures implement the necessary glue code we can introduce down_write_killable(). The only difference wrt. regular down_write() is that the slow path waits in TASK_KILLABLE state and the interruption by the fatal signal is reported as -EINTR to the caller. Signed-off-by: Michal Hocko <mhocko@suse.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Chris Zankel <chris@zankel.net> Cc: David S. Miller <davem@davemloft.net> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Max Filippov <jcmvbkbc@gmail.com> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Signed-off-by: Davidlohr Bueso <dbueso@suse.de> Cc: Signed-off-by: Jason Low <jason.low2@hp.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tony Luck <tony.luck@intel.com> Cc: linux-alpha@vger.kernel.org Cc: linux-arch@vger.kernel.org Cc: linux-ia64@vger.kernel.org Cc: linux-s390@vger.kernel.org Cc: linux-sh@vger.kernel.org Cc: linux-xtensa@linux-xtensa.org Cc: sparclinux@vger.kernel.org Link: http://lkml.kernel.org/r/1460041951-22347-12-git-send-email-mhocko@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to '.mailmap')