Commit Diff
Diff:
d43e0b23190a4b1b2fcf074f9522986498a23a3c
806ac5983ba1a456b7111f222dcbd0613628bb23
Commit:
806ac5983ba1a456b7111f222dcbd0613628bb23
Tree:
d811045502d4ecd9f1bda139770b5f770cafec62
Author:
pjp <pjp@delphinusdns.org>
Committer:
pjp <pjp@delphinusdns.org>
Date:
Sun Jul 12 14:44:52 2020 UTC
Message:
change the sizeof struct sf_imsg to 1024 bytes, adjust the contents into a struct within a union, unfortunately the code looks a bit unpretty but I'm not sure if a #define alias will help it. Will ponder about this. Also I had to enable the scrambling of the cfg->sfptrsize. This needs more work in future commits. Possibly next week.
blob - bd5466e25112751f4d5ba05a45ec08c456002bbd
blob + 815d943e3d7d3c4438b13cc4a5100bf902752a0d
--- ddd-db.h
+++ ddd-db.h
@@ -27,7 +27,7 @@
*/
/*
- * $Id: ddd-db.h,v 1.42 2020/07/11 20:43:18 pjp Exp $
+ * $Id: ddd-db.h,v 1.43 2020/07/12 14:44:52 pjp Exp $
*/
#ifndef _DB_H
@@ -469,10 +469,16 @@ struct reply_logic {
#endif
struct sf_imsg {
- int read;
- int len;
- char pad[12];
- struct sforward sf;
+ union {
+ struct {
+ int read; /* 4 */
+ int len; /* 8 */
+ char pad[10]; /* 18 */
+ struct sforward sf; /* 924 */
+ } s;
+
+ char pad[1024];
+ } u;
};
struct rr_imsg {
blob - 42283e6fd021cd854bfafa8b42c3191522391f92
blob + 34c1f863698888f1a323decf8f5d815fe231065f
--- ddd-dns.h
+++ ddd-dns.h
@@ -27,7 +27,7 @@
*/
/*
- * $Id: ddd-dns.h,v 1.21 2020/07/10 10:42:27 pjp Exp $
+ * $Id: ddd-dns.h,v 1.22 2020/07/12 14:44:52 pjp Exp $
*/
#ifndef _DNS_H
@@ -297,28 +297,28 @@ struct parsequestion {
};
struct sforward {
- int family;
- time_t gotit;
+ int family; /* 4 */
+ time_t gotit; /* 12 */
- struct sockaddr_in from4;
- struct sockaddr_in6 from6;
+ struct sockaddr_in from4; /* 28 */
+ struct sockaddr_in6 from6; /* 56 */
- int oldsel;
- uint16_t rport;
- char buf[512];
- int buflen;
- struct dns_header header;
- uint16_t type;
- uint16_t class;
- uint16_t edns0len;
- int dnssecok;
+ int oldsel; /* 60 */
+ uint16_t rport; /* 62 */
+ char buf[512]; /* 574 */
+ int buflen; /* 578 */
+ struct dns_header header; /* 592 */
+ uint16_t type; /* 594 */
+ uint16_t class; /* 596 */
+ uint16_t edns0len; /* 598 */
+ int dnssecok; /* 602 */
- int havemac;
- char tsigname[256];
- int tsignamelen;
- uint64_t tsigtimefudge;
+ int havemac; /* 606 */
+ char tsigname[256]; /* 862 */
+ int tsignamelen; /* 866 */
+ uint64_t tsigtimefudge; /* 874 */
- char mac[32];
+ char mac[32]; /* 906 */
};
blob - bf52d2c03a5848c2956ab7a79897122fa154749b
blob + 4f25cce07bf60006b369cd4488a7f2d6f28e590d
--- delphinusdnsd.c
+++ delphinusdnsd.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: delphinusdnsd.c,v 1.121 2020/07/11 20:43:18 pjp Exp $
+ * $Id: delphinusdnsd.c,v 1.122 2020/07/12 14:44:52 pjp Exp $
*/
@@ -1084,8 +1084,8 @@ main(int argc, char *argv[], char *environ[])
}
/* initialize */
- for (sf = (struct sf_imsg *)&shptr[16], j = 0; j < SHAREDMEMSIZE; j++, sf++) {
- sf->read = 1;
+ for (sf = (struct sf_imsg *)&shptr[0], j = 0; j < SHAREDMEMSIZE; j++, sf++) {
+ sf->u.s.read = 1;
}
cfg->shptr = shptr;
@@ -1181,7 +1181,10 @@ main(int argc, char *argv[], char *environ[])
/* shptr has no business in parse process */
minherit(cfg->shptr, cfg->shptrsize,
MAP_INHERIT_NONE);
+#if 0
cfg->shptrsize = arc4random();
+ /* disable for now */
+#endif
cfg->shptr2size = arc4random();
cfg->shptr3size = arc4random();
@@ -1653,7 +1656,10 @@ mainloop(struct cfg *cfg, struct imsgbuf *ibuf)
MAP_INHERIT_NONE);
minherit(cfg->shptr3, cfg->shptr3size,
MAP_INHERIT_NONE);
+#if 0
+ /* disable for now */
cfg->shptrsize = arc4random();
+#endif
cfg->shptr2size = arc4random();
cfg->shptr3size = arc4random();
}
@@ -1677,7 +1683,10 @@ mainloop(struct cfg *cfg, struct imsgbuf *ibuf)
MAP_INHERIT_NONE);
minherit(cfg->shptr3, cfg->shptr3size,
MAP_INHERIT_NONE);
+#if 0
+ /* disable for now */
cfg->shptrsize = arc4random();
+#endif
cfg->shptr2size = arc4random();
cfg->shptr3size = arc4random();
}
@@ -2230,20 +2239,20 @@ forwardudp:
sforward->havemac = 0;
sforward->gotit = time(NULL);
- memcpy(&sf.sf, sforward, sizeof(struct sforward));
+ memcpy(&sf.u.s.sf, sforward, sizeof(struct sforward));
/* wait for lock */
- while (cfg->shptr[0] == '*') {
+ while (cfg->shptr[cfg->shptrsize - 16] == '*') {
usleep(arc4random() % 300);
}
- cfg->shptr[0] = '*'; /* nice semaphore eh? */
+ cfg->shptr[cfg->shptrsize - 16] = '*'; /* nice semaphore eh? */
- for (sfi = (struct sf_imsg *)&cfg->shptr[16], ix = 0;
+ for (sfi = (struct sf_imsg *)&cfg->shptr[0], ix = 0;
ix < SHAREDMEMSIZE; ix++, sfi++) {
- if (unpack32((char *)&sfi->read) == 1) {
+ if (unpack32((char *)&sfi->u.s.read) == 1) {
memcpy(sfi, &sf, sizeof(struct sf_imsg));
- pack32((char *)&sfi->read, 0);
+ pack32((char *)&sfi->u.s.read, 0);
break;
}
}
@@ -2253,7 +2262,7 @@ forwardudp:
goto udpout;
}
- cfg->shptr[0] = ' ';
+ cfg->shptr[cfg->shptrsize - 16] = ' ';
imsg_compose(udp_ibuf, IMSG_FORWARD_UDP,
0, 0, -1, &ix, sizeof(int));
@@ -3289,20 +3298,20 @@ forwardtcp:
sforward->havemac = 0;
sforward->gotit = time(NULL);
- memcpy(&sf.sf, sforward, sizeof(struct sforward));
+ memcpy(&sf.u.s.sf, sforward, sizeof(struct sforward));
/* wait for lock */
- while (cfg->shptr[0] == '*') {
+ while (cfg->shptr[cfg->shptrsize - 16] == '*') {
usleep(arc4random() % 300);
}
- cfg->shptr[0] = '*'; /* nice semaphore eh? */
+ cfg->shptr[cfg->shptrsize - 16] = '*'; /* nice semaphore eh? */
- for (sfi = (struct sf_imsg *)&cfg->shptr[16], ix = 0;
+ for (sfi = (struct sf_imsg *)&cfg->shptr[0], ix = 0;
ix < SHAREDMEMSIZE; ix++, sfi++) {
- if (unpack32((char *)&sfi->read) == 1) {
+ if (unpack32((char *)&sfi->u.s.read) == 1) {
memcpy(sfi, &sf, sizeof(struct sf_imsg));
- pack32((char *)&sfi->read, 0);
+ pack32((char *)&sfi->u.s.read, 0);
break;
}
}
@@ -3312,7 +3321,7 @@ forwardtcp:
goto tcpout;
}
- cfg->shptr[0] = ' ';
+ cfg->shptr[cfg->shptrsize - 16] = ' ';
imsg_compose(ibuf, IMSG_FORWARD_TCP,
blob - bdab6f15c1805f95160563651cfdb8e3127e53a1
blob + 6d8f384467d05b09a3e2bfc5e466c31eb6892428
--- forward.c
+++ forward.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: forward.c,v 1.19 2020/07/11 10:01:56 pjp Exp $
+ * $Id: forward.c,v 1.20 2020/07/12 14:44:52 pjp Exp $
*/
#include <sys/types.h>
@@ -541,7 +541,7 @@ drop:
memcpy(&i, imsg.data, sizeof(i));
- sf = (struct sf_imsg *)&ptr[16];
+ sf = (struct sf_imsg *)&ptr[0];
sf = &sf[i];
rdata = malloc(sizeof(struct sforward));
@@ -551,7 +551,7 @@ drop:
break;
}
- memcpy(rdata, &sf->sf, sizeof(struct sforward));
+ memcpy(rdata, &sf->u.s.sf, sizeof(struct sforward));
time0 = time(NULL);
@@ -567,13 +567,13 @@ drop:
#endif
free(rdata);
/* aquire lock */
- while (ptr[0] == '*')
+ while (ptr[cfg->shptrsize - 16] == '*')
usleep(arc4random() % 300);
- ptr[0] = '*';
+ ptr[cfg->shptrsize - 16] = '*';
- sf->read = 1;
+ sf->u.s.read = 1;
- ptr[0] = ' '; /* release */
+ ptr[cfg->shptrsize - 16] = ' '; /* release */
break;
@@ -586,7 +586,7 @@ drop:
memcpy(&i, imsg.data, sizeof(i));
- sf = (struct sf_imsg *)&ptr[16];
+ sf = (struct sf_imsg *)&ptr[0];
sf = &sf[i];
rdata = malloc(sizeof(struct sforward));
@@ -596,7 +596,7 @@ drop:
break;
}
- memcpy(rdata, &sf->sf, sizeof(struct sforward));
+ memcpy(rdata, &sf->u.s.sf, sizeof(struct sforward));
time0 = time(NULL);
forwardthis(db, cfg, imsg.fd, (struct sforward *)rdata);
now = time(NULL);
@@ -605,13 +605,13 @@ drop:
#endif
free(rdata);
/* aquire lock */
- while (ptr[0] == '*')
+ while (ptr[cfg->shptrsize - 16] == '*')
usleep(arc4random() % 300);
- ptr[0] = '*';
+ ptr[cfg->shptrsize - 16] = '*';
- sf->read = 1;
+ sf->u.s.read = 1;
- ptr[0] = ' '; /* release */
+ ptr[cfg->shptrsize - 16] = ' '; /* release */
break;
}
repomaster@centroid.eu