Re: /usr/libexec/locate.updatedb - Check root status before scanning

2019-08-29 Thread Theo de Raadt
Makes sense.

Kurt Mosiejczuk  wrote:

> locate.updatedb can't update the database unless it is run as root.
> 
> Annoyingly, it will scan the entire disk before attempting to create the
> updated database and then error out.
> 
> This just adds a quick check to see if it as running as root and
> erroring out if that is not the case. It will save me time in the
> future.  Periodically I run locate.updatedb without doas by mistake and
> don't realize my mistake until many minutes later when I get an error.
> 
> --Kurt
> 
> Index: updatedb.sh
> ===
> RCS file: /cvs/src/usr.bin/locate/locate/updatedb.sh,v
> retrieving revision 1.14
> diff -u -p -r1.14 updatedb.sh
> --- updatedb.sh   17 Jan 2019 06:15:44 -  1.14
> +++ updatedb.sh   30 Aug 2019 00:42:17 -
> @@ -29,6 +29,11 @@
>  # updatedb - update locate database for local mounted filesystems
>  #
>  
> +if [ $( id -u ) != 0 ]; then
> + echo "$0: must be root"
> + exit 1
> +fi
> +
>  LOCATE_CONFIG="/etc/locate.rc"
>  if [ -f "$LOCATE_CONFIG" -a -r "$LOCATE_CONFIG" ]; then
> . $LOCATE_CONFIG
> 



Re: validate addresses in routing message

2019-08-29 Thread Alexander Bluhm
On Thu, Aug 29, 2019 at 05:31:04PM +0200, Claudio Jeker wrote:
> I don't think this is the right way to do this. The consumer of rtinfo
> need to check the values based on their needs. Ideally we add some helpers
> to make that easier. I think it is close to impossible to properly
> validate the sockaddrs in rtm_xaddrs() since that function is missing
> needed context.

For me it is not perfectly clear at which places the routing code
deals with user input.  So I think it is better to do all the size
checks when the user data enters the kernel.  Placing the checks
at multiple places would also mean the we need error handling
everywhere.

So my plan is to check the sizes in a general way at the beginning.
If the specific code looks at the address family, it knows that the
struct is complete; e.g.  MPLS igores non AF_MPLS adresses.  It
would be easier to add sa_af checks here and there than to care
about sa_len.

A problem is that user land sometimes provides only partial addresses.
RTAX_NETMASK is such an example, so I do not check it here.  Route
labels do not have an address family, I only depend on RTAX_LABEL.
Perhaps we can figure out where userland actually provides partial
addresses and add more errors in this switch.  I consider this diff
only a start.  Ports may send even more crap than I found in our
tools already.

So I think a central size check is good, more specific code can add
more checks if needed.

New diff with more comments.  RTAX_GATEWAY may be AF_LINK, so also
check that.  RTAX_IFP from userland is very broken, so I have a
very weak check.  We should make it stricter when fixes have been
deployed.

This change needs a lot of testing.

bluhm

Index: net/rtsock.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/net/rtsock.c,v
retrieving revision 1.291
diff -u -p -r1.291 rtsock.c
--- net/rtsock.c28 Aug 2019 22:36:41 -  1.291
+++ net/rtsock.c29 Aug 2019 23:52:53 -
@@ -1350,6 +1350,11 @@ rtm_xaddrs(caddr_t cp, caddr_t cplim, st
struct sockaddr *sa;
int  i;

+   /*
+* Parse address bits, split address storage in chunks, and
+* set info pointers.  Use sa_len for traversing the memory
+* and check that we stay within in the limit.
+*/
bzero(rtinfo->rti_info, sizeof(rtinfo->rti_info));
for (i = 0; i < sizeof(rtinfo->rti_addrs) * 8; i++) {
if ((rtinfo->rti_addrs & (1 << i)) == 0)
@@ -1361,6 +1366,104 @@ rtm_xaddrs(caddr_t cp, caddr_t cplim, st
return (EINVAL);
rtinfo->rti_info[i] = sa;
ADVANCE(cp, sa);
+   }
+   /*
+* Check that the address family is suitable for the route address
+* type.  Check that each address has a size that fits its family
+* and its length is within the size.  Strings within addresses must
+* be NUL terminated.
+*/
+   for (i = 0; i < RTAX_MAX; i++) {
+   size_t len, maxlen, size;
+
+   sa = rtinfo->rti_info[i];
+   if (sa == NULL)
+   continue;
+   maxlen = size = 0;
+   switch (i) {
+   case RTAX_DST:
+   case RTAX_GATEWAY:
+   case RTAX_SRC:
+   switch (sa->sa_family) {
+   case AF_INET:
+   size = sizeof(struct sockaddr_in);
+   break;
+   case AF_LINK:
+   size = sizeof(struct sockaddr_dl);
+   break;
+#ifdef INET6
+   case AF_INET6:
+   size = sizeof(struct sockaddr_in6);
+   break;
+#endif
+#ifdef MPLS
+   case AF_MPLS:
+   size = sizeof(struct sockaddr_mpls);
+   break;
+#endif
+   }
+   break;
+   case RTAX_IFP:
+   if (sa->sa_family != AF_LINK)
+   return (EAFNOSUPPORT);
+   /*
+* XXX Should be sizeof(struct sockaddr_dl), but
+* route(8) has a bug and provides less memory.
+* arp(8) has another bug and uses sizeof pointer.
+*/
+   size = 4;
+   break;
+   case RTAX_IFA:
+   switch (sa->sa_family) {
+   case AF_INET:
+   size = sizeof(struct sockaddr_in);
+   break;
+#ifdef INET6
+   case AF_INET6:
+   size = sizeof(struct sockaddr_in6);
+   break;
+#endif
+   default:
+   

Re: route address order

2019-08-29 Thread Claudio Jeker
On Thu, Aug 29, 2019 at 10:55:44PM +0200, Alexander Bluhm wrote:
> Hi,
> 
> The kernel uses rtm_addrs as a bit field for addresses that are
> included in the routing message.  The significance of the bits has
> to be consistent with the order of the addresss.  In route(8) store
> addresses in ascending order of RTA values.  This allows to use
> MPLS routes together with route labels.
> 
> ok?

OK claudio@
 
> bluhm
> 
> Index: sbin/route/route.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/sbin/route/route.c,v
> retrieving revision 1.231
> diff -u -p -r1.231 route.c
> --- sbin/route/route.c29 Aug 2019 14:28:34 -  1.231
> +++ sbin/route/route.c29 Aug 2019 20:44:35 -
> @@ -68,7 +68,7 @@
>  const struct if_status_description
>   if_status_descriptions[] = LINK_STATE_DESCRIPTIONS;
> 
> -union sockunion so_dst, so_gate, so_mask, so_ifa, so_ifp, so_label, so_src;
> +union sockunion so_dst, so_gate, so_mask, so_ifa, so_ifp, so_src, so_label;
> 
>  typedef union sockunion *sup;
>  pid_tpid;
> @@ -1087,13 +1087,14 @@ rtmsg(int cmd, int flags, int fmask, uin
> 
>   if (rtm_addrs & RTA_NETMASK)
>   mask_addr(_dst, _mask, RTA_DST);
> + /* store addresses in ascending order of RTA values */
>   NEXTADDR(RTA_DST, so_dst);
>   NEXTADDR(RTA_GATEWAY, so_gate);
>   NEXTADDR(RTA_NETMASK, so_mask);
>   NEXTADDR(RTA_IFP, so_ifp);
>   NEXTADDR(RTA_IFA, so_ifa);
> - NEXTADDR(RTA_LABEL, so_label);
>   NEXTADDR(RTA_SRC, so_src);
> + NEXTADDR(RTA_LABEL, so_label);
>   rtm.rtm_msglen = l = cp - (char *)_rtmsg;
>   if (verbose)
>   print_rtmsg(, l);
> 

-- 
:wq Claudio



route address order

2019-08-29 Thread Alexander Bluhm
Hi,

The kernel uses rtm_addrs as a bit field for addresses that are
included in the routing message.  The significance of the bits has
to be consistent with the order of the addresss.  In route(8) store
addresses in ascending order of RTA values.  This allows to use
MPLS routes together with route labels.

ok?

bluhm

Index: sbin/route/route.c
===
RCS file: /data/mirror/openbsd/cvs/src/sbin/route/route.c,v
retrieving revision 1.231
diff -u -p -r1.231 route.c
--- sbin/route/route.c  29 Aug 2019 14:28:34 -  1.231
+++ sbin/route/route.c  29 Aug 2019 20:44:35 -
@@ -68,7 +68,7 @@
 const struct if_status_description
if_status_descriptions[] = LINK_STATE_DESCRIPTIONS;

-union sockunion so_dst, so_gate, so_mask, so_ifa, so_ifp, so_label, so_src;
+union sockunion so_dst, so_gate, so_mask, so_ifa, so_ifp, so_src, so_label;

 typedef union sockunion *sup;
 pid_t  pid;
@@ -1087,13 +1087,14 @@ rtmsg(int cmd, int flags, int fmask, uin

if (rtm_addrs & RTA_NETMASK)
mask_addr(_dst, _mask, RTA_DST);
+   /* store addresses in ascending order of RTA values */
NEXTADDR(RTA_DST, so_dst);
NEXTADDR(RTA_GATEWAY, so_gate);
NEXTADDR(RTA_NETMASK, so_mask);
NEXTADDR(RTA_IFP, so_ifp);
NEXTADDR(RTA_IFA, so_ifa);
-   NEXTADDR(RTA_LABEL, so_label);
NEXTADDR(RTA_SRC, so_src);
+   NEXTADDR(RTA_LABEL, so_label);
rtm.rtm_msglen = l = cp - (char *)_rtmsg;
if (verbose)
print_rtmsg(, l);



[patch] vmd: fix possible small memleak in vm_claimid() error path

2019-08-29 Thread Hiltjo Posthuma
Hi,

This fixes a small possible memory leak in an error handling path in vmd.c
vm_claimid().


diff --git usr.sbin/vmd/vmd.c usr.sbin/vmd/vmd.c
index 654af5974d3..81be6b356d6 100644
--- usr.sbin/vmd/vmd.c
+++ usr.sbin/vmd/vmd.c
@@ -1197,6 +1197,7 @@ vm_claimid(const char *name, int uid, uint32_t *id)
n2i->uid = uid;
if (strlcpy(n2i->name, name, sizeof(n2i->name)) >= sizeof(n2i->name)) {
log_warnx("vm name too long");
+   free(n2i);
return -1;
}
TAILQ_INSERT_TAIL(env->vmd_known, n2i, entry);

-- 
Kind regards,
Hiltjo



Re: validate addresses in routing message

2019-08-29 Thread Claudio Jeker
On Wed, Aug 28, 2019 at 11:58:36PM +0200, Alexander Bluhm wrote:
> Hi,
> 
> The kernel may crash as there is not enough input validation in
> routing messages.
> 
> https://syzkaller.appspot.com/bug?id=e2076a6518b49730aefe64acf0a266f8e79685a5
> 
> Here the name of a routing label is not NUL terminated, but there
> are more things that can go wrong.  So I added some checks for
> incoming routing addresses from userland that the kernel actually
> uses.
> 
> It is not super strict as userland may provide incomplete addresses
> that work anyway.  I remember openvpn caused some problems in this
> area.  Could someone test it with this diff?
> 
> ok?

I don't think this is the right way to do this. The consumer of rtinfo
need to check the values based on their needs. Ideally we add some helpers
to make that easier. I think it is close to impossible to properly
validate the sockaddrs in rtm_xaddrs() since that function is missing
needed context.

 
> bluhm
> 
> Index: net/rtsock.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/sys/net/rtsock.c,v
> retrieving revision 1.290
> diff -u -p -w -r1.290 rtsock.c
> --- net/rtsock.c  28 Aug 2019 20:54:24 -  1.290
> +++ net/rtsock.c  28 Aug 2019 21:23:34 -
> @@ -1366,6 +1366,91 @@ rtm_xaddrs(caddr_t cp, caddr_t cplim, st
>   rtinfo->rti_info[i] = sa;
>   ADVANCE(cp, sa);
>   }
> + for (i = 0; i < RTAX_MAX; i++) {
> + size_t len, maxlen, size;
> +
> + sa = rtinfo->rti_info[i];
> + if (sa == NULL)
> + continue;
> + maxlen = size = 0;
> + switch (i) {
> + case RTAX_DST:
> + case RTAX_GATEWAY:
> + case RTAX_SRC:
> + switch (sa->sa_family) {
> + case AF_INET:
> + size = sizeof(struct sockaddr_in);
> + break;
> +#ifdef INET6
> + case AF_INET6:
> + size = sizeof(struct sockaddr_in6);
> + break;
> +#endif
> +#ifdef MPLS
> + case AF_MPLS:
> + size = sizeof(struct sockaddr_mpls);
> + break;
> +#endif
> + }
> + break;
> + case RTAX_IFP:
> + if (sa->sa_family != AF_LINK)
> + return (EAFNOSUPPORT);
> + /*
> +  * XXX Should be sizeof(struct sockaddr_dl), but
> +  * route(8) has a bug and provides less memory.
> +  */
> + size = 16;
> + break;
> + case RTAX_IFA:
> + switch (sa->sa_family) {
> + case AF_INET:
> + size = sizeof(struct sockaddr_in);
> + break;
> +#ifdef INET6
> + case AF_INET6:
> + size = sizeof(struct sockaddr_in6);
> + break;
> +#endif
> + default:
> + return (EAFNOSUPPORT);
> + }
> + break;
> + case RTAX_LABEL:
> + maxlen = RTLABEL_LEN;
> + size = sizeof(struct sockaddr_rtlabel);
> + break;
> +#ifdef BFD
> + case RTAX_BFD:
> + size = sizeof(struct sockaddr_bfd);
> + break;
> +#endif
> + case RTAX_DNS:
> + maxlen = RTDNS_LEN;
> + size = sizeof(struct sockaddr_rtdns);
> + break;
> + case RTAX_STATIC:
> + maxlen = RTSTATIC_LEN;
> + size = sizeof(struct sockaddr_rtstatic);
> + break;
> + case RTAX_SEARCH:
> + maxlen = RTSEARCH_LEN;
> + size = sizeof(struct sockaddr_rtsearch);
> + break;
> + }
> + if (size) {
> + if (sa->sa_len < size)
> + return (EINVAL);
> + }
> + if (maxlen) {
> + if (2 + maxlen >= size)
> + return (EINVAL);
> + len = strnlen(sa->sa_data, maxlen);
> + if (len >= maxlen || 2 + len >= sa->sa_len)
> + return (EINVAL);
> + break;
> + }
> + }
>   return (0);
>  }
> 

-- 
:wq Claudio



Re: iked(8): remove redundant valid_ike_sa check

2019-08-29 Thread Alexander Bluhm
On Thu, Aug 29, 2019 at 02:21:47PM +0200, Tobias Heider wrote:
> This check is done twice. The diff removes the second one.
>
> ok?

OK bluhm@

> Index: ikev2.c
> ===
> RCS file: /mount/openbsd/cvs/src/sbin/iked/ikev2.c,v
> retrieving revision 1.174
> diff -u -p -u -r1.174 ikev2.c
> --- ikev2.c   24 Aug 2019 13:09:38 -  1.174
> +++ ikev2.c   29 Aug 2019 12:14:43 -
> @@ -833,9 +833,6 @@ ikev2_init_recv(struct iked *env, struct
>   break;
>   case IKEV2_EXCHANGE_IKE_AUTH:
>   case IKEV2_EXCHANGE_CREATE_CHILD_SA:
> - if (ikev2_msg_valid_ike_sa(env, hdr, msg) == -1)
> - return;
> - break;
>   case IKEV2_EXCHANGE_INFORMATIONAL:
>   break;
>   default:



arp routing addresses size

2019-08-29 Thread Alexander Bluhm
Hi,

As soon as our kernel does input validation, I find bugs in userland.
The IFP address in arp(8) used some 0 bytes at locations depending
on sizeof(long) as sockaddr_dl.  We were lucky and it worked.

Use the correct size and the algorithm from route(8) for arp(8).

ok?

bluhm

Index: usr.sbin/arp/arp.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/arp/arp.c,v
retrieving revision 1.84
diff -u -p -r1.84 arp.c
--- usr.sbin/arp/arp.c  27 Aug 2019 20:50:36 -  1.84
+++ usr.sbin/arp/arp.c  29 Aug 2019 14:12:15 -
@@ -91,8 +91,9 @@ static int rdomain;
 extern int h_errno;

 /* ROUNDUP() is nasty, but it is identical to what's in the kernel. */
-#define ROUNDUP(a) \
+#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
+#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))

 /* which function we're supposed to do */
 #define F_GET  1
@@ -282,7 +283,7 @@ parse_host(const char *host, struct in_a
 struct sockaddr_in so_mask = { 8, 0, 0, { 0x } };
 struct sockaddr_inarp  blank_sin = { sizeof(blank_sin), AF_INET }, sin_m;
 struct sockaddr_dl blank_sdl = { sizeof(blank_sdl), AF_LINK }, sdl_m;
-struct sockaddr_dl ifp_m = { sizeof(_m), AF_LINK };
+struct sockaddr_dl ifp_m = { sizeof(ifp_m), AF_LINK };
 time_t expire_time;
 intflags, export_only, doing_proxy, found_entry;
 struct {
@@ -672,10 +673,11 @@ rtmsg(int cmd)
rtm->rtm_addrs |= (RTA_DST | RTA_IFP);
}

-#define NEXTADDR(w, s) \
-   if (rtm->rtm_addrs & (w)) { \
-   memcpy(cp, , sizeof(s));  \
-   cp += ROUNDUP(sizeof(s));   \
+#define NEXTADDR(w, s) \
+   if (rtm->rtm_addrs & (w)) { \
+   l = ROUNDUP(((struct sockaddr *)&(s))->sa_len); \
+   memcpy(cp, &(s), l);\
+   cp += l;\
}

NEXTADDR(RTA_DST, sin_m);
@@ -732,7 +734,7 @@ rtget(struct sockaddr_inarp **sinp, stru
default:
break;
}
-   cp += ROUNDUP(sa->sa_len);
+   ADVANCE(cp, sa);
}
}
}



iked(8): remove redundant valid_ike_sa check

2019-08-29 Thread Tobias Heider
This check is done twice. The diff removes the second one.

ok?

Index: ikev2.c
===
RCS file: /mount/openbsd/cvs/src/sbin/iked/ikev2.c,v
retrieving revision 1.174
diff -u -p -u -r1.174 ikev2.c
--- ikev2.c 24 Aug 2019 13:09:38 -  1.174
+++ ikev2.c 29 Aug 2019 12:14:43 -
@@ -833,9 +833,6 @@ ikev2_init_recv(struct iked *env, struct
break;
case IKEV2_EXCHANGE_IKE_AUTH:
case IKEV2_EXCHANGE_CREATE_CHILD_SA:
-   if (ikev2_msg_valid_ike_sa(env, hdr, msg) == -1)
-   return;
-   break;
case IKEV2_EXCHANGE_INFORMATIONAL:
break;
default:



make patch: let MAKEOBJDIR be more powerful

2019-08-29 Thread Marc Espie
After some musings, I realized I just had to reorder a few things to
make MAKEOBJDIR way more powerful (and possibly useful)

The idea here is to init vars early, which is easy, and to set up
.CURDIR, MACHINE, MACHINE_ARCH, MACHINE_CPU, so that
MAKEOBJDIR can actually become a full-blown make expression.

e.g., with this something like

MAKEOBJDIR='${.CURDIR}:S/src/obj/}'

will work.

any takers ?


Index: init.c
===
RCS file: /cvs/src/usr.bin/make/init.c,v
retrieving revision 1.7
diff -u -p -r1.7 init.c
--- init.c  2 Oct 2012 10:29:30 -   1.7
+++ init.c  29 Aug 2019 11:01:19 -
@@ -48,8 +48,6 @@ Init(void)
 * can be processed correctly */
Parse_Init();   /* Need to initialize the paths of #include
 * directories */
-   Var_Init(); /* As well as the lists of variables for
-* parsing arguments */
Arch_Init();
Suff_Init();
 }
Index: main.c
===
RCS file: /cvs/src/usr.bin/make/main.c,v
retrieving revision 1.123
diff -u -p -r1.123 main.c
--- main.c  22 Apr 2019 18:32:09 -  1.123
+++ main.c  29 Aug 2019 11:01:19 -
@@ -558,12 +558,16 @@ setup_CURDIR_OBJDIR(struct dirs *d)
 * and modify the paths for the Makefiles appropriately.  The
 * current directory is also placed as a variable for make scripts.
 */
-   if ((path = getenv("MAKEOBJDIR")) == NULL) {
+   Var_Set(".CURDIR", d->current);
+   if ((path = getenv("MAKEOBJDIR")) == NULL)
path = _PATH_OBJDIR;
-   } 
+   /* if there's a $ in there, allow substitution */
+   else if (strchr(path, '$'))
+   path = Var_Subst(path, NULL, false);
d->object = chdir_verify_path(path, d);
if (d->object == NULL)
d->object = d->current;
+   Var_Set(".OBJDIR", d->object);
 }
 
 /*
@@ -656,6 +660,11 @@ main(int argc, char **argv)
bool read_depend = true;/* false if we don't want to read .depend */
 
MainParseChdir(argc, argv);
+   Var_Init(); /* do this early for OBJDIR */
+   Var_Set("MACHINE", machine);
+   Var_Set("MACHINE_ARCH", machine_arch);
+   Var_Set("MACHINE_CPU", machine_cpu);
+
setup_CURDIR_OBJDIR();
 
esetenv("PWD", d.object);
@@ -687,8 +696,6 @@ main(int argc, char **argv)
 
if (d.object != d.current)
Dir_AddDir(defaultPath, d.current);
-   Var_Set(".CURDIR", d.current);
-   Var_Set(".OBJDIR", d.object);
Parse_setcurdir(d.current);
Targ_setdirs(d.current, d.object);
 
@@ -702,9 +709,6 @@ main(int argc, char **argv)
Var_Set(".MAKE", argv[0]);
Var_Set(MAKEFLAGS, "");
Var_Set("MFLAGS", "");
-   Var_Set("MACHINE", machine);
-   Var_Set("MACHINE_ARCH", machine_arch);
-   Var_Set("MACHINE_CPU", machine_cpu);
 
/*
 * First snag any flags out of the MAKEFLAGS environment variable.



switching between audio devices with no playback interruption

2019-08-29 Thread Alexandre Ratchov
The diff below allows to specifiy "an alternate device" to use in case
the audio device is disconnected. If so, programs continue playing
using the other device.

For instance, if dmesg contains:

audio0 at azalia0
audio1 at uaudio0

and /etc/rc.conf.local contains:

sndiod_flags=-f rsnd/0 -F rsnd/1

then sndiod will try to use the usb device by default. If it's
disconnected, programs continue using the internal one. Note that
there's no way to detect that the usb device is reconnected; the
internal one will keep playing until all programs stop; then sndiod
will retry the usb one again. To force sndiod to retry the usb one,
send SIGHUP.

As we're at it, the same logic is applied to MIDI as well; it makes
possible to swap instuments without restarting programs.

For all this to work, both audio devices must support the same rate
(48kHz by default) and the same block size (now 10ms by default). This
requires the block size calculation to be fixed in the audio(9) layer,
so this diff is needed as well:

https://marc.info/?l=openbsd-tech=156610818325864

Please test even if you don't use this feature as this diff changes
the default audio block size (not all USB host controllers support
large transfers).

OK?

Index: dev.c
===
RCS file: /cvs/src/usr.bin/sndiod/dev.c,v
retrieving revision 1.58
diff -u -p -u -p -r1.58 dev.c
--- dev.c   29 Aug 2019 07:38:15 -  1.58
+++ dev.c   29 Aug 2019 07:52:08 -
@@ -968,7 +968,8 @@ dev_new(char *path, struct aparams *par,
return NULL;
}
d = xmalloc(sizeof(struct dev));
-   d->path = xstrdup(path);
+   d->path_list = NULL;
+   namelist_add(>path_list, path);
d->num = dev_sndnum++;
d->opt_list = NULL;
 
@@ -1173,6 +1174,94 @@ dev_close(struct dev *d)
dev_close_do(d);
 }
 
+/*
+ * Close the device, but attempt to migrate everything to a new sndio
+ * device.
+ */
+void
+dev_reopen(struct dev *d)
+{
+   struct slot *s;
+   long long pos;
+   unsigned int mode, round, bufsz, rate, pstate;
+   int delta;
+
+   /* not opened */
+   if (d->pstate == DEV_CFG)
+   return;
+
+   if (log_level >= 1) {
+   dev_log(d);
+   log_puts(": reopening device\n");
+   }
+
+   /* save state */
+   mode = d->mode;
+   round = d->round;
+   bufsz = d->bufsz;
+   rate = d->rate;
+   delta = d->delta;
+   pstate = d->pstate;
+
+   /* close device */
+   dev_close_do(d);
+
+   /* open device */
+   if (!dev_open_do(d)) {
+   if (log_level >= 1) {
+   dev_log(d);
+   log_puts(": found no working alternate device\n");
+   }
+   dev_exitall(d);
+   return;
+   }
+
+   /* check if new parameters are compatible with old ones */
+   if (d->mode != mode ||
+   d->round != round ||
+   d->bufsz != bufsz ||
+   d->rate != rate) {
+   if (log_level >= 1) {
+   dev_log(d);
+   log_puts(": alternate device not compatible\n");
+   }
+   dev_close(d);
+   return;
+   }
+
+   /*
+* adjust time positions, make anything go back delta ticks, so
+* that the new device can start at zero
+*/
+   for (s = d->slot_list; s != NULL; s = s->next) {
+   pos = (long long)(d->round - delta) * s->round + s->delta_rem;
+   s->delta_rem = pos % d->round;
+   s->delta += pos / (int)d->round;
+   s->delta -= s->round;
+   if (log_level >= 2) {
+   slot_log(s);
+   log_puts(": adjusted: delta -> ");
+   log_puti(s->delta);
+   log_puts(", delta_rem -> ");
+   log_puti(s->delta_rem);
+   log_puts("\n");
+   }
+   }
+   if (d->tstate == MMC_RUN) {
+   d->mtc.delta -= delta * MTC_SEC;
+   if (log_level >= 2) {
+   dev_log(d);
+   log_puts(": adjusted mtc: delta ->");
+   log_puti(d->mtc.delta);
+   log_puts("\n");
+   }
+   }
+
+   /* start the device if needed */
+   if (pstate == DEV_RUN)
+   dev_wakeup(d);
+}
+
 int
 dev_ref(struct dev *d)
 {
@@ -1279,7 +1368,7 @@ dev_del(struct dev *d)
}
midi_del(d->midi);
*p = d->next;
-   xfree(d->path);
+   namelist_clear(>path_list);
xfree(d);
 }
 
Index: dev.h
===
RCS file: /cvs/src/usr.bin/sndiod/dev.h,v
retrieving revision 1.21
diff -u -p -u -p -r1.21 dev.h
--- dev.h   12 Jul 2019 06:30:55 -  1.21
+++ dev.h   29 

Re: smtpd reports - expectation management

2019-08-29 Thread Martijn van Duren
On 8/29/19 8:53 AM, gil...@poolp.org wrote:
> 29 août 2019 07:02 "Martijn van Duren"  a 
> écrit:
> 
>> Since we don't support any smtp-out events at time of writing, so we
>> might as well throw an error if people try to register one. This way
>> people won't be surprised if the registration succeeds, but no event
>> ever arrives.
>>
>> OK?
>>
> 
> no warning for unused smtp_out ?

it's still used on lines 84, 93 and 155.
The one on line 155 is just never triggered. :-)
> 
> ok with ifdef-ing out smtp-out for now, i can bring it back.
> 
> for the record, smtp-out has been implemented and I have it running on my
> machines but it requires a rework of the filter session registration (not
> visible to users) which I'm not comfortable to do before 6.6.

I assumed it's in the works.
> 
> 
>> Index: lka_report.c
>> ===
>> RCS file: /cvs/src/usr.sbin/smtpd/lka_report.c,v
>> retrieving revision 1.26
>> diff -u -p -r1.26 lka_report.c
>> --- lka_report.c 28 Aug 2019 15:50:36 - 1.26
>> +++ lka_report.c 29 Aug 2019 05:01:21 -
>> @@ -107,10 +107,13 @@ lka_report_register_hook(const char *nam
>> subsystem = _in;
>> hook += 8;
>> }
>> +#if 0
>> + /* No smtp-out event has been implemented yet */
>> else if (strncmp(hook, "smtp-out|", 9) == 0) {
>> subsystem = _out;
>> hook += 9;
>> }
>> +#endif
>> else
>> fatalx("Invalid message direction: %s", hook);



Re: smtpd reports - expectation management

2019-08-29 Thread gilles
29 août 2019 07:02 "Martijn van Duren"  a 
écrit:

> Since we don't support any smtp-out events at time of writing, so we
> might as well throw an error if people try to register one. This way
> people won't be surprised if the registration succeeds, but no event
> ever arrives.
> 
> OK?
> 

no warning for unused smtp_out ?

ok with ifdef-ing out smtp-out for now, i can bring it back.

for the record, smtp-out has been implemented and I have it running on my
machines but it requires a rework of the filter session registration (not
visible to users) which I'm not comfortable to do before 6.6.


> Index: lka_report.c
> ===
> RCS file: /cvs/src/usr.sbin/smtpd/lka_report.c,v
> retrieving revision 1.26
> diff -u -p -r1.26 lka_report.c
> --- lka_report.c 28 Aug 2019 15:50:36 - 1.26
> +++ lka_report.c 29 Aug 2019 05:01:21 -
> @@ -107,10 +107,13 @@ lka_report_register_hook(const char *nam
> subsystem = _in;
> hook += 8;
> }
> +#if 0
> + /* No smtp-out event has been implemented yet */
> else if (strncmp(hook, "smtp-out|", 9) == 0) {
> subsystem = _out;
> hook += 9;
> }
> +#endif
> else
> fatalx("Invalid message direction: %s", hook);



Re: iwm: two small Rx code path fixes

2019-08-29 Thread Richard Procter
Hi Stefan,

On 28/08/2019, Stefan Sperling  wrote:
> 1) Fix max frame length check to account for the firmware's Rx result
>header in the buffer, which contains two uint16_t fields.
>Frame data begins after this header.
>
> 2) Do not write to mbuf length fields before the mbuf has been removed
>from the Rx ring.
>Based on dragonfly commit 96eaecf93d9f731459a0df8efc72cfad034320bd
>by Imre Vadasz.
>
> Tested on 8260; ping and tcpbench still work.

Tested pings, bulk downloads, etc, with no ill effects seen.

ok procter@

iwm0 at pci1 dev 0 function 0 "Intel Dual Band Wireless AC 7265" rev 0x69, msi
iwm0: hw rev 0x210, fw ver 16.242414.0, address xx:xx:xx:xx:xx:xx

best,
Richard.

>
> ok?
>
> diff refs/heads/master refs/heads/iwm-mbuf-hacks
> blob - 038e6a63dfff113b525bb1e9a30c935996535569
> blob + b586f473be83a7a68e251700242ba19baa60d83c
> --- sys/dev/pci/if_iwm.c
> +++ sys/dev/pci/if_iwm.c
> @@ -3540,46 +3540,45 @@ iwm_rx_rx_mpdu(struct iwm_softc *sc, struct
> iwm_rx_pac
>   rx_res = (struct iwm_rx_mpdu_res_start *)pkt->data;
>   wh = (struct ieee80211_frame *)(pkt->data + sizeof(*rx_res));
>   len = le16toh(rx_res->byte_count);
>   if (len < IEEE80211_MIN_LEN) {
>   ic->ic_stats.is_rx_tooshort++;
>   IC2IFP(ic)->if_ierrors++;
>   return;
>   }
> - if (len > IWM_RBUF_SIZE) {
> + if (len > IWM_RBUF_SIZE - sizeof(*rx_res)) {
>   IC2IFP(ic)->if_ierrors++;
>   return;
>   }
>   rx_pkt_status = le32toh(*(uint32_t *)(pkt->data +
>   sizeof(*rx_res) + len));
>
> - m = data->m;
> - m->m_data = pkt->data + sizeof(*rx_res);
> - m->m_pkthdr.len = m->m_len = len;
> -
>   if (__predict_false(phy_info->cfg_phy_cnt > 20))
>   return;
>
>   if (!(rx_pkt_status & IWM_RX_MPDU_RES_STATUS_CRC_OK) ||
>   !(rx_pkt_status & IWM_RX_MPDU_RES_STATUS_OVERRUN_OK))
>   return; /* drop */
>
> + m = data->m;
> + if (iwm_rx_addbuf(sc, IWM_RBUF_SIZE, sc->rxq.cur) != 0)
> + return;
> + m->m_data = pkt->data + sizeof(*rx_res);
> + m->m_pkthdr.len = m->m_len = len;
> +
>   device_timestamp = le32toh(phy_info->system_timestamp);
>
>   if (sc->sc_capaflags & IWM_UCODE_TLV_FLAGS_RX_ENERGY_API) {
>   rssi = iwm_get_signal_strength(sc, phy_info);
>   } else {
>   rssi = iwm_calc_rssi(sc, phy_info);
>   }
>   rssi = (0 - IWM_MIN_DBM) + rssi;/* normalize */
>   rssi = MIN(rssi, ic->ic_max_rssi);  /* clip to max. 100% */
> -
> - if (iwm_rx_addbuf(sc, IWM_RBUF_SIZE, sc->rxq.cur) != 0)
> - return;
>
>   chanidx = letoh32(phy_info->channel);
>   if (chanidx < 0 || chanidx >= nitems(ic->ic_channels))  
>   chanidx = ieee80211_chan2ieee(ic, ic->ic_ibss_chan);
>
>   ni = ieee80211_find_rxnode(ic, wh);
>   if (ni == ic->ic_bss) {
>   /*
>
>