Re: remove /dev/sound*

2016-09-07 Thread Michael W. Bombardieri
Hi Alexandre,

Do you know if any applications in ports use /dev/sound as default audio device.
Maybe they are not smart enough to try /dev/audio if /dev/sound fails.

- Michael


On Thu, Sep 08, 2016 at 08:12:45AM +0200, Alexandre Ratchov wrote:
> As audio(4) manual says "In all respects /dev/audio and /dev/sound
> are identical".  Only one of them is needed and this diff is to
> remove /dev/sound.
> 
> OK?
> 
> Index: etc/MAKEDEV.common
> ===
> RCS file: /cvs/src/etc/MAKEDEV.common,v
> retrieving revision 1.91
> diff -u -p -u -p -r1.91 MAKEDEV.common
> --- etc/MAKEDEV.common4 Sep 2016 15:38:59 -   1.91
> +++ etc/MAKEDEV.common8 Sep 2016 05:48:20 -
> @@ -418,13 +418,11 @@ _mkdev(acpi, acpi*, {-M acpic major_acp
>  __devitem(pctr, pctr*, PC Performance Tuning Register access device)dnl
>  _mkdev(pctr, pctr, {-M pctr c major_pctr_c 0 644-})dnl
>  __devitem(au, audio*, Audio devices,audio)dnl
> -_mkdev(au, audio*, {-M sound$U   c major_au_c $U
> +_mkdev(au, audio*, {-M audio$U   c major_au_c $U
>   M mixer$U   c major_au_c Add($U, 16)
> - M audio$U   c major_au_c Add($U, 128)
>   M audioctl$Uc major_au_c Add($U, 192)
>   MKlist[${#MKlist[*]}]=";[ -e audio ] || ln -s audio$U audio"
>   MKlist[${#MKlist[*]}]=";[ -e mixer ] || ln -s mixer$U mixer"
> - MKlist[${#MKlist[*]}]=";[ -e sound ] || ln -s sound$U sound"
>   MKlist[${#MKlist[*]}]=";[ -e audioctl ] || ln -s audioctl$U 
> audioctl"-})dnl
>  __devitem(vi, video*, Video V4L2 devices,video)dnl
>  _mkdev(vi, video*, {-M video$U  c major_vi_c $U 600
> Index: share/man/man4/audio.4
> ===
> RCS file: /cvs/src/share/man/man4/audio.4,v
> retrieving revision 1.74
> diff -u -p -u -p -r1.74 audio.4
> --- share/man/man4/audio.48 Sep 2016 05:18:20 -   1.74
> +++ share/man/man4/audio.48 Sep 2016 05:48:20 -
> @@ -53,14 +53,11 @@ underlying hardware configuration suppor
>  .Pp
>  There are four device files available for audio operation:
>  .Pa /dev/audio ,
> -.Pa /dev/sound ,
>  .Pa /dev/audioctl ,
>  and
>  .Pa /dev/mixer .
>  .Pa /dev/audio
> -and
> -.Pa /dev/sound
> -are used for recording or playback of digital samples.
> +is used for recording or playback of digital samples.
>  .Pa /dev/mixer
>  is used to manipulate volume, recording source, or other audio mixer
>  functions.
> @@ -68,10 +65,10 @@ functions.
>  accepts the same
>  .Xr ioctl 2
>  operations as
> -.Pa /dev/sound ,
> +.Pa /dev/audio ,
>  but no other operations.
>  In contrast to
> -.Pa /dev/sound ,
> +.Pa /dev/audio ,
>  which has the exclusive open property,
>  .Pa /dev/audioctl
>  can be opened at any time and can be used to read the
> @@ -80,18 +77,11 @@ device variables while it is in use.
>  .Sh SAMPLING DEVICES
>  When
>  .Pa /dev/audio
> -or
> -.Pa /dev/sound
>  is opened, it attempts to maintain the previous audio sample format and
>  record/playback mode.
>  In addition, if it is opened read-only
>  (write-only) the device is set to half-duplex record (play) mode with
>  recording (playing) unpaused.
> -In all respects
> -.Pa /dev/audio
> -and
> -.Pa /dev/sound
> -are identical.
>  .Pp
>  Only one process may hold open a sampling device at a given time
>  (although file descriptors may be shared between processes once the
> @@ -514,7 +504,6 @@ string values.
>  .Bl -tag -width /dev/audioctl -compact
>  .It Pa /dev/audio
>  .It Pa /dev/audioctl
> -.It Pa /dev/sound
>  .It Pa /dev/mixer
>  .El
>  .Sh SEE ALSO
> 



Re: replace microtime with getmicrouptime in ip_mroute.c

2016-09-07 Thread Florian Obser
OK florian@

On Thu, Sep 08, 2016 at 11:54:01AM +1000, David Gwynne wrote:
> it uses the time to rate limit the sending of assertion messages.
> 
> there are two reasons for this change.
> 
> firstly, using uptime instead of wall time means the intervals will
> be measured against a a monotonic clock that isnt skewed by clock
> changes. it should therefore always be rate limited to 30 seconds,
> even if the clock jumps in the middle of that interval.
> 
> secondly, using the get variant of the api means it can use a cached clock 
> time at the expense of accuracy. accuracy between 30s intervals isnt 
> necessary in this use case, but making it use the faster clock read is good 
> cos this path is in response to packets, so it will mitigate a DoS.
> 
> ok?
> 
> after this i intend to tweak the code to use ratecheck().
> 
> Index: ip_mroute.c
> ===
> RCS file: /cvs/src/sys/netinet/ip_mroute.c,v
> retrieving revision 1.90
> diff -u -p -r1.90 ip_mroute.c
> --- ip_mroute.c   7 Mar 2016 18:44:00 -   1.90
> +++ ip_mroute.c   8 Sep 2016 01:49:05 -
> @@ -1482,7 +1482,7 @@ ip_mdq(struct mbuf *m, struct ifnet *ifp
>   return (0);
>   }
>  
> - microtime(&now);
> + getmicrouptime(&now);
>  
>   TV_DELTA(rt->mfc_last_assert, now, delta);
>  
> 

-- 
I'm not entirely sure you are real.



Re: random malloc junk

2016-09-07 Thread Otto Moerbeek
On Wed, Sep 07, 2016 at 06:29:07PM -0400, Ted Unangst wrote:

> Instead of always using a fixed byte pattern, I think malloc should use a
> random pattern. Now, this sometimes means it's harder to identify exactly
> what's used after free, so we should provide a means to get the old 0xdf
> pattern back.
> 
> Since we already have two junk modes, I thought I'd carry on along those
> lines. The default junk behavior, for free chunks only, is more of a security
> measure. I think this means we want random junk. The second level 'J' junk is
> more of a debugging tool, so that retains 0xdf.
> 
> There's some overlap here with canaries, but nothing wrong with that. :)

Like it, though I am a bit worried about the costs. Any measurements?

Should be able to look more closely the coming days.

BTW, we should revisit canaries and work further on moving them
closer to requested size. There's a chance this diff wil complicate
that.

-Otto

> 
> Index: malloc.c
> ===
> RCS file: /cvs/src/lib/libc/stdlib/malloc.c,v
> retrieving revision 1.195
> diff -u -p -r1.195 malloc.c
> --- malloc.c  1 Sep 2016 10:41:02 -   1.195
> +++ malloc.c  7 Sep 2016 22:21:37 -
> @@ -186,6 +186,7 @@ struct malloc_readonly {
>  #endif
>   u_int32_t malloc_canary;/* Matched against ones in malloc_pool 
> */
>   uintptr_t malloc_chunk_canary;
> + u_char  malloc_junkbytes[256];
>  };
>  
>  /* This object is mapped PROT_READ after initialisation to prevent tampering 
> */
> @@ -597,6 +598,8 @@ omalloc_init(void)
>   mopts.malloc_move = 1;
>   mopts.malloc_cache = MALLOC_DEFAULT_CACHE;
>  
> + arc4random_buf(mopts.malloc_junkbytes, sizeof(mopts.malloc_junkbytes));
> +
>   for (i = 0; i < 3; i++) {
>   switch (i) {
>   case 0:
> @@ -1260,7 +1263,29 @@ malloc(size_t size)
>  /*DEF_STRONG(malloc);*/
>  
>  static void
> -validate_junk(struct dir_info *pool, void *p) {
> +random_junk(void *p, size_t amt)
> +{
> + u_long offset = ((u_long)p) & (sizeof(mopts.malloc_junkbytes) - 1);
> +
> + if (amt < sizeof(mopts.malloc_junkbytes) - offset) {
> + memcpy(p, mopts.malloc_junkbytes + offset, amt);
> + } else {
> + memcpy(p, mopts.malloc_junkbytes + offset,
> + sizeof(mopts.malloc_junkbytes) - offset);
> + amt -= sizeof(mopts.malloc_junkbytes) - offset;
> + while (amt > 0) {
> + size_t x = amt > sizeof(mopts.malloc_junkbytes) ?
> + sizeof(mopts.malloc_junkbytes) : amt;
> + memcpy(p, mopts.malloc_junkbytes, x);
> + amt -= x;
> + }
> + }
> +}
> +
> +
> +static void
> +validate_junk(struct dir_info *pool, void *p)
> +{
>   struct region_info *r;
>   size_t byte, sz;
>  
> @@ -1274,9 +1299,15 @@ validate_junk(struct dir_info *pool, voi
>   sz -= mopts.malloc_canaries;
>   if (sz > 32)
>   sz = 32;
> - for (byte = 0; byte < sz; byte++) {
> - if (((unsigned char *)p)[byte] != SOME_FREEJUNK)
> + if (mopts.malloc_junk == 1) {
> + u_long offset = ((u_long)p) & (sizeof(mopts.malloc_junkbytes) - 
> 1);
> + if (memcmp(p, mopts.malloc_junkbytes + offset, sz) != 0)
>   wrterror(pool, "use after free", p);
> + } else {
> + for (byte = 0; byte < sz; byte++) {
> + if (((unsigned char *)p)[byte] != SOME_FREEJUNK)
> + wrterror(pool, "use after free", p);
> + }
>   }
>  }
>  
> @@ -1336,10 +1367,11 @@ ofree(struct dir_info *argpool, void *p)
>   }
>   STATS_SUB(pool->malloc_guarded, mopts.malloc_guard);
>   }
> - if (mopts.malloc_junk && !mopts.malloc_freeunmap) {
> - size_t amt = mopts.malloc_junk == 1 ? MALLOC_MAXCHUNK :
> - PAGEROUND(sz) - mopts.malloc_guard;
> - memset(p, SOME_FREEJUNK, amt);
> + if (mopts.malloc_junk == 2 && !mopts.malloc_freeunmap) {
> + memset(p, SOME_FREEJUNK,
> + PAGEROUND(sz) - mopts.malloc_guard);
> + } else if (mopts.malloc_junk == 1 && !mopts.malloc_freeunmap) {
> + random_junk(p, MALLOC_MAXCHUNK); 
>   }
>   unmap(pool, p, PAGEROUND(sz));
>   delete(pool, r);
> @@ -1347,8 +1379,10 @@ ofree(struct dir_info *argpool, void *p)
>   void *tmp;
>   int i;
>  
> - if (mopts.malloc_junk && sz > 0)
> + if (mopts.malloc_junk == 2 && sz > 0)
>   memset(p, SOME_FREEJUNK, sz - mopts.malloc_canaries);
> + else if (mopts.malloc_junk == 1 && sz > 0)
> + random_junk(p, sz);
>   if (!mopts.malloc_freenow) {
> 

remove /dev/sound*

2016-09-07 Thread Alexandre Ratchov
As audio(4) manual says "In all respects /dev/audio and /dev/sound
are identical".  Only one of them is needed and this diff is to
remove /dev/sound.

OK?

Index: etc/MAKEDEV.common
===
RCS file: /cvs/src/etc/MAKEDEV.common,v
retrieving revision 1.91
diff -u -p -u -p -r1.91 MAKEDEV.common
--- etc/MAKEDEV.common  4 Sep 2016 15:38:59 -   1.91
+++ etc/MAKEDEV.common  8 Sep 2016 05:48:20 -
@@ -418,13 +418,11 @@ _mkdev(acpi, acpi*, {-M acpi  c major_acp
 __devitem(pctr, pctr*, PC Performance Tuning Register access device)dnl
 _mkdev(pctr, pctr, {-M pctr c major_pctr_c 0 644-})dnl
 __devitem(au, audio*, Audio devices,audio)dnl
-_mkdev(au, audio*, {-M sound$U c major_au_c $U
+_mkdev(au, audio*, {-M audio$U c major_au_c $U
M mixer$U   c major_au_c Add($U, 16)
-   M audio$U   c major_au_c Add($U, 128)
M audioctl$Uc major_au_c Add($U, 192)
MKlist[${#MKlist[*]}]=";[ -e audio ] || ln -s audio$U audio"
MKlist[${#MKlist[*]}]=";[ -e mixer ] || ln -s mixer$U mixer"
-   MKlist[${#MKlist[*]}]=";[ -e sound ] || ln -s sound$U sound"
MKlist[${#MKlist[*]}]=";[ -e audioctl ] || ln -s audioctl$U 
audioctl"-})dnl
 __devitem(vi, video*, Video V4L2 devices,video)dnl
 _mkdev(vi, video*, {-M video$U  c major_vi_c $U 600
Index: share/man/man4/audio.4
===
RCS file: /cvs/src/share/man/man4/audio.4,v
retrieving revision 1.74
diff -u -p -u -p -r1.74 audio.4
--- share/man/man4/audio.4  8 Sep 2016 05:18:20 -   1.74
+++ share/man/man4/audio.4  8 Sep 2016 05:48:20 -
@@ -53,14 +53,11 @@ underlying hardware configuration suppor
 .Pp
 There are four device files available for audio operation:
 .Pa /dev/audio ,
-.Pa /dev/sound ,
 .Pa /dev/audioctl ,
 and
 .Pa /dev/mixer .
 .Pa /dev/audio
-and
-.Pa /dev/sound
-are used for recording or playback of digital samples.
+is used for recording or playback of digital samples.
 .Pa /dev/mixer
 is used to manipulate volume, recording source, or other audio mixer
 functions.
@@ -68,10 +65,10 @@ functions.
 accepts the same
 .Xr ioctl 2
 operations as
-.Pa /dev/sound ,
+.Pa /dev/audio ,
 but no other operations.
 In contrast to
-.Pa /dev/sound ,
+.Pa /dev/audio ,
 which has the exclusive open property,
 .Pa /dev/audioctl
 can be opened at any time and can be used to read the
@@ -80,18 +77,11 @@ device variables while it is in use.
 .Sh SAMPLING DEVICES
 When
 .Pa /dev/audio
-or
-.Pa /dev/sound
 is opened, it attempts to maintain the previous audio sample format and
 record/playback mode.
 In addition, if it is opened read-only
 (write-only) the device is set to half-duplex record (play) mode with
 recording (playing) unpaused.
-In all respects
-.Pa /dev/audio
-and
-.Pa /dev/sound
-are identical.
 .Pp
 Only one process may hold open a sampling device at a given time
 (although file descriptors may be shared between processes once the
@@ -514,7 +504,6 @@ string values.
 .Bl -tag -width /dev/audioctl -compact
 .It Pa /dev/audio
 .It Pa /dev/audioctl
-.It Pa /dev/sound
 .It Pa /dev/mixer
 .El
 .Sh SEE ALSO



Re: replace microtime with getmicrouptime in ip_mroute.c

2016-09-07 Thread Claudio Jeker
On Thu, Sep 08, 2016 at 11:54:01AM +1000, David Gwynne wrote:
> it uses the time to rate limit the sending of assertion messages.
> 
> there are two reasons for this change.
> 
> firstly, using uptime instead of wall time means the intervals will
> be measured against a a monotonic clock that isnt skewed by clock
> changes. it should therefore always be rate limited to 30 seconds,
> even if the clock jumps in the middle of that interval.
> 
> secondly, using the get variant of the api means it can use a cached clock 
> time at the expense of accuracy. accuracy between 30s intervals isnt 
> necessary in this use case, but making it use the faster clock read is good 
> cos this path is in response to packets, so it will mitigate a DoS.
> 
> ok?

OK claudio@
 
> after this i intend to tweak the code to use ratecheck().
> 
> Index: ip_mroute.c
> ===
> RCS file: /cvs/src/sys/netinet/ip_mroute.c,v
> retrieving revision 1.90
> diff -u -p -r1.90 ip_mroute.c
> --- ip_mroute.c   7 Mar 2016 18:44:00 -   1.90
> +++ ip_mroute.c   8 Sep 2016 01:49:05 -
> @@ -1482,7 +1482,7 @@ ip_mdq(struct mbuf *m, struct ifnet *ifp
>   return (0);
>   }
>  
> - microtime(&now);
> + getmicrouptime(&now);
>  
>   TV_DELTA(rt->mfc_last_assert, now, delta);
>  
> 

-- 
:wq Claudio



Re: [patch] Some consistence

2016-09-07 Thread Jason McIntyre
On Wed, Sep 07, 2016 at 10:56:19PM -0300, Daniel Bolgheroni wrote:
> Some consistence.
> 

fixed, thanks.
jmc

> Index: ls.1
> ===
> RCS file: /cvs/src/bin/ls/ls.1,v
> retrieving revision 1.77
> diff -u -p -r1.77 ls.1
> --- ls.110 Aug 2016 19:46:43 -  1.77
> +++ ls.18 Sep 2016 01:44:18 -
> @@ -370,7 +370,7 @@ and set-group-ID mode is set.
>  If in the owner permissions, the file is executable
>  and set-user-ID mode is set.
>  If in the group permissions, the file is executable
> -and setgroup-ID mode is set.
> +and set-group-ID mode is set.
>  .It Sy x
>  The file is executable or the directory is
>  searchable.
> 
> -- 
> db
> 



[patch] Some consistence

2016-09-07 Thread Daniel Bolgheroni
Some consistence.

Index: ls.1
===
RCS file: /cvs/src/bin/ls/ls.1,v
retrieving revision 1.77
diff -u -p -r1.77 ls.1
--- ls.110 Aug 2016 19:46:43 -  1.77
+++ ls.18 Sep 2016 01:44:18 -
@@ -370,7 +370,7 @@ and set-group-ID mode is set.
 If in the owner permissions, the file is executable
 and set-user-ID mode is set.
 If in the group permissions, the file is executable
-and setgroup-ID mode is set.
+and set-group-ID mode is set.
 .It Sy x
 The file is executable or the directory is
 searchable.

-- 
db



replace microtime with getmicrouptime in ip_mroute.c

2016-09-07 Thread David Gwynne
it uses the time to rate limit the sending of assertion messages.

there are two reasons for this change.

firstly, using uptime instead of wall time means the intervals will
be measured against a a monotonic clock that isnt skewed by clock
changes. it should therefore always be rate limited to 30 seconds,
even if the clock jumps in the middle of that interval.

secondly, using the get variant of the api means it can use a cached clock time 
at the expense of accuracy. accuracy between 30s intervals isnt necessary in 
this use case, but making it use the faster clock read is good cos this path is 
in response to packets, so it will mitigate a DoS.

ok?

after this i intend to tweak the code to use ratecheck().

Index: ip_mroute.c
===
RCS file: /cvs/src/sys/netinet/ip_mroute.c,v
retrieving revision 1.90
diff -u -p -r1.90 ip_mroute.c
--- ip_mroute.c 7 Mar 2016 18:44:00 -   1.90
+++ ip_mroute.c 8 Sep 2016 01:49:05 -
@@ -1482,7 +1482,7 @@ ip_mdq(struct mbuf *m, struct ifnet *ifp
return (0);
}
 
-   microtime(&now);
+   getmicrouptime(&now);
 
TV_DELTA(rt->mfc_last_assert, now, delta);
 



random malloc junk

2016-09-07 Thread Ted Unangst
Instead of always using a fixed byte pattern, I think malloc should use a
random pattern. Now, this sometimes means it's harder to identify exactly
what's used after free, so we should provide a means to get the old 0xdf
pattern back.

Since we already have two junk modes, I thought I'd carry on along those
lines. The default junk behavior, for free chunks only, is more of a security
measure. I think this means we want random junk. The second level 'J' junk is
more of a debugging tool, so that retains 0xdf.

There's some overlap here with canaries, but nothing wrong with that. :)

Index: malloc.c
===
RCS file: /cvs/src/lib/libc/stdlib/malloc.c,v
retrieving revision 1.195
diff -u -p -r1.195 malloc.c
--- malloc.c1 Sep 2016 10:41:02 -   1.195
+++ malloc.c7 Sep 2016 22:21:37 -
@@ -186,6 +186,7 @@ struct malloc_readonly {
 #endif
u_int32_t malloc_canary;/* Matched against ones in malloc_pool 
*/
uintptr_t malloc_chunk_canary;
+   u_char  malloc_junkbytes[256];
 };
 
 /* This object is mapped PROT_READ after initialisation to prevent tampering */
@@ -597,6 +598,8 @@ omalloc_init(void)
mopts.malloc_move = 1;
mopts.malloc_cache = MALLOC_DEFAULT_CACHE;
 
+   arc4random_buf(mopts.malloc_junkbytes, sizeof(mopts.malloc_junkbytes));
+
for (i = 0; i < 3; i++) {
switch (i) {
case 0:
@@ -1260,7 +1263,29 @@ malloc(size_t size)
 /*DEF_STRONG(malloc);*/
 
 static void
-validate_junk(struct dir_info *pool, void *p) {
+random_junk(void *p, size_t amt)
+{
+   u_long offset = ((u_long)p) & (sizeof(mopts.malloc_junkbytes) - 1);
+
+   if (amt < sizeof(mopts.malloc_junkbytes) - offset) {
+   memcpy(p, mopts.malloc_junkbytes + offset, amt);
+   } else {
+   memcpy(p, mopts.malloc_junkbytes + offset,
+   sizeof(mopts.malloc_junkbytes) - offset);
+   amt -= sizeof(mopts.malloc_junkbytes) - offset;
+   while (amt > 0) {
+   size_t x = amt > sizeof(mopts.malloc_junkbytes) ?
+   sizeof(mopts.malloc_junkbytes) : amt;
+   memcpy(p, mopts.malloc_junkbytes, x);
+   amt -= x;
+   }
+   }
+}
+
+
+static void
+validate_junk(struct dir_info *pool, void *p)
+{
struct region_info *r;
size_t byte, sz;
 
@@ -1274,9 +1299,15 @@ validate_junk(struct dir_info *pool, voi
sz -= mopts.malloc_canaries;
if (sz > 32)
sz = 32;
-   for (byte = 0; byte < sz; byte++) {
-   if (((unsigned char *)p)[byte] != SOME_FREEJUNK)
+   if (mopts.malloc_junk == 1) {
+   u_long offset = ((u_long)p) & (sizeof(mopts.malloc_junkbytes) - 
1);
+   if (memcmp(p, mopts.malloc_junkbytes + offset, sz) != 0)
wrterror(pool, "use after free", p);
+   } else {
+   for (byte = 0; byte < sz; byte++) {
+   if (((unsigned char *)p)[byte] != SOME_FREEJUNK)
+   wrterror(pool, "use after free", p);
+   }
}
 }
 
@@ -1336,10 +1367,11 @@ ofree(struct dir_info *argpool, void *p)
}
STATS_SUB(pool->malloc_guarded, mopts.malloc_guard);
}
-   if (mopts.malloc_junk && !mopts.malloc_freeunmap) {
-   size_t amt = mopts.malloc_junk == 1 ? MALLOC_MAXCHUNK :
-   PAGEROUND(sz) - mopts.malloc_guard;
-   memset(p, SOME_FREEJUNK, amt);
+   if (mopts.malloc_junk == 2 && !mopts.malloc_freeunmap) {
+   memset(p, SOME_FREEJUNK,
+   PAGEROUND(sz) - mopts.malloc_guard);
+   } else if (mopts.malloc_junk == 1 && !mopts.malloc_freeunmap) {
+   random_junk(p, MALLOC_MAXCHUNK); 
}
unmap(pool, p, PAGEROUND(sz));
delete(pool, r);
@@ -1347,8 +1379,10 @@ ofree(struct dir_info *argpool, void *p)
void *tmp;
int i;
 
-   if (mopts.malloc_junk && sz > 0)
+   if (mopts.malloc_junk == 2 && sz > 0)
memset(p, SOME_FREEJUNK, sz - mopts.malloc_canaries);
+   else if (mopts.malloc_junk == 1 && sz > 0)
+   random_junk(p, sz);
if (!mopts.malloc_freenow) {
if (find_chunknum(pool, r, p) == -1)
goto done;



Re: Default softraid crypto PBKDF2 rounds

2016-09-07 Thread Damien Miller
On Wed, 7 Sep 2016, Andreas Bartelt wrote:

> yes, due to the larger internal state of the blowfish algorithm which is
> harder to efficiently realize in dedicated hardware. However, since bcrypt's
> internal state effectively is of fixed size, scrypt would be an even better
> option since it allows for a parameterization of this internal state. Is there
> any interest in switching to scrypt in the context of password authentication
> on OpenBSD?

no, its advantages aren't sufficient for the disruption IMO.

We might consider whatever wins the shootout going on between balloon
hashing and Argon2, but bcrypt has survived so incredibly well that
we can afford to wait.



look(1): eliminate FOLD and DICT macros

2016-09-07 Thread Todd C. Miller
There's no need to check for isascii() with ANSI ctype macros/functions.
Eliminating the macros makes the code clearer.

 - todd

Index: usr.bin/look/look.c
===
RCS file: /cvs/src/usr.bin/look/look.c,v
retrieving revision 1.18
diff -u -p -u -r1.18 look.c
--- usr.bin/look/look.c 9 Oct 2015 01:37:08 -   1.18
+++ usr.bin/look/look.c 7 Sep 2016 21:44:53 -
@@ -57,20 +57,9 @@
 
 #include "pathnames.h"
 
-/*
- * FOLD and DICT convert characters to a normal form for comparison,
- * according to the user specified flags.
- * 
- * DICT expects integers because it uses a non-character value to
- * indicate a character which should not participate in comparisons.
- */
 #defineEQUAL   0
 #defineGREATER 1
 #defineLESS(-1)
-#define NO_COMPARE (-2)
-
-#defineFOLD(c) (isascii(c) && isupper(c) ? tolower(c) : (c))
-#defineDICT(c) (isascii(c) && isalnum(c) ? (c) : NO_COMPARE)
 
 int dflag, fflag;
 
@@ -147,10 +136,8 @@ look(char *string, char *front, char *ba
/* Reformat string to avoid doing it multiple times later. */
for (readp = writep = string; ch = *readp++;) {
if (fflag)
-   ch = FOLD((unsigned char)ch);
-   if (dflag)
-   ch = DICT((unsigned char)ch);
-   if (ch != NO_COMPARE)
+   ch = tolower((unsigned char)ch);
+   if (!dflag || isalnum((unsigned char)ch))
*(writep++) = ch;
}
*writep = '\0';
@@ -294,11 +281,8 @@ compare(char *s1, char *s2, char *back)
for (; *s1 && s2 < back && *s2 != '\n'; ++s1, ++s2) {
ch = *s2;
if (fflag)
-   ch = FOLD((unsigned char)ch);
-   if (dflag)
-   ch = DICT((unsigned char)ch);
-
-   if (ch == NO_COMPARE) {
+   ch = tolower((unsigned char)ch);
+   if (dflag && !isalnum((unsigned char)ch)) {
++s2;   /* Ignore character in comparison. */
continue;
}



netinet6 bcopy->memcpy

2016-09-07 Thread David Hill
Hello -

Here is a diff to switch some bcopy's to memcpy's.

Most bcopy's are on freshly alloc'd memory.

Index: ip6_output.c
===
RCS file: /cvs/src/sys/netinet6/ip6_output.c,v
retrieving revision 1.213
diff -u -p -r1.213 ip6_output.c
--- ip6_output.c25 Aug 2016 12:30:16 -  1.213
+++ ip6_output.c7 Sep 2016 21:10:41 -
@@ -969,7 +969,7 @@ ip6_insert_jumboopt(struct ip6_exthdrs *
optbuf[2] = IP6OPT_JUMBO;
optbuf[3] = 4;
v = (u_int32_t)htonl(plen + JUMBOOPTLEN);
-   bcopy(&v, &optbuf[4], sizeof(u_int32_t));
+   memcpy(&optbuf[4], &v, sizeof(u_int32_t));
 
/* finally, adjust the packet header length */
exthdrs->ip6e_ip6->m_pkthdr.len += JUMBOOPTLEN;
@@ -1906,11 +1906,11 @@ ip6_clearpktopts(struct ip6_pktopts *pkt
 #define PKTOPT_EXTHDRCPY(type) \
 do {\
if (src->type) {\
-   int hlen = (((struct ip6_ext *)src->type)->ip6e_len + 1) << 3;\
+   size_t hlen = (((struct ip6_ext *)src->type)->ip6e_len + 1) << 
3;\
dst->type = malloc(hlen, M_IP6OPT, canwait);\
if (dst->type == NULL && canwait == M_NOWAIT)\
goto bad;\
-   bcopy(src->type, dst->type, hlen);\
+   memcpy(dst->type, src->type, hlen);\
}\
 } while (/*CONSTCOND*/ 0)
 
@@ -1993,7 +1993,7 @@ ip6_setmoptions(int optname, struct ip6_
error = EINVAL;
break;
}
-   bcopy(mtod(m, u_int *), &ifindex, sizeof(ifindex));
+   memcpy(&ifindex, mtod(m, u_int *), sizeof(ifindex));
if (ifindex != 0) {
ifp = if_get(ifindex);
if (ifp == NULL) {
@@ -2020,7 +2020,7 @@ ip6_setmoptions(int optname, struct ip6_
error = EINVAL;
break;
}
-   bcopy(mtod(m, u_int *), &optval, sizeof(optval));
+   memcpy(&optval, mtod(m, u_int *), sizeof(optval));
if (optval < -1 || optval >= 256)
error = EINVAL;
else if (optval == -1)
@@ -2039,7 +2039,7 @@ ip6_setmoptions(int optname, struct ip6_
error = EINVAL;
break;
}
-   bcopy(mtod(m, u_int *), &loop, sizeof(loop));
+   memcpy(&loop, mtod(m, u_int *), sizeof(loop));
if (loop > 1) {
error = EINVAL;
break;
@@ -2522,7 +2522,7 @@ ip6_setpktopt(int optname, u_char *buf, 
opt->ip6po_hbh = malloc(hbhlen, M_IP6OPT, M_NOWAIT);
if (opt->ip6po_hbh == NULL)
return (ENOBUFS);
-   bcopy(hbh, opt->ip6po_hbh, hbhlen);
+   memcpy(opt->ip6po_hbh, hbh, hbhlen);
 
break;
}
@@ -2566,7 +2566,7 @@ ip6_setpktopt(int optname, u_char *buf, 
*newdest = malloc(destlen, M_IP6OPT, M_NOWAIT);
if (*newdest == NULL)
return (ENOBUFS);
-   bcopy(dest, *newdest, destlen);
+   memcpy(*newdest, dest, destlen);
 
break;
}
@@ -2606,7 +2606,7 @@ ip6_setpktopt(int optname, u_char *buf, 
opt->ip6po_rthdr = malloc(rthlen, M_IP6OPT, M_NOWAIT);
if (opt->ip6po_rthdr == NULL)
return (ENOBUFS);
-   bcopy(rth, opt->ip6po_rthdr, rthlen);
+   memcpy(opt->ip6po_rthdr, rth, rthlen);
break;
}
 
Index: raw_ip6.c
===
RCS file: /cvs/src/sys/netinet6/raw_ip6.c,v
retrieving revision 1.95
diff -u -p -r1.95 raw_ip6.c
--- raw_ip6.c   22 Aug 2016 10:33:22 -  1.95
+++ raw_ip6.c   7 Sep 2016 21:10:41 -
@@ -735,7 +735,7 @@ rip6_usrreq(struct socket *so, int req, 
bzero(&tmp, sizeof(tmp));
tmp.sin6_family = AF_INET6;
tmp.sin6_len = sizeof(struct sockaddr_in6);
-   bcopy(&in6p->inp_faddr6, &tmp.sin6_addr,
+   memcpy(&tmp.sin6_addr, &in6p->inp_faddr6,
sizeof(struct in6_addr));
dst = &tmp;
} else {



remove unreachable code from all audio drivers

2016-09-07 Thread Alexandre Ratchov
This diff deletes unreachable code in low-level audio drivers.  As
this touches all archs, tests (a quick kernel build is enough) are
welcome on anything but amd64 and i386.

OK?

Index: share/man/man9/audio.9
===
RCS file: /cvs/src/share/man/man9/audio.9,v
retrieving revision 1.24
diff -u -p -r1.24 audio.9
--- share/man/man9/audio.9  1 Sep 2016 10:14:08 -   1.24
+++ share/man/man9/audio.9  7 Sep 2016 14:01:04 -
@@ -45,9 +45,6 @@ structure.
 struct audio_hw_if {
int (*open)(void *, int);
void(*close)(void *);
-   int (*drain)(void *);
-
-   int (*query_encoding)(void *, struct audio_encoding *);
int (*set_params)(void *, int, int,
struct audio_params *, struct audio_params *);
int (*round_blocksize)(void *, int);
@@ -78,15 +75,12 @@ struct audio_hw_if {
void*(*allocm)(void *, int, size_t, int, int);
void(*freem)(void *, void *, int);
size_t  (*round_buffersize)(void *, int, size_t);
-   paddr_t (*mappage)(void *, void *, off_t, int);
-
int (*get_props)(void *);
 
int (*trigger_output)(void *, void *, void *, int,
void (*)(void *), void *, struct audio_params *);
int (*trigger_input)(void *, void *, void *, int,
void (*)(void *), void *, struct audio_params *);
-   void(*get_default_params)(void *, int, struct audio_params *);
 };
 
 struct audio_params {
@@ -160,22 +154,6 @@ is matched by a call to
 This function returns 0 on success, otherwise an error code.
 .It Fn "void (*close)" "void *hdl"
 This function is called when the audio device is closed.
-.It Fn "int (*drain)" "void *hdl"
-This function is optional.
-If supplied, it is called before the device is closed or when the
-.Dv AUDIO_DRAIN
-.Xr ioctl 2
-is called.
-It makes sure that no samples remain to be played that could
-be lost when
-.Fn close
-is called.
-This function returns 0 on success, otherwise an error code.
-.It Fn "int (*query_encoding)" "void *hdl" "struct audio_encoding *ae"
-This function fills
-.Fa ae
-and returns 0 or, if there is no encoding with the given number, returns
-.Er EINVAL .
 .It Fn "int (*set_params)" "void *hdl" "int setmode" "int usemode" \
 "struct audio_params *play" "struct audio_params *rec"
 This function is called to set the audio encoding mode.
@@ -375,18 +353,6 @@ Note that the buffer size is always a mu
 and
 .Fn round_buffersize
 must be consistent.
-.It Fn "paddr_t (*mappage)" "void *hdl" "void *addr" "off_t offs" "int prot"
-This function is optional.
-If supplied, it is called for
-.Xr mmap 2 .
-It returns the map value for the page at offset
-.Fa offs
-from address
-.Fa addr
-mapped with protection
-.Fa prot .
-This function returns \-1 on failure, or a machine dependent opaque
-value on success.
 .It Fn "int (*get_props)" "void *hdl"
 This function returns a combination of
 .Dv AUDIO_PROP_xxx
@@ -435,21 +401,6 @@ will be called with the argument
 Once started, the transfer may be stopped using
 .Fn halt_input .
 This function returns 0 on success, otherwise an error code.
-.It Fn "void (*get_default_params)" "void *hdl" "int direction" \
-"struct audio_params *param"
-This function is optional.
-If supplied, it is called to retrieve the default configuration
-for the given
-.Fa direction ,
-parameterized in
-.Fa param .
-.Fa direction
-is
-.Dv AUMODE_PLAY
-or
-.Dv AUMODE_RECORD .
-The default configuration should not include emulated formats, and should
-reflect the optimal operating configuration for the underlying hardware.
 .El
 .Pp
 If the audio hardware is capable of input from more
@@ -497,7 +448,6 @@ and be of class
 .Dv AudioCoutputs .
 .Sh SEE ALSO
 .Xr ioctl 2 ,
-.Xr mmap 2 ,
 .Xr open 2 ,
 .Xr sio_open 3 ,
 .Xr audio 4 ,
Index: sys/arch/hppa/gsc/harmony.c
===
RCS file: /cvs/src/sys/arch/hppa/gsc/harmony.c,v
retrieving revision 1.31
diff -u -p -r1.31 harmony.c
--- sys/arch/hppa/gsc/harmony.c 8 Sep 2015 07:14:04 -   1.31
+++ sys/arch/hppa/gsc/harmony.c 7 Sep 2016 14:01:05 -
@@ -56,7 +56,6 @@
 
 int harmony_open(void *, int);
 voidharmony_close(void *);
-int harmony_query_encoding(void *, struct audio_encoding *);
 int harmony_set_params(void *, int, int, struct audio_params *,
 struct audio_params *);
 int harmony_round_blocksize(void *, int);
@@ -79,8 +78,6 @@ int harmony_trigger_input(void *, vo
 struct audio_hw_if harmony_sa_hw_if = {
harmony_open,
harmony_close,
-   NULL,
-   harmony_query_encoding,
harmony_set_params,
harmony_round_blocksize,
harmony_commit_settings,
@@ -99,11 +96,9 @@ struct audio_hw_if harmony_sa_hw_if = {
harmony_allocm,
harmony_freem,
harmony_round_buffersize,
-   NULL,
harmony_get_props,
ha

static pie for arm

2016-09-07 Thread Mark Kettenis
Diff below makes static pie work on arm.  While reviewing the
MD_CRT0_START assembly I noticed that we don't actually need to save
r4 and r5 on the stack as those arguments are unused.  I also removed
the useless comment around the stack alignment code.

I'll probably hold off on the bsd.own.mk bit for a bit to give people
the opportunity to install a proper rcrt0.o file.

ok?


Index: libexec/ld.so/arm/archdep.h
===
RCS file: /cvs/src/libexec/ld.so/arm/archdep.h,v
retrieving revision 1.7
diff -u -p -r1.7 archdep.h
--- libexec/ld.so/arm/archdep.h 18 May 2016 20:40:20 -  1.7
+++ libexec/ld.so/arm/archdep.h 7 Sep 2016 20:22:20 -
@@ -60,6 +60,10 @@ RELOC_DYN(Elf_Rel *r, const Elf_Sym *s, 
 {
if (ELF_R_TYPE(r->r_info) == R_ARM_RELATIVE) {
*p += v;
+   } else if (ELF_R_TYPE(r->r_info) == R_ARM_GLOB_DAT) {
+   *p += v + s->st_value;
+   } else if (ELF_R_TYPE(r->r_info) == R_ARM_ABS32) {
+   *p += v + s->st_value;
} else {
/* XXX - printf might not work here, but we give it a shot. */
_dl_printf("Unknown bootstrap relocation.\n");
Index: lib/csu/arm/md_init.h
===
RCS file: /cvs/src/lib/csu/arm/md_init.h,v
retrieving revision 1.7
diff -u -p -r1.7 md_init.h
--- lib/csu/arm/md_init.h   24 Mar 2016 05:27:19 -  1.7
+++ lib/csu/arm/md_init.h   7 Sep 2016 20:22:20 -
@@ -87,21 +87,70 @@
"__start:   \n" \
"   mov r3, r0  /* cleanup */   \n" \
"/* Get argc/argv/envp from stack */\n" \
-   "   ldr r0, [sp, #0x]   \n" \
-   "   add r1, sp, #0x0004 \n" \
+   "   ldr r0, [sp, #0]\n" \
+   "   add r1, sp, #4  \n" \
"   add r2, r1, r0, lsl #2  \n" \
-   "   add r2, r2, #0x0004 \n" \
+   "   add r2, r2, #4  \n" \
"   \n" \
"/* \n" \
" * Ensure the stack is properly\n" \
" * aligned before calling C code.  \n" \
" */\n" \
-   /* #if 1 */ \
"   bic sp, sp, #7" /*__STRING(STACKALIGNBYTES)*/ " \n" \
-   /* #endif */\
"   sub sp, sp, #8  \n" \
-   "   str r5, [sp, #4]\n" \
-   "   str r4, [sp, #0]\n" \
"   \n" \
"   b   ___start\n" \
+   ".previous");
+
+#defineMD_RCRT0_START  \
+   char **environ, *__progname;\
+   __asm(  \
+   ".text  \n" \
+   "   .align  0   \n" \
+   "   .globl  _start  \n" \
+   "   .globl  __start \n" \
+   "_start:\n" \
+   "__start:   \n" \
+   "   mov fp, sp  \n" \
+   "   mov r0, fp  \n" \
+   "   \n" \
+   "   sub sp, sp, #4+4+(16*4) \n" \
+   "   add r1, sp, #4  \n" \
+   "   \n" \
+   "   ldr r8, .L_GOT  \n" \
+   "1: add r8, pc, r8  \n" \
+   "   ldr r2, .L__DYNAMIC \n" \
+   "   add r2, r2, r8  \n" \
+   "   \n" \
+   "   bl  _dl_boot_bind   \n" \
+   "   \n" \
+   "   mov sp, fp  \n" \
+   "   mov fp, #0  \n" \
+   "   \n" \
+   "   mov r3, #0  /* cleanup */   \n" \
+   "/* Get argc/argv/envp from stack */\n" \
+   "   ldr r0, [sp, #0]\n" \
+   "   add r1, sp, #4  \n" \
+   "   add r2, r1, r0, lsl #2  \n" \
+   "   add r2, r2, #4  \n" \
+   "   \n" \
+   "/* \n" \
+   " * Ensure the stack is properly\n" \
+   " * aligned before calling C code.  \n" \
+   " */\n" \
+   "   bic sp, sp, #7" /*__STRING(STACKALIGNBYTES)*/ " \n" \
+   "   sub sp, sp, #8  \n" \
+   "   \n" \
+   "   b   ___start  

config(8): strlen + emalloc + snprintf = asprintf

2016-09-07 Thread Michal Mazurek
ok?

Index: usr.sbin/config/main.c
===
RCS file: /cvs/src/usr.sbin/config/main.c,v
retrieving revision 1.50
diff -u -p -r1.50 main.c
--- usr.sbin/config/main.c  16 Oct 2015 13:37:44 -  1.50
+++ usr.sbin/config/main.c  7 Sep 2016 18:51:09 -
@@ -226,15 +226,13 @@ main(int argc, char *argv[])
last_component = strrchr(conffile, '/');
last_component = (last_component) ? last_component + 1 : conffile;
if (pflag) {
-   int len = strlen(last_component) + 17;
-   p = emalloc(len);
-   (void)snprintf(p, len, "../compile/%s.PROF", last_component);
+   if (asprintf(&p, "../compile/%s.PROF", last_component) == -1)
+   err(1, NULL);
(void)addmkoption(intern("PROF"), "-pg");
(void)addoption(intern("GPROF"), NULL);
} else {
-   int len = strlen(last_component) + 12;
-   p = emalloc(len);
-   (void)snprintf(p, len, "../compile/%s", last_component);
+   if (asprintf(&p, "../compile/%s", last_component) == -1)
+   err(1, NULL);
}
defbuilddir = (argc == 0) ? "." : p;
 
-- 
Michal Mazurek



Re: mount(8): remove unneeded headers

2016-09-07 Thread Ted Unangst
Michal Mazurek wrote:
> ok?
> 
> Index: sbin/mount/getmntopts.c
> ===
> RCS file: /cvs/src/sbin/mount/getmntopts.c,v
> retrieving revision 1.12
> diff -u -p -r1.12 getmntopts.c
> --- sbin/mount/getmntopts.c   16 Jan 2015 06:39:59 -  1.12
> +++ sbin/mount/getmntopts.c   7 Sep 2016 17:29:37 -
> @@ -31,11 +31,9 @@
>   */
>  
>  #include 
> -#include 

I think this is too far. mntopts.h definitely uses defines from here, it
should be considered a prerequisite even if this file doesn't use them
at present. Otherwise looks ok.



Re: Fix Wacom Intuos S 2 descriptor and make wsmouse work

2016-09-07 Thread Frank Groeneveld
On Wed, Sep 07, 2016 at 12:12:43AM +0200, Ulf Brosziewski wrote:
> Hi, I was a bit hasty, I should have mentioned that calling
> wsmouse_input_sync is required here. The equivalent of your
> code would would be this:
> 
> if (x != 0 || y != 0 || buttons != ms->sc_buttons) {
>   wsmouse_position(ms->sc_wsmousedev, x, y);
>   /* ignore proximity, it will cause invalid button 2 events */
>   if ((data[0] & 0xf0) != 0xc0)
>   wsmouse_buttons(ms->sc_wsmousedev, buttons);
>   wsmouse_input_sync();
> }
> 
> The WSMOUSE_INPUT macro - a substitute for the old wsmouse_input
> function - does include that call (see wsmousevar.h).
> 
> There is a set of functions for reporting input states:
> wsmouse_buttons, wsmouse_motion, wsmouse_position, wsmouse_touch,
> and wsmouse_mtstate (and the somewhat special wsmouse_set and
> wsmouse_mtframe). A driver can call them in any order, and it
> doesn't need to check whether there are deltas, wsmouse does
> this anyway. However, a frame must be finished by a call to
> wsmouse_input_sync. It is this function that generates the
> wscons events.
> 
> The new interface has been introduced in 6.0.
> 

That explains, thanks you very much for the detailed reply. My sources
were less than a week old, so it will probably just work with the sync
call.

I'll probably send an updated diff when I've fixed the scaling issue.

Frank



mount(8): remove unneeded headers

2016-09-07 Thread Michal Mazurek
ok?

Index: sbin/mount/getmntopts.c
===
RCS file: /cvs/src/sbin/mount/getmntopts.c,v
retrieving revision 1.12
diff -u -p -r1.12 getmntopts.c
--- sbin/mount/getmntopts.c 16 Jan 2015 06:39:59 -  1.12
+++ sbin/mount/getmntopts.c 7 Sep 2016 17:29:37 -
@@ -31,11 +31,9 @@
  */
 
 #include 
-#include 
 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
Index: sbin/mount/mount.c
===
RCS file: /cvs/src/sbin/mount/mount.c,v
retrieving revision 1.67
diff -u -p -r1.67 mount.c
--- sbin/mount/mount.c  4 Sep 2016 19:45:27 -   1.67
+++ sbin/mount/mount.c  7 Sep 2016 17:29:37 -
@@ -35,7 +35,6 @@
 #include 
 #include 
 
-#include 
 #include 
 #include 
 
@@ -48,7 +47,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include "pathnames.h"

-- 
Michal Mazurek



ping(8): fix multicast source address selection

2016-09-07 Thread Florian Obser
This got broken in rev 1.136 9 months ago. Sorry about that.

Tests / OKs?

p.s. applying + diff -bu is easier to figure out what's going on.

diff --git ping.c ping.c
index 9c2395a..b879d6f 100644
--- ping.c
+++ ping.c
@@ -121,7 +121,6 @@ int options;
 int moptions;
 #defineMULTICAST_NOLOOP0x001
 #defineMULTICAST_TTL   0x002
-#defineMULTICAST_IF0x004
 
 /*
  * MAX_DUP_CHK is the number of bits in received table, i.e. the maximum
@@ -395,24 +394,25 @@ main(int argc, char *argv[])
freeaddrinfo(res);
 
if (source) {
-   if (IN_MULTICAST(ntohl(dst.sin_addr.s_addr)))
-   moptions |= MULTICAST_IF;
-   else {
-   memset(&from4, 0, sizeof(from4));
-   from4.sin_family = AF_INET;
-   if (inet_aton(source, &from4.sin_addr) == 0) {
-   memset(&hints, 0, sizeof(hints));
-   hints.ai_family = AF_INET;
-   hints.ai_socktype = SOCK_DGRAM; /*dummy*/
-   if ((error = getaddrinfo(source, NULL, &hints,
-   &res)))
-   errx(1, "%s: %s", source,
-   gai_strerror(error));
-   if (res->ai_addrlen != sizeof(from4))
-   errx(1, "size of sockaddr mismatch");
-   memcpy(&from4, res->ai_addr, res->ai_addrlen);
-   freeaddrinfo(res);
-   }
+   memset(&from4, 0, sizeof(from4));
+   from4.sin_family = AF_INET;
+   if (inet_aton(source, &from4.sin_addr) == 0) {
+   memset(&hints, 0, sizeof(hints));
+   hints.ai_family = AF_INET;
+   hints.ai_socktype = SOCK_DGRAM; /*dummy*/
+   if ((error = getaddrinfo(source, NULL, &hints, &res)))
+   errx(1, "%s: %s", source, gai_strerror(error));
+   if (res->ai_addrlen != sizeof(from4))
+   errx(1, "size of sockaddr mismatch");
+   memcpy(&from4, res->ai_addr, res->ai_addrlen);
+   freeaddrinfo(res);
+   }
+
+   if (IN_MULTICAST(ntohl(dst.sin_addr.s_addr))) {
+   if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF,
+   &from4.sin_addr, sizeof(from4.sin_addr)) < 0)
+   err(1, "setsockopt IP_MULTICAST_IF");
+   } else {
if (bind(s, (struct sockaddr *)&from4, sizeof(from4))
< 0)
err(1, "bind");
@@ -492,10 +492,6 @@ main(int argc, char *argv[])
setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl,
sizeof(ttl)) < 0)
err(1, "setsockopt IP_MULTICAST_TTL");
-   if ((moptions & MULTICAST_IF) &&
-   setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &from4.sin_addr,
-   sizeof(from4.sin_addr)) < 0)
-   err(1, "setsockopt IP_MULTICAST_IF");
 
/*
 * When trying to send large packets, you must increase the


-- 
I'm not entirely sure you are real.



Re: [PATCH] Callback-based interface to libtls

2016-09-07 Thread tobias

On 07.09.2016, at 10:45, Tobias Pape  wrote:

> Hi there
> 
> On 05.09.2016, at 15:50, bust...@gmail.com wrote:
> 
>> Hey, the typedef came in handy :) Ok bcook@
>> 
>> On Sep 5, 2016, at 11:52 AM, Bob Beck  wrote:
>> 
>>> I am in agreement in principle, but please coordinate with bcook@ and/or 
>>> jsing@ who were possibly doing
>>> some related adjustments. 
>>> 
>>> 
> 
> I have a minor adjustment: it should be able to instruct POLLIN/POLLOUT via 
> the callbacks.
> I added this, see the diff.

Aaand: a fix for the FLUSH BIO cntl, that happens at the end of SSL handshakes…

Best regards
-Tobias

diff --git src/lib/libtls/tls_bio_cb.c src/lib/libtls/tls_bio_cb.c
index c4220df..e52f43c 100644
--- src/lib/libtls/tls_bio_cb.c
+++ src/lib/libtls/tls_bio_cb.c
@@ -154,6 +154,7 @@ ctrl_cb(BIO *b, int cmd, long num, void *ptr)
b->shutdown = (int)num;
break;
case BIO_CTRL_DUP:
+   case BIO_CTRL_FLUSH:
break;
case BIO_CTRL_INFO:
case BIO_CTRL_GET:
@@ -169,14 +170,32 @@ static int
 tls_bio_write_cb(BIO *h, const char *buf, int num, void *cb_arg)
 {
struct tls *ctx = cb_arg;
-   return (ctx->write_cb)(ctx, buf, num, ctx->cb_arg);
+   BIO_clear_retry_flags(h);
+   int rv = (ctx->write_cb)(ctx, buf, num, ctx->cb_arg);
+   if (rv == TLS_WANT_POLLIN) {
+   BIO_set_retry_read(h);
+   rv = -1;
+   } else if (rv == TLS_WANT_POLLOUT) {
+   BIO_set_retry_write(h);
+   rv = -1;
+   }
+   return (rv);
 }
 
 static int
 tls_bio_read_cb(BIO *h, char *buf, int size, void *cb_arg)
 {
struct tls *ctx = cb_arg;
-   return (ctx->read_cb)(ctx, buf, size, ctx->cb_arg);
+   BIO_clear_retry_flags(h);
+   int rv = (ctx->read_cb)(ctx, buf, size, ctx->cb_arg);
+   if (rv == TLS_WANT_POLLIN) {
+   BIO_set_retry_read(h);
+   rv = -1;
+   } else if (rv == TLS_WANT_POLLOUT) {
+   BIO_set_retry_write(h);
+   rv = -1;
+   }
+   return (rv);
 }
 
 static BIO *



Re: mg: Collect forked off children from M-| command

2016-09-07 Thread Todd C. Miller
On Wed, 07 Sep 2016 12:05:22 -, Mark Lumsden wrote:

> Source Joachim Nilsson:
> 
> Collect forked off children from M-| command
> 
> Mg left zombies from commands executed when piping a region of text to
> an external command.  This patch makes sure to collect for the child
> before returning.
> 
> Looks ok to me. ok?

OK millert@.

 - todd



Re: Default softraid crypto PBKDF2 rounds

2016-09-07 Thread joshua stein
On Wed, 07 Sep 2016 at 11:18:57 +0200, Andreas Bartelt wrote:
> yes, due to the larger internal state of the blowfish algorithm which is
> harder to efficiently realize in dedicated hardware. However, since bcrypt's
> internal state effectively is of fixed size, scrypt would be an even better
> option since it allows for a parameterization of this internal state. Is
> there any interest in switching to scrypt in the context of password
> authentication on OpenBSD?

That would require changing our logo from a blowfish to a bobblehead
of Colin Percival.



Re: mg: Collect forked off children from M-| command

2016-09-07 Thread Sunil Nimmagadda
On Wed, Sep 07, 2016 at 12:05:22PM +, Mark Lumsden wrote:
> Source Joachim Nilsson:
> 
> Collect forked off children from M-| command
> 
> Mg left zombies from commands executed when piping a region of text to
> an external command.  This patch makes sure to collect for the child
> before returning.
> 
> Looks ok to me. ok?

Ok sunil@



mg: Collect forked off children from M-| command

2016-09-07 Thread Mark Lumsden
Source Joachim Nilsson:

Collect forked off children from M-| command

Mg left zombies from commands executed when piping a region of text to
an external command.  This patch makes sure to collect for the child
before returning.

Looks ok to me. ok?

Index: region.c
===
RCS file: /cvs/src/usr.bin/mg/region.c,v
retrieving revision 1.35
diff -u -p -u -p -r1.35 region.c
--- region.c19 Mar 2015 21:22:15 -  1.35
+++ region.c7 Sep 2016 11:58:55 -
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -515,8 +516,9 @@ int
 pipeio(const char* const path, char* const argv[], char* const text, int len,
 struct buffer *outbp)
 {
-   int s[2];
+   int s[2], ret;
char *err;
+   pid_t pid;
 
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, s) == -1) {
dobeep();
@@ -524,7 +526,7 @@ pipeio(const char* const path, char* con
return (FALSE);
}
 
-   switch(fork()) {
+   switch((pid = fork())) {
case -1:
dobeep();
ewprintf("Can't fork");
@@ -548,7 +550,10 @@ pipeio(const char* const path, char* con
default:
/* Parent process */
close(s[1]);
-   return (iomux(s[0], text, len, outbp));
+   ret = iomux(s[0], text, len, outbp);
+   waitpid(pid, NULL, 0); /* Collect child to prevent zombies */
+
+   return (ret);
}
return (FALSE);
 }



Re: Default softraid crypto PBKDF2 rounds

2016-09-07 Thread Andreas Bartelt

On 09/07/16 09:16, Damien Miller wrote:

On Tue, 6 Sep 2016, David Coppa wrote:


Il 6 settembre 2016 14:56:32 CEST, Filippo Valsorda  ha 
scritto:

Hello,

I recently had the occasion to dive into the softraid crypto code [1]
and was quite pleased with the cleanliness of it all. However, I found
surprising the default value of 8k PBKDF2 rounds.

I know it is easy to override and I should have RTFM, but I (naively,
I'll admit) assumed OpenBSD would pick very robust defaults, erring on
the conservative side. Is it maybe time to bump it up, or pick it based
on a quick machine benchmark?

If there's consensus I might also provide a patch for the live
benchmark
option.


yes, autodetection of a sensible value would be cool...


using bcrypt_kdf would be better :)




yes, due to the larger internal state of the blowfish algorithm which is 
harder to efficiently realize in dedicated hardware. However, since 
bcrypt's internal state effectively is of fixed size, scrypt would be an 
even better option since it allows for a parameterization of this 
internal state. Is there any interest in switching to scrypt in the 
context of password authentication on OpenBSD?




Re: [PATCH] Callback-based interface to libtls

2016-09-07 Thread Tobias Pape
Hi there

On 05.09.2016, at 15:50, bust...@gmail.com wrote:

> Hey, the typedef came in handy :) Ok bcook@
> 
> On Sep 5, 2016, at 11:52 AM, Bob Beck  wrote:
> 
>> I am in agreement in principle, but please coordinate with bcook@ and/or 
>> jsing@ who were possibly doing
>> some related adjustments. 
>> 
>> 

I have a minor adjustment: it should be able to instruct POLLIN/POLLOUT via the 
callbacks.
I added this, see the diff.

Best regards
-Tobias

diff --git src/lib/libtls/tls_bio_cb.c src/lib/libtls/tls_bio_cb.c
index c4220df..acc8a8a 100644
--- src/lib/libtls/tls_bio_cb.c
+++ src/lib/libtls/tls_bio_cb.c
@@ -169,14 +169,32 @@ static int
 tls_bio_write_cb(BIO *h, const char *buf, int num, void *cb_arg)
 {
struct tls *ctx = cb_arg;
-   return (ctx->write_cb)(ctx, buf, num, ctx->cb_arg);
+   BIO_clear_retry_flags(h);
+   int rv = (ctx->write_cb)(ctx, buf, num, ctx->cb_arg);
+   if (rv == TLS_WANT_POLLIN) {
+   BIO_set_retry_read(h);
+   rv = -1;
+   } else if (rv == TLS_WANT_POLLOUT) {
+   BIO_set_retry_write(h);
+   rv = -1;
+   }
+   return (rv);
 }
 
 static int
 tls_bio_read_cb(BIO *h, char *buf, int size, void *cb_arg)
 {
struct tls *ctx = cb_arg;
-   return (ctx->read_cb)(ctx, buf, size, ctx->cb_arg);
+   BIO_clear_retry_flags(h);
+   int rv = (ctx->read_cb)(ctx, buf, size, ctx->cb_arg);
+   if (rv == TLS_WANT_POLLIN) {
+   BIO_set_retry_read(h);
+   rv = -1;
+   } else if (rv == TLS_WANT_POLLOUT) {
+   BIO_set_retry_write(h);
+   rv = -1;
+   }
+   return (rv);
 }
 
 static BIO *



Re: mg - fix modeline segfault

2016-09-07 Thread Mark Lumsden
I think the question is how shold mg behave in a cornercase situation
where mg is running but cannot be used in any meaningful fashion (as a
text editor). In the case of mg being run with only two lines
available to it, what should it do?

1. do nothing, just show the bottom 1 or 2 lines (minibuffer
and/or modeline) and allow all other functions.

2."suspend" from taking input but output a message similar to "Display
unusable" until the lines available to mg increas to >2. (Although
perhaps the ability to save files/exit mg would also be available, in
case the screen cannot be increased!)

Personally, I would choose 1. Most simple I think. However, are there
any other opinions?

Mark



Re: [patch] make npppd do as the man page says

2016-09-07 Thread YASUOKA Masahiko
Sorry for long delay.

Using empty sting for hostname in PPTP is intentional.  So I will fix
the man page.  Thank you for your report.

On Tue, 8 Mar 2016 11:20:40 +
Joe Holden  wrote:
> Below is a patch that corrects pptp to set the pptp hostname as the
> system hostname, as per the man page and l2tp:
> 
> diff --git a/usr.sbin/npppd/pptp/pptp_ctrl.c
> b/usr.sbin/npppd/pptp/pptp_ctrl.c
> index 1dfdc03..722b2a0 100644
> --- a/usr.sbin/npppd/pptp/pptp_ctrl.c
> +++ b/usr.sbin/npppd/pptp/pptp_ctrl.c
> @@ -721,6 +721,7 @@ pptp_ctrl_send_SCCRP(pptp_ctrl *_this, int result,
> int error)
> struct pptp_scc *scc;
> char logbuf[512];
> const char *val;
> +   char hbuf[NI_MAXHOST + NI_MAXSERV + 16];
> 
> scc = bytebuffer_pointer(_this->send_buf);
> lpkt = bytebuffer_remaining(_this->send_buf);
> @@ -749,8 +750,10 @@ pptp_ctrl_send_SCCRP(pptp_ctrl *_this, int
> result, int error)
>  * 63 character */
> /* host name */
> 
> -   if ((val = PPTP_CTRL_CONF(_this)->hostname) == NULL)
> -   val = "";
> +   if ((val = PPTP_CTRL_CONF(_this)->hostname) == NULL) {
> +   gethostname(hbuf, sizeof(hbuf));
> +   val = hbuf;
> +   }
> strlcpy(scc->host_name, val, sizeof(scc->host_name));
> 
> /* vender name */
> 



Re: smtpd shutdown cleanup

2016-09-07 Thread Gilles Chehade
On Tue, Sep 06, 2016 at 11:31:04PM +0200, Eric Faurot wrote:
> Previously, all processes would shutdown on receiving SIGINT or SIGTERM.
> When going down, the parent process would kill all the other process and
> waitpid() them.
> 
> Now, only the parent process handles SIGTERM and SIGINT, other processes
> ignore them. Upon receiving one of these signals, the parent process all
> imsg sockets and waitpid() for the children.  It fatal()s if one of the
> imsg sockets is closed unexpectedly.
> 
> Other processes exit() "normally" when one of their imsg socket is closed
> (except for client connection on the control socket of course). That's how
> they are supposed to stop now.  When doing so, they log as "debug" instead
> of "info" because useless logs are useless.
> 
> This makes the shutdown sequence much saner.
> 

ok

> Index: ca.c
> ===
> RCS file: /cvs/src/usr.sbin/smtpd/ca.c,v
> retrieving revision 1.24
> diff -u -p -r1.24 ca.c
> --- ca.c  4 Sep 2016 16:10:31 -   1.24
> +++ ca.c  6 Sep 2016 19:33:45 -
> @@ -66,29 +66,14 @@ static uint64_trsae_reqid = 0;
>  static void
>  ca_shutdown(void)
>  {
> - log_info("info: ca agent exiting");
> + log_debug("debug: ca agent exiting");
>   _exit(0);
>  }
>  
> -static void
> -ca_sig_handler(int sig, short event, void *p)
> -{
> - switch (sig) {
> - case SIGINT:
> - case SIGTERM:
> - ca_shutdown();
> - break;
> - default:
> - fatalx("ca_sig_handler: unexpected signal");
> - }
> -}
> -
>  int
>  ca(void)
>  {
>   struct passwd   *pw;
> - struct event ev_sigint;
> - struct event ev_sigterm;
>  
>   purge_config(PURGE_LISTENERS|PURGE_TABLES|PURGE_RULES);
>  
> @@ -110,10 +95,8 @@ ca(void)
>   imsg_callback = ca_imsg;
>   event_init();
>  
> - signal_set(&ev_sigint, SIGINT, ca_sig_handler, NULL);
> - signal_set(&ev_sigterm, SIGTERM, ca_sig_handler, NULL);
> - signal_add(&ev_sigint, NULL);
> - signal_add(&ev_sigterm, NULL);
> + signal(SIGINT, SIG_IGN);
> + signal(SIGTERM, SIG_IGN);
>   signal(SIGPIPE, SIG_IGN);
>   signal(SIGHUP, SIG_IGN);
>  
> @@ -242,6 +225,9 @@ ca_imsg(struct mproc *p, struct imsg *im
>   int  ret = 0;
>   uint64_t id;
>   int  v;
> +
> + if (imsg == NULL)
> + ca_shutdown();
>  
>   if (p->proc == PROC_PARENT) {
>   switch (imsg->hdr.type) {
> Index: control.c
> ===
> RCS file: /cvs/src/usr.sbin/smtpd/control.c,v
> retrieving revision 1.116
> diff -u -p -r1.116 control.c
> --- control.c 4 Sep 2016 16:10:31 -   1.116
> +++ control.c 6 Sep 2016 19:33:45 -
> @@ -63,7 +63,6 @@ static void control_shutdown(void);
>  static void control_listen(void);
>  static void control_accept(int, short, void *);
>  static void control_close(struct ctl_conn *);
> -static void control_sig_handler(int, short, void *);
>  static void control_dispatch_ext(struct mproc *, struct imsg *);
>  static void control_digest_update(const char *, size_t, int);
>  static void control_broadcast_verbose(int, int);
> @@ -89,6 +88,12 @@ control_imsg(struct mproc *p, struct ims
>   const void  *data;
>   size_t   sz;
>  
> + if (imsg == NULL) {
> + if (p->proc != PROC_CLIENT)
> + control_shutdown();
> + return;
> + }
> +
>   if (p->proc == PROC_PONY) {
>   switch (imsg->hdr.type) {
>   case IMSG_CTL_SMTP_SESSION:
> @@ -186,19 +191,6 @@ control_imsg(struct mproc *p, struct ims
>   imsg_to_str(imsg->hdr.type));
>  }
>  
> -static void
> -control_sig_handler(int sig, short event, void *p)
> -{
> - switch (sig) {
> - case SIGINT:
> - case SIGTERM:
> - control_shutdown();
> - break;
> - default:
> - fatalx("control_sig_handler: unexpected signal");
> - }
> -}
> -
>  int
>  control_create_socket(void)
>  {
> @@ -245,8 +237,6 @@ int
>  control(void)
>  {
>   struct passwd   *pw;
> - struct event ev_sigint;
> - struct event ev_sigterm;
>  
>   purge_config(PURGE_EVERYTHING);
>  
> @@ -271,10 +261,8 @@ control(void)
>   imsg_callback = control_imsg;
>   event_init();
>  
> - signal_set(&ev_sigint, SIGINT, control_sig_handler, NULL);
> - signal_set(&ev_sigterm, SIGTERM, control_sig_handler, NULL);
> - signal_add(&ev_sigint, NULL);
> - signal_add(&ev_sigterm, NULL);
> + signal(SIGINT, SIG_IGN);
> + signal(SIGTERM, SIG_IGN);
>   signal(SIGPIPE, SIG_IGN);
>   signal(SIGHUP, SIG_IGN);
>  
> @@ -305,7 +293,7 @@ control(void)
>  static void
>  control_shutdown(void)
>  {
> - log_info("info: control process exiting");
> + log_debug("debug: cont

Re: Default softraid crypto PBKDF2 rounds

2016-09-07 Thread Damien Miller
On Tue, 6 Sep 2016, David Coppa wrote:

> Il 6 settembre 2016 14:56:32 CEST, Filippo Valsorda  ha 
> scritto:
> >Hello,
> >
> >I recently had the occasion to dive into the softraid crypto code [1]
> >and was quite pleased with the cleanliness of it all. However, I found
> >surprising the default value of 8k PBKDF2 rounds.
> >
> >I know it is easy to override and I should have RTFM, but I (naively,
> >I'll admit) assumed OpenBSD would pick very robust defaults, erring on
> >the conservative side. Is it maybe time to bump it up, or pick it based
> >on a quick machine benchmark?
> >
> >If there's consensus I might also provide a patch for the live
> >benchmark
> >option.
> 
> yes, autodetection of a sensible value would be cool...

using bcrypt_kdf would be better :)