From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eigenstate.org ([206.124.132.107]) by ewsd; Sat Nov 24 00:55:58 EST 2018 Received: from eigenstate.org (localhost [127.0.0.1]) by eigenstate.org (OpenSMTPD) with ESMTP id 0e2492a9 for <9front@9front.org>; Fri, 23 Nov 2018 21:55:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=eigenstate.org; h=date :from:to:subject:message-id:mime-version:content-type :content-transfer-encoding; s=mail; bh=MhIXP/fZ49pYTr9u+HQ9Qh24M B8=; b=jHITLAwb/6wGF9AAqBcbOjtGS0tWLMFFp9nWFBTNhgXpRscG8kJxT0KeS E7G1XImCrb1m+f4T8YUS7WLwVuYlIQnrmr2K9v+dOum5KSGf/mkqy9R/RDN/Hl4u 5GTC/ORrGxLRxv4hmJNFqDnEiKkA8Z8BfDyysejLZfQ/vWMTgU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=eigenstate.org; h=date:from :to:subject:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=mail; b=nqIhmmg1zT7wRprifly suN2jqefmzcIsV2T1vxN1RE6yKKhrfZzpQVyzgQXrmQOSk12yJzlxfSDOsNCp2Q6 8N+TwMS9/fuPWsWwe5SDbEyx4YU0JuaGQgI68zoISy3kUCJbqwnZrasonABjtupu D1ZmNhw4wcK8dsF95UEAbe8w= Received: from gooseberry.hsd1.ca.comcast.net. (c-76-21-119-139.hsd1.ca.comcast.net [76.21.119.139]) by eigenstate.org (OpenSMTPD) with ESMTPSA id 46d462be (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO) for <9front@9front.org>; Fri, 23 Nov 2018 21:55:54 -0800 (PST) Date: Fri, 23 Nov 2018 21:55:53 -0800 From: Ori Bernstein To: 9front@9front.org Subject: Fixes for front9port. Message-Id: <20181123215553.05548e7a6845935511ccccb2@eigenstate.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-unknown-openbsd6.4) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: content-addressed extended HTML over ORM self-signing session module-aware control A few misc changes that I've had locally for a while, but never committed. I mainly use the plumber, along with (sometimes) sam. - Fixes sam interepreting the unix integer return code as a char*, and crashing when trying to dereference it. - Fixes AES using the wrong type (u32 should have been 32 bits, not 64 bits). - Maps the stack as a stack on openbsd, which prevents the kernel from killing the process. - Allows 'chrome' as the name of the browser (BSDs tend to install chromium under that name) Ok to commit? # HG changeset patch # User Ori Bernstein # Date 1524465914 25200 # Sun Apr 22 23:45:14 2018 -0700 # Node ID 03ae02d4c6e9b6cc48f1a86f8e1fb73aeac5213a # Parent a798c8d8e3f6091b6dff43c77d630df989b13605 Fix sam command execution. Currently, sam tries to treat the result of waiting for a function as a pointer, but it's an integer. Pointers being treated as integers lead to segfaults. This fixes the usage of the wait status. diff -r a798c8d8e3f6 -r 03ae02d4c6e9 src/cmd/sam/shell.c --- a/src/cmd/sam/shell.c Mon Aug 07 22:14:03 2017 -0400 +++ b/src/cmd/sam/shell.c Sun Apr 22 23:45:14 2018 -0700 @@ -17,7 +17,6 @@ int m; int pid, fd; int retcode; - char *retmsg; int pipe1[2], pipe2[2]; if(s->s[0]==0 && plan9cmd.s[0]==0) @@ -123,15 +122,15 @@ bufload(&cmdbuf, cmdbufpos, pipe1[0], &nulls); close(pipe1[0]); } - retmsg = waitfor(pid); + retcode = waitfor(pid); if(type=='|' || type=='<' || type=='_' || type=='^') - if(retmsg[0]!=0) - warn_s(Wbadstatus, retmsg); + if(retcode!=0) + warn_s(Wbadstatus, "bad"); if(downloaded) checkerrs(); if(!nest) dprint("!\n"); - return retmsg[0] ? -1 : 0; + return retcode==0 ? -1 : 0; } void # HG changeset patch # User Ori Bernstein # Date 1528215932 25200 # Tue Jun 05 09:25:32 2018 -0700 # Node ID 0e100ffc7cae00b369d2766b0cd9db9a700d86cf # Parent 03ae02d4c6e9b6cc48f1a86f8e1fb73aeac5213a Allow 'chrome' as the web browser name. diff -r 03ae02d4c6e9 -r 0e100ffc7cae bin/web --- a/bin/web Sun Apr 22 23:45:14 2018 -0700 +++ b/bin/web Tue Jun 05 09:25:32 2018 -0700 @@ -34,7 +34,7 @@ $BROWSER -remote 'openURL('"$@"',new-tab)' || $BROWSER "$@" ;; - *google-chrome*|*chromium*) + *google-chrome*|*chromium*|*chrome*) $BROWSER "$@" ;; esac # HG changeset patch # User Ori Bernstein # Date 1528216093 25200 # Tue Jun 05 09:28:13 2018 -0700 # Node ID b11ffb8db544409e2fd3d52fb07f990008c0862f # Parent 0e100ffc7cae00b369d2766b0cd9db9a700d86cf Add support for OpenBSD-current's stack mapping checks. OpenBSD is starting to validate that the stack pointer points to an address range that is mapped as stack data. This change acquires the memory by mapping it as stack. diff -r 0e100ffc7cae -r b11ffb8db544 src/libthread/OpenBSD-386.c --- a/src/libthread/OpenBSD-386.c Tue Jun 05 09:25:32 2018 -0700 +++ b/src/libthread/OpenBSD-386.c Tue Jun 05 09:28:13 2018 -0700 @@ -1,4 +1,8 @@ #include "threadimpl.h" +#include + +#define MAX(a, b) \ + ((a) > (b) ? (a) : (b)) void makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...) @@ -21,3 +25,28 @@ return 0; } +void* +stkalloc(ulong sz) +{ + void *p; + ulong *m; + + p = mmap(NULL, sz, + PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_ANON|MAP_STACK, + -1, 0); + if (p == (void*)-1) + return p; + m = p; + m[0] = sz; + return (char*)p + MAX(sizeof(ulong), 16); +} + +void +stkfree(void *p) +{ + ulong *m = (char*)p - MAX(sizeof(ulong), 16); + ulong sz = m[0]; + munmap(p, sz); +} + diff -r 0e100ffc7cae -r b11ffb8db544 src/libthread/OpenBSD-power.c --- a/src/libthread/OpenBSD-power.c Tue Jun 05 09:25:32 2018 -0700 +++ b/src/libthread/OpenBSD-power.c Tue Jun 05 09:28:13 2018 -0700 @@ -1,4 +1,8 @@ #include "threadimpl.h" +#include + +#define MAX(a, b) \ + ((a) > (b) ? (a) : (b)) void makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...) @@ -23,3 +27,28 @@ return 0; } +void* +stkalloc(ulong sz) +{ + void *p; + ulong *m; + + p = mmap(NULL, sz, + PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_ANON|MAP_STACK, + -1, 0); + if (p == (void*)-1) + return p; + m = p; + m[0] = sz; + return (char*)p + MAX(sizeof(ulong), 16); +} + +void +stkfree(void *p) +{ + ulong *m = (char*)p - MAX(sizeof(ulong), 16); + ulong sz = m[0]; + munmap(p, sz); +} + diff -r 0e100ffc7cae -r b11ffb8db544 src/libthread/OpenBSD-x86_64.c --- a/src/libthread/OpenBSD-x86_64.c Tue Jun 05 09:25:32 2018 -0700 +++ b/src/libthread/OpenBSD-x86_64.c Tue Jun 05 09:28:13 2018 -0700 @@ -1,4 +1,8 @@ #include "threadimpl.h" +#include + +#define MAX(a, b) \ + ((a) > (b) ? (a) : (b)) void makecontext(ucontext_t *uc, void (*fn)(void), int argc, ...) @@ -29,4 +33,28 @@ return 0; } +void* +stkalloc(ulong sz) +{ + void *p; + ulong *m; + p = mmap(NULL, sz, + PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_ANON|MAP_STACK, + -1, 0); + if (p == (void*)-1) + return p; + m = p; + m[0] = sz; + return (char*)p + MAX(sizeof(ulong), 16); +} + +void +stkfree(void *p) +{ + ulong *m = (ulong*)((char*)p - MAX(sizeof(ulong), 16)); + ulong sz = m[0]; + munmap(p, sz); +} + diff -r 0e100ffc7cae -r b11ffb8db544 src/libthread/thread.c --- a/src/libthread/thread.c Tue Jun 05 09:25:32 2018 -0700 +++ b/src/libthread/thread.c Tue Jun 05 09:28:13 2018 -0700 @@ -108,7 +108,7 @@ ulong z; /* allocate the task and stack together */ - t = malloc(sizeof *t+stack); + t = stkalloc(sizeof *t+stack); if(t == nil) sysfatal("threadalloc malloc: %r"); memset(t, 0, sizeof *t); @@ -364,7 +364,7 @@ delthreadinproc(p, t); p->nthread--; /*print("nthread %d\n", p->nthread); */ - free(t); + stkfree(t); } } diff -r 0e100ffc7cae -r b11ffb8db544 src/libthread/threadimpl.h --- a/src/libthread/threadimpl.h Tue Jun 05 09:25:32 2018 -0700 +++ b/src/libthread/threadimpl.h Tue Jun 05 09:28:13 2018 -0700 @@ -62,6 +62,11 @@ # include "power-ucontext.h" # endif extern pid_t rfork_thread(int, void*, int(*)(void*), void*); +extern void* stkalloc(ulong); +extern void stkfree(void*); +#else +# define stkalloc malloc +# define stkfree free #endif /* THIS DOES NOT WORK! Don't do this! # HG changeset patch # User Ori Bernstein # Date 1528216124 25200 # Tue Jun 05 09:28:44 2018 -0700 # Node ID 379c7c171d42b689d7c0432e0f75418d71bf8ce8 # Parent b11ffb8db544409e2fd3d52fb07f990008c0862f Drop the incorrect int typedefs. diff -r b11ffb8db544 -r 379c7c171d42 src/libsec/port/aes.c --- a/src/libsec/port/aes.c Tue Jun 05 09:28:13 2018 -0700 +++ b/src/libsec/port/aes.c Tue Jun 05 09:28:44 2018 -0700 @@ -33,17 +33,16 @@ #include #include -typedef uchar u8; -typedef ulong u32; +typedef u8int u8; #define FULL_UNROLL #define const -static const u32 Td0[256]; -static const u32 Td1[256]; -static const u32 Td2[256]; -static const u32 Td3[256]; -static const u8 Te4[256]; +static const u32int Td0[256]; +static const u32int Td1[256]; +static const u32int Td2[256]; +static const u32int Td3[256]; +static const u32int Te4[256]; static uchar basekey[3][16] = { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, @@ -290,7 +289,7 @@ Td4[x] = Si[x] */ -static const u32 Te0[256] = { +static const u32int Te0[256] = { 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU, 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U, 0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU, @@ -356,7 +355,7 @@ 0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U, 0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU, }; -static const u32 Te1[256] = { +static const u32int Te1[256] = { 0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU, 0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U, 0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU, @@ -422,7 +421,7 @@ 0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU, 0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U, }; -static const u32 Te2[256] = { +static const u32int Te2[256] = { 0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU, 0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U, 0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU, @@ -488,7 +487,7 @@ 0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU, 0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U, }; -static const u32 Te3[256] = { +static const u32int Te3[256] = { 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U, 0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U, @@ -555,7 +554,7 @@ 0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU, 0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU, }; -static const u8 Te4[256] = { +static const u32int Te4[256] = { 0x63U, 0x7cU, 0x77U, 0x7bU, 0xf2U, 0x6bU, 0x6fU, 0xc5U, 0x30U, 0x01U, 0x67U, 0x2bU, @@ -621,7 +620,7 @@ 0x41U, 0x99U, 0x2dU, 0x0fU, 0xb0U, 0x54U, 0xbbU, 0x16U, }; -static const u32 Td0[256] = { +static const u32int Td0[256] = { 0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U, 0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U, 0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U, @@ -687,7 +686,7 @@ 0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U, 0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U, }; -static const u32 Td1[256] = { +static const u32int Td1[256] = { 0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU, 0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U, 0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU, @@ -753,7 +752,7 @@ 0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U, 0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U, }; -static const u32 Td2[256] = { +static const u32int Td2[256] = { 0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U, 0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U, 0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U, @@ -820,7 +819,7 @@ 0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U, 0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U, }; -static const u32 Td3[256] = { +static const u32int Td3[256] = { 0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU, 0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU, 0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U, @@ -952,15 +951,15 @@ 0xe1U, 0x69U, 0x14U, 0x63U, 0x55U, 0x21U, 0x0cU, 0x7dU, }; -static const u32 rcon[] = { +static const u32int rcon[] = { 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000, 0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */ }; -#define GETU32(pt) (((u32)(pt)[0]<<24) ^ ((u32)(pt)[1]<<16) ^ \ - ((u32)(pt)[2]<< 8) ^ ((u32)(pt)[3])) +#define GETU32(pt) (((u32int)(pt)[0]<<24) ^ ((u32int)(pt)[1]<<16) ^ \ + ((u32int)(pt)[2]<< 8) ^ ((u32int)(pt)[3])) #define PUTU32(ct, st) { (ct)[0] = (u8)((st)>>24); (ct)[1] = (u8)((st)>>16); \ (ct)[2] = (u8)((st)>> 8); (ct)[3] = (u8)(st); } @@ -973,7 +972,7 @@ aes_setupEnc(ulong rk[/*4*(Nr + 1)*/], const uchar cipherKey[], int keyBits) { int i = 0; - u32 temp; + u32int temp; rk[0] = GETU32(cipherKey ); rk[1] = GETU32(cipherKey + 4); @@ -1471,11 +1470,11 @@ #ifdef INTERMEDIATE_VALUE_KAT static void -aes_encryptRound(const u32 rk[/* 4*(Nr + 1) */], int Nr, u8 block[16], +aes_encryptRound(const u32int rk[/* 4*(Nr + 1) */], int Nr, u8 block[16], int rounds) { int r; - u32 s0, s1, s2, s3, t0, t1, t2, t3; + u32int s0, s1, s2, s3, t0, t1, t2, t3; /* * map byte array block to cipher state @@ -1564,11 +1563,11 @@ } static void -aes_decryptRound(const u32 rk[/* 4*(Nr + 1) */], int Nr, u8 block[16], +aes_decryptRound(const u32int rk[/* 4*(Nr + 1) */], int Nr, u8 block[16], int rounds) { int r; - u32 s0, s1, s2, s3, t0, t1, t2, t3; + u32int s0, s1, s2, s3, t0, t1, t2, t3; /* * map byte array block to cipher state @@ -1585,25 +1584,25 @@ */ for (r = (rounds < Nr ? rounds : Nr) - 1; r > 0; r--) { t0 = - Td0[(s0 >> 24) ] ^ + Td0[(s0 >> 24) & 0xff] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[(s1 ) & 0xff] ^ rk[0]; t1 = - Td0[(s1 >> 24) ] ^ + Td0[(s1 >> 24) & 0xff] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[(s2 ) & 0xff] ^ rk[1]; t2 = - Td0[(s2 >> 24) ] ^ + Td0[(s2 >> 24) & 0xff] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[(s3 ) & 0xff] ^ rk[2]; t3 = - Td0[(s3 >> 24) ] ^ + Td0[(s3 >> 24) & 0xff] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[(s0 ) & 0xff] ^ @@ -1621,22 +1620,22 @@ * map cipher state to byte array block: */ t0 = - (Td4[(s0 >> 24) ] << 24) ^ + (Td4[(s0 >> 24) & 0xff] << 24) ^ (Td4[(s3 >> 16) & 0xff] << 16) ^ (Td4[(s2 >> 8) & 0xff] << 8) ^ (Td4[(s1 ) & 0xff] ); t1 = - (Td4[(s1 >> 24) ] << 24) ^ + (Td4[(s1 >> 24) & 0xff] << 24) ^ (Td4[(s0 >> 16) & 0xff] << 16) ^ (Td4[(s3 >> 8) & 0xff] << 8) ^ (Td4[(s2 ) & 0xff] ); t2 = - (Td4[(s2 >> 24) ] << 24) ^ + (Td4[(s2 >> 24) & 0xff] << 24) ^ (Td4[(s1 >> 16) & 0xff] << 16) ^ (Td4[(s0 >> 8) & 0xff] << 8) ^ (Td4[(s3 ) & 0xff] ); t3 = - (Td4[(s3 >> 24) ] << 24) ^ + (Td4[(s3 >> 24) & 0xff] << 24) ^ (Td4[(s2 >> 16) & 0xff] << 16) ^ (Td4[(s1 >> 8) & 0xff] << 8) ^ (Td4[(s0 ) & 0xff] ); -- Ori Bernstein