From 33d59ee83a819742c93267bca9cedddc92f7a112 Mon Sep 17 00:00:00 2001 From: Stefanos Kornilios Misis Poiitidis Date: Wed, 6 Apr 2022 16:33:13 +0300 Subject: [PATCH] Add mmap + shmdt test --- smc-shmatdt | Bin 0 -> 25672 bytes src/smc-shmatdt.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100755 smc-shmatdt create mode 100644 src/smc-shmatdt.cpp diff --git a/smc-shmatdt b/smc-shmatdt new file mode 100755 index 0000000000000000000000000000000000000000..5b7a47f9ea43fe9ac11bd3540f36b9f70b873cda GIT binary patch literal 25672 zcmeHwd3c=FdGDDSjWqHnjU<)o z+3GA+3cN&Un%}AcxH`S;E`&Zq_W)9FGBabqX_~Aov^6B8-s#fjGR?72RcoAjUSx;5@Hq+~S(vX!-|TM?w%Wg<2pYc}GSKP~rQRJz?+&A9;Ym}T zh1Q?+34cqBKZ{`qJf@Ibl`7WTX7q~T8Y6EZ%V65_YNqQyQ{HByw>2bYR54ty$;v`o z-X+kZU;d-XcJrmCywml=ZsUIojeAv7e_!XKmZtu$hW@@pc6Y<>C5svswKS%ajq{}n ztQX7Ra9OwUG6ge7Ni%MgzNj@g`L#cK?8@tYQhoQcKm6@Ip9_9>!m7%dhpY{jNf{>U z+aW=m`3n3fquYNIa+*f?V*CdKgr`eAV1&kC&IE1Z81(Z`L!WgTddF$#`#=xjSDczb z7^~dLr=e4JEP3ZN^xHuX;a8lNfpBIqkvRG}#%^7t(!B#c@eDy!uCYu%k*~bYCgNM8o&D788Av9KW<-mQDah)&&A-AN#|Qt7EN|H< zedUy~%eGyA?7X*5J!IAwOFwGXeP1g}8(AkT{_=&I&aueyZ2CnW-7cZz9nYiZ&)<`I zboQl9@8;1t?rl0^=v?0O=f?wibUXK`^Kc&Bt|6p9mPa?Y3X;{)Ji7G->CffS;m}-q zA&)*GM;*_MdtlrH;~p6Iz__!!LyQ zeb;wPDnGpNT98i-&)N=9HB(W(mz+~4emOim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include +#include +#include +#include +#include +#include +#include +#include + +void test(char* code, const char* name) { + code[0] = 0xB8; + code[1] = 0xAA; + code[2] = 0xBB; + code[3] = 0xCC; + code[4] = 0xDD; + + code[5] = 0xC3; + + auto fn = (int(*)())code; + auto e1 = fn(); + code[3]=0xFE; + auto e2 = fn(); + + mprotect(code, 4096, PROT_READ | PROT_EXEC); + + mprotect(code, 4096, PROT_READ | PROT_WRITE | PROT_EXEC); + + code[3] = 0xF3; + + mprotect(code, 4096, PROT_READ | PROT_EXEC); + + auto e3 = fn(); + + mprotect(code, 4096, PROT_READ | PROT_WRITE | PROT_EXEC); + + code[3] = 0xF1; + + auto e4 = fn(); + + printf("%s-1: %X, %s\n", name, e1, e1 != 0xDDCCBBAA? "FAIL" : "PASS"); + printf("%s-2: %X, %s\n", name, e2, e2 != 0xDDFEBBAA? "FAIL" : "PASS"); + printf("%s-3: %X, %s\n", name, e3, e3 != 0xDDF3BBAA? "FAIL" : "PASS"); + printf("%s-4: %X, %s\n", name, e4, e4 != 0xDDF1BBAA? "FAIL" : "PASS"); +} + +int main() { + auto shmid = shmget(IPC_PRIVATE, 4096 * 3, IPC_CREAT | 0777); + auto ptrshm = (char*)shmat(shmid, 0, 0); + shmctl(shmid, IPC_RMID, NULL); + auto ptrmmap = (char*)mmap(ptrshm + 4096, 4096, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_FIXED | MAP_PRIVATE | MAP_ANON, 0, 0); + shmdt(ptrshm); + test(ptrmmap, "mmap+shmdt"); + return 0; +}