# elfedit -e 'dyn:runpath $ORIGIN/../lib' /opt/bin/myprog
There is a nice blog entry about it from Ali Bahrami.
# elfedit -e 'dyn:runpath $ORIGIN/../lib' /opt/bin/myprog
When overwriting a block which is check summed with a cryptographically secure hash function we can compare the old and new checksums for the block to determine if they differ (at almost no cost since we were going to do the checksums anyway). If they do not differ we don't actually need to do the write. This:Philosophical question - should we just trust sha256?
1) Reduces I/O
2) Reduces space usage, because if the old block is referenced by a snapshot we will need to keep both copies of the block around even though they contain the same data.
This functionality is only enabled if:
1) The old and new blocks are checksummed using the same algorithm.
2) That algorithm is cryptographically secure (e.g. sha256)
3) Compression is enabled on that block.
cwafseng3 $ pmap -ax $$ 27709: bash Address Kbytes RSS Anon Locked Mode Mapped File 08050000 968 968 - - r-x-- bash 08151000 76 76 8 - rwx-- bash 08164000 140 140 56 - rwx-- [ heap ] F05D0000 440 440 - - r-x-- libnsl.so.1 F064E000 8 8 4 - rw--- libnsl.so.1 F0650000 20 12 - - rw--- libnsl.so.1 F0660000 56 56 - - r-x-- libsocket.so.1 F067E000 4 4 - - rw--- libsocket.so.1 FE560000 64 16 - - rwx-- [ anon ] FE577000 4 4 4 - rwxs- [ anon ] FE580000 24 12 4 - rwx-- [ anon ] FE590000 4 4 4 - rw--- [ anon ] FE5A0000 1352 1352 - - r-x-- libc_hwcap1.so.1 FE702000 44 44 16 - rwx-- libc_hwcap1.so.1 FE70D000 4 4 - - rwx-- libc_hwcap1.so.1 FE710000 4 4 - - r-x-- libdl.so.1 FE720000 4 4 4 - rw--- [ anon ] FE730000 184 184 - - r-x-- libcurses.so.1 FE76E000 16 16 - - rw--- libcurses.so.1 FE772000 8 8 - - rw--- libcurses.so.1 FE780000 4 4 4 - rw--- [ anon ] FE790000 4 4 4 - rw--- [ anon ] FE7A0000 4 4 - - rw--- [ anon ] FE7AD000 4 4 - - r--s- [ anon ] FE7B4000 220 220 - - r-x-- ld.so.1 FE7FB000 8 8 4 - rwx-- ld.so.1 FE7FD000 4 4 - - rwx-- ld.so.1 FEFFB000 16 16 4 - rw--- [ stack ] -------- ------- ------- ------- ------- total Kb 3688 3620 116 -
$ ./pr_memcntl 27709 pr_memcntl() failed: Not owner
$ ppriv -D 27709
bash[27709]: missing privilege "proc_lock_memory"
(euid = 145104, syscall = 131) needed at memcntl+0x140
$ ppriv -s EP+proc_lock_memory 27709 $ ./pr_memcntl 27709 $This time no error, lets see the pmap output again:
$ pmap -ax $$ 27709: bash Address Kbytes RSS Anon Locked Mode Mapped File 08050000 968 968 - 968 r-x-- bash 08151000 76 76 8 76 rwx-- bash 08164000 140 140 48 140 rwx-- [ heap ] F05D0000 440 440 - 440 r-x-- libnsl.so.1 F064E000 8 8 4 - rw--- libnsl.so.1 F0650000 20 12 - - rw--- libnsl.so.1 F0660000 56 56 - 56 r-x-- libsocket.so.1 F067E000 4 4 - - rw--- libsocket.so.1 FE560000 64 64 - 64 rwx-- [ anon ] FE577000 4 4 4 - rwxs- [ anon ] FE580000 24 24 4 24 rwx-- [ anon ] FE590000 4 4 4 - rw--- [ anon ] FE5A0000 1352 1352 - 1352 r-x-- libc_hwcap1.so.1 FE702000 44 44 16 44 rwx-- libc_hwcap1.so.1 FE70D000 4 4 - 4 rwx-- libc_hwcap1.so.1 FE710000 4 4 - 4 r-x-- libdl.so.1 FE720000 4 4 4 - rw--- [ anon ] FE730000 184 184 - 184 r-x-- libcurses.so.1 FE76E000 16 16 - - rw--- libcurses.so.1 FE772000 8 8 - - rw--- libcurses.so.1 FE780000 4 4 4 - rw--- [ anon ] FE790000 4 4 4 - rw--- [ anon ] FE7A0000 4 4 - - rw--- [ anon ] FE7AD000 4 4 - - r--s- [ anon ] FE7B4000 220 220 - 220 r-x-- ld.so.1 FE7FB000 8 8 4 8 rwx-- ld.so.1 FE7FD000 4 4 - 4 rwx-- ld.so.1 FEFFB000 16 16 4 - rw--- [ stack ] -------- ------- ------- ------- ------- total Kb 3688 3680 108 3588
// gcc -m64 -lproc -I. -o pr_memcntl pr_memcntl.c
#include <sys/types.h>
#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <libproc.h>
int main(int argc, char **argv) {
pid_t pid;
int perr;
static struct ps_prochandle *Pr;
pid = atoi(argv[1]);
if((Pr = Pgrab(pid, PGRAB_NOSTOP, &perr)) == NULL) {
printf("Pgrab() failed: %s\n", Pgrab_error(perr));
exit(1);
}
if(pr_memcntl(Pr, 0, 0, MC_LOCKAS, (caddr_t)(MCL_CURRENT|MCL_FUTURE), PROC_TEXT, (int)0)) {
perror("pr_memcntl() failed");
Prelease(Pr, 0);
exit(1);
}
if(pr_memcntl(Pr, 0, 0, MC_LOCKAS, (caddr_t)(MCL_CURRENT|MCL_FUTURE), PROC_TEXT|PROT_WRITE, (int)0)) {
perror("pr_memcntl() failed");
Prelease(Pr, 0);
exit(1);
}
Prelease(Pr, 0);
Pr = NULL;
exit(0);
}