Re: ASan checkpoint

2021-09-04 Thread Todd C . Miller
On Sat, 04 Sep 2021 11:36:33 +0200, Greg Steuck wrote:

> This brings me to the "what's next" part. Obviously the mmap
> interception needs to be fixed to get anywhere. MmapNamed invokes
> internal_mmap which is defined in sanitizer_openbsd.cpp as:
>
> uptr internal_mmap(void *addr, size_t length, int prot, int flags, int fd,
>u64 offset) {
>   return (uptr)mmap(addr, length, prot, flags, fd, offset);
> }
>
> This sadly can't work because mmap in sanitizer_common_interceptors.inc
> calls internal_mmap if !asan_inited and hence the endless
> recursion. Other systems have alternative ways of reaching the original
> libc mmap. E.g. directly calling mmap syscall in sanitizer_linux.cpp or
> calling __mmap in sanitizer_netbsd.cpp. Neither of these seems to be
> available on OpenBSD. So, what can we do to interpose mmap?

The simplest approach is probably to use _thread_sys_mmap() instead.
That is a strong alias for the hidden _libc_mmap() function.

 - todd



Re: timeout: Prettify man page and usage

2021-09-04 Thread Ingo Schwarze
Hi Jason,

Jason McIntyre wrote on Sat, Sep 04, 2021 at 09:47:12PM +0100:

> pretty damning that my ok is on that commit ;)
> i'll try to remember...

Heh.  With the amount of work you are doing - your current commit
count stands at 9113, on average 1.34 per day, during a time of
over eightteen years and seven months (and that does not even include
the many OKs you provided), it would be pretty unreasonable to
expect remembering every single commit...   8-)

Yours,
  Ingo



Re: update to tcpdump(8)

2021-09-04 Thread Jason McIntyre
On Sat, Sep 04, 2021 at 07:26:21PM +0200, Denis Fondras wrote:
> Le Thu, Sep 02, 2021 at 08:36:06AM -0600, Theo de Raadt a ?crit :
> > I think the following approach will work.
> > 
> > 1. changes from tcpdump.8 -r1.00 to -rHEAD need merging into pcap-filter.5
> > 
> 
> Here is a diff for this step.
> 

hi.

the diff looks ok to me. but run any doc changes through "mandoc
-Tlint", and look at any issues your diff may have introduced. in this
case it's just trailing whitespace, but it's super helpful to check your
work.

> I have one question though.
> 
> tcpdump.8 has :
> " tcpdump does not currently know how to parse lat, moprc, or mopdl.  "
> 
> while pcap-filter.5 has :
> " Note that not all applications using pcap_open_live(3) currently know how to
> parse these protocols. "
> 
> Should I mention explicitely tcpdump(8) in pcap-filter.5 ? It seems implicit 
> in
> the current version.
> 

i guess it would be fine to have differences in the text where they made
sense. or you could try to write the sentence in a more general way,
that will make sense in both pages.

still, doesn;t the sentence in pcap-filter.5 also include tcpdump (as an
pllication using pcap_open_live, or at least a version of it)?

jmc

> Index: pcap-filter.5
> ===
> RCS file: /cvs/src/lib/libpcap/pcap-filter.5,v
> retrieving revision 1.9
> diff -u -p -r1.9 pcap-filter.5
> --- pcap-filter.5 2 Sep 2021 10:59:13 -   1.9
> +++ pcap-filter.5 4 Sep 2021 17:04:36 -
> @@ -40,27 +40,31 @@ or
>  .Pp
>  The filter expression consists of one or more
>  .Em primitives .
> -Primitives usually consist of an ID (name or number)
> +Primitives usually consist of an
> +.Ar id
> +.Pq name or number
>  preceded by one or more qualifiers.
>  There are three different kinds of qualifier:
>  .Bl -tag -width "proto"
> -.It type
> -Type qualifiers say what kind of thing the ID name or number refers to.
> +.It Ar type
> +Specify which kind of address component the
> +.Ar id
> +name or number refers to.
>  Possible types are
>  .Cm host ,
> -.Cm net ,
> +.Cm net
>  and
>  .Cm port .
> -For example,
> +E.g.,
>  .Dq host foo ,
>  .Dq net 128.3 ,
> -and
>  .Dq port 20 .
>  If there is no type qualifier,
>  .Cm host
>  is assumed.
> -.It dir
> -Dir qualifiers specify a particular transfer direction to and/or from an ID.
> +.It Ar dir
> +Specify a particular transfer direction to and/or from
> +.Ar id .
>  Possible directions are
>  .Cm src ,
>  .Cm dst ,
> @@ -73,11 +77,13 @@ Possible directions are
>  .Cm addr3 ,
>  and
>  .Cm addr4 .
> -For example,
> -.Cm src foo ,
> -.Cm dst net 128.3 ,
> -.Cm src or dst port ftp-data .
> -If there is no dir qualifier,
> +E.g.,
> +.Dq src foo ,
> +.Dq dst net 128.3 ,
> +.Dq src or dst port ftp-data .
> +If there is no
> +.Ar dir
> +qualifier,
>  .Cm src or dst
>  is assumed.
>  The
> @@ -89,55 +95,83 @@ The
>  and
>  .Cm addr4
>  qualifiers are only valid for IEEE 802.11 Wireless LAN link layers.
> -For some link layers, such as SLIP and the "cooked" Linux capture mode
> -used for the "any" device and for some other device types, the
> +For null link layers (i.e., point-to-point protocols such as SLIP
> +.Pq Serial Line Internet Protocol
> +or the
> +.Xr pflog 4
> +header), the
>  .Cm inbound
>  and
>  .Cm outbound
>  qualifiers can be used to specify a desired direction.
> -.It proto
> +.It Ar proto
>  Proto qualifiers restrict the match to a particular protocol.
>  Possible
> -protos are:
> +protocols are:
> +.Cm ah ,
> +.Cm arp ,
> +.Cm atalk ,
> +.Cm decnet ,
> +.Cm esp ,
>  .Cm ether ,
>  .Cm fddi ,
> -.Cm tr ,
> -.Cm wlan ,
> +.Cm icmp ,
> +.Cm icmp6 ,
> +.Cm igmp ,
> +.Cm igrp ,
>  .Cm ip ,
>  .Cm ip6 ,
> -.Cm arp ,
> +.Cm lat ,
> +.Cm mopdl ,
> +.Cm moprc ,
> +.Cm pim ,
>  .Cm rarp ,
> -.Cm decnet ,
> +.Cm sca ,
> +.Cm stp ,
>  .Cm tcp ,
> +.Cm udp ,
>  and
> -.Cm udp .
> -For example,
> +.Cm wlan .
> +E.g.,
>  .Dq ether src foo ,
>  .Dq arp net 128.3 ,
>  .Dq tcp port 21 ,
>  and
>  .Dq wlan addr2 0:2:3:4:5:6 .
> -If there is no proto qualifier,
> +If there is no protocol qualifier,
>  all protocols consistent with the type are assumed.
> -For example,
> +E.g.,
>  .Dq src foo
>  means
> -.Dq (ip or arp or rarp) src foo
> -(except the latter is not legal syntax);
> +.Do
> +.Pq ip or arp or rarp
> +src foo
> +.Dc
> +.Pq except the latter is not legal syntax ;
>  .Dq net bar
>  means
> -.Dq (ip or arp or rarp) net bar ;
> +.Do
> +.Pq ip or arp or rarp
> +net bar
> +.Dc ;
>  and
>  .Dq port 53
>  means
> -.Dq (tcp or udp) port 53 .
> +.Do
> +.Pq TCP or UDP
> +port 53
> +.Dc .
>  .Pp
>  .Cm fddi
>  is actually an alias for
>  .Cm ether ;
>  the parser treats them identically as meaning
> -"the data link level used on the specified network interface".
> -FDDI headers contain Ethernet-like source and destination addresses,
> +.Qo
> +the data link level used on the specified network interface
> +.Qc .
> +FDDI
> +.Pq Fiber Distributed Data 

Re: timeout: Prettify man page and usage

2021-09-04 Thread Jason McIntyre
On Sat, Sep 04, 2021 at 02:14:47PM +0200, Ingo Schwarze wrote:
> Hi Jason,
> 
> Jason McIntyre wrote on Fri, Sep 03, 2021 at 02:46:47PM +0100:
> > On Fri, Sep 03, 2021 at 03:42:21PM +0200, Ingo Schwarze wrote:
> >> Theo de Raadt wrote on Thu, Sep 02, 2021 at 09:57:11AM -0600:
> 
> >>> I think we should list shorts, and longs which have no shorts.
> 
> >> I agree, and i think we arrived at the same conclusion in the past.
> >> 
> >> It applies to both usage() and SYNOPSIS, and ideally, both should
> >> match, except maybe in very unusual cases.
> 
> > sure. but grep tripped me up, and it's always the page i think of with
> > long options. why did we leave --context in SYNOPSIS?
> 
> I admit the grep(1) case is slightly confusing, but it is explained
> here why it is somewhat special:
> 
>   https://cvsweb.openbsd.org/src/usr.bin/grep/grep.1#rev1.47
> 
> Yours,
>   Ingo
> 

hi ingo.

pretty damning that my ok is on that commit ;)
i'll try to remember...

jmc



new gpiocharger driver

2021-09-04 Thread Klemens Nanni
Read a single GPIO pin indicating whether AC is plugged in or not.

This gives me a sensor on my Pinebook Pro.
cwfg(4) already provides battery information but not the charger bits.

apm(4) integration can follow separately.

Feedback? OK?


diff 4e7699b4cf65fba4bf837b202fb68ee0f66e6d07 refs/heads/master
blob - b92b1f60934ba60f92341ce94570d0ae96e78c1d
blob + 549a8316b874e4e5a6e1ede1640eeefadd9af0d4
--- distrib/sets/lists/man/mi
+++ distrib/sets/lists/man/mi
@@ -1417,6 +1417,7 @@
 ./usr/share/man/man4/glenv.4
 ./usr/share/man/man4/glkgpio.4
 ./usr/share/man/man4/gpio.4
+./usr/share/man/man4/gpiocharger.4
 ./usr/share/man/man4/gpiodcf.4
 ./usr/share/man/man4/gpioiic.4
 ./usr/share/man/man4/gpioleds.4
blob - bb62c44d32f152ecf64aa77d60a1a5a3454d3968
blob + a40cf91ec22f638f9c030aa7128d10bf75748305
--- share/man/man4/Makefile
+++ share/man/man4/Makefile
@@ -35,7 +35,8 @@ MAN=  aac.4 abcrtc.4 abl.4 ac97.4 acphy.4 acrtc.4 \
eso.4 ess.4 et.4 etherip.4 etphy.4 ex.4 exphy.4 exrtc.4 \
fanpwr.4 fd.4 fdc.4 fec.4 fido.4 fins.4 fintek.4 fms.4 fusbtc.4 \
fuse.4 fxp.4 \
-   gdt.4 gentbi.4 gem.4 gfrtc.4 gif.4 glenv.4 glkgpio.4 gpio.4 gpiodcf.4 \
+   gdt.4 gentbi.4 gem.4 gfrtc.4 gif.4 glenv.4 glkgpio.4 gpio.4 \
+   gpiocharger.4 gpiodcf.4 \
gpioiic.4 gpioleds.4 gpioow.4 graphaudio.4 gre.4 gscsio.4 \
hds.4 hiclock.4 hidwusb.4 hifn.4 hil.4 hilid.4 hilkbd.4 hilms.4 \
hireset.4 hitemp.4 hme.4 hotplug.4 hsq.4 \
blob - /dev/null
blob + 12aa353d9367f57f07a89ae30dc3966c373032f8 (mode 644)
--- /dev/null
+++ share/man/man4/gpiocharger.4
@@ -0,0 +1,51 @@
+.\"$OpenBSD: $
+.\"
+.\" Copyright (c) 2021 Klemens Nanni 
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd $Mdocdate: September 04 2021 $
+.Dt GPIOCHARGER 4
+.Os
+.Sh NAME
+.Nm gpiocharger
+.Nd GPIO battery charger
+.Sh SYNOPSIS
+.Cd "gpiocharger* at fdt?"
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for battery chargers connected to GPIO pins.
+Currently, only power supply status events are supported.
+.Pp
+The power supply status (connected or disconnected) is set up as a sensor
+and can be monitored using
+.Xr sysctl 8
+or
+.Xr sensorsd 8 .
+.Sh SEE ALSO
+.Xr gpio 4 ,
+.Xr intro 4 ,
+.Xr sensorsd 8 ,
+.Xr sysctl 8
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Ox 7.0 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+driver was written by
+.An Klemens Nanni Aq Mt k...@openbsd.org .
blob - d3c3afb621f20013dc2475b4d87bd959e4127c9d
blob + b0702181cd2e510ef5267460dc71b68a8abd508a
--- sys/arch/arm64/conf/GENERIC
+++ sys/arch/arm64/conf/GENERIC
@@ -132,6 +132,7 @@ drm*at amdgpu?
 wsdisplay* at amdgpu?
 
 gpioleds*  at fdt?
+gpiocharger*   at fdt?
 
 # Apple
 apldart*   at fdt?
blob - f749803b07408179ddc090d484ed4f79bfcb52a7
blob + f91263405dc183dd60e8ddc1fe69c5fbaf38b651
--- sys/dev/fdt/files.fdt
+++ sys/dev/fdt/files.fdt
@@ -592,3 +592,7 @@ filedev/fdt/dapmic.cdapmic
 device gpioleds
 attach gpioleds at fdt
 file   dev/fdt/gpioleds.c  gpioleds
+
+device gpiocharger
+attach gpiocharger at fdt
+file   dev/fdt/gpiocharger.c   gpiocharger
blob - /dev/null
blob + dbf6bf50a13029438b9b7e969306c34640c5747e (mode 644)
--- /dev/null
+++ sys/dev/fdt/gpiocharger.c
@@ -0,0 +1,116 @@
+/* $OpenBSD: $ */
+/*
+ * Copyright (c) 2021 Klemens Nanni 
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+struct gpiocharger_softc {
+ 

Re: iked(8): make proto option accept lists

2021-09-04 Thread Sebastian Benoit
Tobias Heider(tobias.hei...@stusta.de) on 2021.09.04 12:39:26 +0200:
> Here's an updated diff including the man page bits.

I don't want to bikeshed the manpage. The code is ok benno@ :)

> Looking at pf.conf(5)
> and ipsec.conf(5), there does not really seem to be a standard way to document
> which parameters accept lists.

This is because the both parsers define "lists" as "duplicate the rules for
all combinations".

The parsers of other programs (like bgpd, ospfd or relayd) have more
elaborate language constructs where simple expansion by duplicating the
line/rule is not sensible. This also applies to iked.

So i think one should look at those daemons and document the fact
that a specific keyword takes a { ... } list as argument, like this:

diff --git sbin/iked/iked.conf.5 sbin/iked/iked.conf.5
index df1a0f09442..6d8cb47cdbe 100644
--- sbin/iked/iked.conf.5
+++ sbin/iked/iked.conf.5
@@ -354,7 +354,13 @@ Note that this only matters for IKEv2 endpoints and does 
not
 restrict the traffic selectors to negotiate flows with different
 address families, e.g. IPv6 flows negotiated by IPv4 endpoints.
 .Pp
-.It Ic proto Ar protocol
+.It Xo
+.Ic proto Ar protocol
+.Xc
+.It Xo
+.Ic proto
+.Ic { Ar protocol ... Ic }
+.Xc
 The optional
 .Ic proto
 parameter restricts the flow to a specific IP protocol.
@@ -368,6 +374,14 @@ For a list of all the protocol name to number mappings 
used by
 see the file
 .Pa /etc/protocols .
 .Pp
+Multiple
+.Ar protocol
+entries can be specified, separated by commas or whitespace,
+if enclosed in curly brackets:
+.Bd -literal -offset indent
+proto { tcp, udp }
+.Ed
+.Pp
 .It Ic rdomain Ar number
 Specify a different routing domain for unencrypted traffic.
 The resulting IPsec SAs will match outgoing packets in the specified

Search for "Multiple" in bgpd.conf for more examples.

I CC jmc@, maybe he wants to help with the manpage.

> 
> Index: iked.conf.5
> ===
> RCS file: /cvs/src/sbin/iked/iked.conf.5,v
> retrieving revision 1.86
> diff -u -p -r1.86 iked.conf.5
> --- iked.conf.5   3 Aug 2021 12:46:30 -   1.86
> +++ iked.conf.5   4 Sep 2021 09:54:55 -
> @@ -93,6 +93,16 @@ keyword, for example:
>  .Bd -literal -offset indent
>  include "/etc/macros.conf"
>  .Ed
> +.Pp
> +Certain parameters can be expressed as lists, in which case
> +.Xr iked 8
> +generates all the necessary flow combinations.
> +For example:
> +.Bd -literal -offset indent
> +ikev2 esp proto { tcp, udp } \e
> + from 192.168.1.1 to 10.0.0.18 \e
> + peer 192.168.10.1
> +.Ed
>  .Sh MACROS
>  Macros can be defined that will later be expanded in context.
>  Macro names must start with a letter, digit, or underscore,
> Index: iked.h
> ===
> RCS file: /cvs/src/sbin/iked/iked.h,v
> retrieving revision 1.193
> diff -u -p -r1.193 iked.h
> --- iked.h1 Sep 2021 15:30:06 -   1.193
> +++ iked.h4 Sep 2021 09:54:55 -
> @@ -242,10 +242,9 @@ struct iked_policy {
>  
>  #define IKED_SKIP_FLAGS   0
>  #define IKED_SKIP_AF  1
> -#define IKED_SKIP_PROTO   2
> -#define IKED_SKIP_SRC_ADDR3
> -#define IKED_SKIP_DST_ADDR4
> -#define IKED_SKIP_COUNT   5
> +#define IKED_SKIP_SRC_ADDR2
> +#define IKED_SKIP_DST_ADDR3
> +#define IKED_SKIP_COUNT   4
>   struct iked_policy  *pol_skip[IKED_SKIP_COUNT];
>  
>   uint8_t  pol_flags;
> @@ -265,7 +264,8 @@ struct iked_policy {
>   int  pol_af;
>   int  pol_rdomain;
>   uint8_t  pol_saproto;
> - unsigned int pol_ipproto;
> + unsigned int pol_ipproto[IKED_IPPROTO_MAX];
> + unsigned int pol_nipproto;
>  
>   struct iked_addr pol_peer;
>   struct iked_static_idpol_peerid;
> Index: parse.y
> ===
> RCS file: /cvs/src/sbin/iked/parse.y,v
> retrieving revision 1.131
> diff -u -p -r1.131 parse.y
> --- parse.y   28 May 2021 18:01:39 -  1.131
> +++ parse.y   4 Sep 2021 09:54:55 -
> @@ -374,7 +374,7 @@ void   copy_transforms(unsigned int,
>   const struct ipsec_xf **, unsigned int,
>   struct iked_transform **, unsigned int *,
>   struct iked_transform *, size_t);
> -int   create_ike(char *, int, uint8_t,
> +int   create_ike(char *, int, struct ipsec_addr_wrap *,
>   int, struct ipsec_hosts *,
>   struct ipsec_hosts *, struct ipsec_mode *,
>   struct ipsec_mode *, uint8_t,
> @@ -388,9 +388,9 @@ 

Re: update to tcpdump(8)

2021-09-04 Thread Denis Fondras
Le Thu, Sep 02, 2021 at 08:36:06AM -0600, Theo de Raadt a écrit :
> I think the following approach will work.
> 
> 1. changes from tcpdump.8 -r1.00 to -rHEAD need merging into pcap-filter.5
> 

Here is a diff for this step.

I have one question though.

tcpdump.8 has :
" tcpdump does not currently know how to parse lat, moprc, or mopdl.  "

while pcap-filter.5 has :
" Note that not all applications using pcap_open_live(3) currently know how to
parse these protocols. "

Should I mention explicitely tcpdump(8) in pcap-filter.5 ? It seems implicit in
the current version.

Index: pcap-filter.5
===
RCS file: /cvs/src/lib/libpcap/pcap-filter.5,v
retrieving revision 1.9
diff -u -p -r1.9 pcap-filter.5
--- pcap-filter.5   2 Sep 2021 10:59:13 -   1.9
+++ pcap-filter.5   4 Sep 2021 17:04:36 -
@@ -40,27 +40,31 @@ or
 .Pp
 The filter expression consists of one or more
 .Em primitives .
-Primitives usually consist of an ID (name or number)
+Primitives usually consist of an
+.Ar id
+.Pq name or number
 preceded by one or more qualifiers.
 There are three different kinds of qualifier:
 .Bl -tag -width "proto"
-.It type
-Type qualifiers say what kind of thing the ID name or number refers to.
+.It Ar type
+Specify which kind of address component the
+.Ar id
+name or number refers to.
 Possible types are
 .Cm host ,
-.Cm net ,
+.Cm net
 and
 .Cm port .
-For example,
+E.g.,
 .Dq host foo ,
 .Dq net 128.3 ,
-and
 .Dq port 20 .
 If there is no type qualifier,
 .Cm host
 is assumed.
-.It dir
-Dir qualifiers specify a particular transfer direction to and/or from an ID.
+.It Ar dir
+Specify a particular transfer direction to and/or from
+.Ar id .
 Possible directions are
 .Cm src ,
 .Cm dst ,
@@ -73,11 +77,13 @@ Possible directions are
 .Cm addr3 ,
 and
 .Cm addr4 .
-For example,
-.Cm src foo ,
-.Cm dst net 128.3 ,
-.Cm src or dst port ftp-data .
-If there is no dir qualifier,
+E.g.,
+.Dq src foo ,
+.Dq dst net 128.3 ,
+.Dq src or dst port ftp-data .
+If there is no
+.Ar dir
+qualifier,
 .Cm src or dst
 is assumed.
 The
@@ -89,55 +95,83 @@ The
 and
 .Cm addr4
 qualifiers are only valid for IEEE 802.11 Wireless LAN link layers.
-For some link layers, such as SLIP and the "cooked" Linux capture mode
-used for the "any" device and for some other device types, the
+For null link layers (i.e., point-to-point protocols such as SLIP
+.Pq Serial Line Internet Protocol
+or the
+.Xr pflog 4
+header), the
 .Cm inbound
 and
 .Cm outbound
 qualifiers can be used to specify a desired direction.
-.It proto
+.It Ar proto
 Proto qualifiers restrict the match to a particular protocol.
 Possible
-protos are:
+protocols are:
+.Cm ah ,
+.Cm arp ,
+.Cm atalk ,
+.Cm decnet ,
+.Cm esp ,
 .Cm ether ,
 .Cm fddi ,
-.Cm tr ,
-.Cm wlan ,
+.Cm icmp ,
+.Cm icmp6 ,
+.Cm igmp ,
+.Cm igrp ,
 .Cm ip ,
 .Cm ip6 ,
-.Cm arp ,
+.Cm lat ,
+.Cm mopdl ,
+.Cm moprc ,
+.Cm pim ,
 .Cm rarp ,
-.Cm decnet ,
+.Cm sca ,
+.Cm stp ,
 .Cm tcp ,
+.Cm udp ,
 and
-.Cm udp .
-For example,
+.Cm wlan .
+E.g.,
 .Dq ether src foo ,
 .Dq arp net 128.3 ,
 .Dq tcp port 21 ,
 and
 .Dq wlan addr2 0:2:3:4:5:6 .
-If there is no proto qualifier,
+If there is no protocol qualifier,
 all protocols consistent with the type are assumed.
-For example,
+E.g.,
 .Dq src foo
 means
-.Dq (ip or arp or rarp) src foo
-(except the latter is not legal syntax);
+.Do
+.Pq ip or arp or rarp
+src foo
+.Dc
+.Pq except the latter is not legal syntax ;
 .Dq net bar
 means
-.Dq (ip or arp or rarp) net bar ;
+.Do
+.Pq ip or arp or rarp
+net bar
+.Dc ;
 and
 .Dq port 53
 means
-.Dq (tcp or udp) port 53 .
+.Do
+.Pq TCP or UDP
+port 53
+.Dc .
 .Pp
 .Cm fddi
 is actually an alias for
 .Cm ether ;
 the parser treats them identically as meaning
-"the data link level used on the specified network interface".
-FDDI headers contain Ethernet-like source and destination addresses,
+.Qo
+the data link level used on the specified network interface
+.Qc .
+FDDI
+.Pq Fiber Distributed Data Interface
+headers contain Ethernet-like source and destination addresses,
 and often contain Ethernet-like packet types,
 so it's possible to filter these FDDI fields just as with the analogous 
Ethernet fields.
 FDDI headers also contain other fields,
@@ -156,8 +190,8 @@ and the source address is the SA field;
 the BSSID, RA, and TA fields aren't tested.
 .El
 .Pp
-In addition to the above,
-there are some special primitives that don't follow the pattern:
+In addition to the above, there are some special primitive
+keywords that don't follow the pattern:
 .Cm gateway ,
 .Cm broadcast ,
 .Cm less ,
@@ -171,13 +205,17 @@ More complex filter expressions are buil
 and
 .Cm not
 to combine primitives.
-For example,
-.Dq host foo and not port ftp and not port ftp-data .
-To save typing, identical qualifier lists can be omitted,
-so that
+e.g.,
+.Do
+host foo and not port ftp and not port ftp-data
+.Dc .
+To save typing, identical qualifier lists can be omitted
+e.g.,
 

Re: ksh: add support for bracketed paste mode

2021-09-04 Thread Sören Tempel
Ping.

I've been using the patched the last ~6 months and didn't encounter any
problems with it. If there is no interested in bracketed paste mode or
if the design needs to be revised in general, please let me know. Below
is a slightly updated version of this patch which should fix the build
without -DEMACS.

Greetings,
Sören

diff --git edit.c edit.c
index 3089d195d20..cef7949b88d 100644
--- edit.c
+++ edit.c
@@ -150,12 +150,28 @@ x_puts(const char *s)
shf_putc(*s++, shl_out);
 }
 
+#ifdef EMACS
+static void
+x_paste_mode(bool onoff)
+{
+   if (!Flag(FBBRACKETPASTE))
+   return;
+
+   printf((onoff) ? BRPASTE_INT : BRPASTE_DEINT);
+   fflush(stdout);
+}
+#endif
+
 bool
 x_mode(bool onoff)
 {
static bool x_cur_mode;
boolprev;
 
+#ifdef EMACS
+   x_paste_mode(onoff);
+#endif
+
if (x_cur_mode == onoff)
return x_cur_mode;
prev = x_cur_mode;
diff --git edit.h edit.h
index 0b604cd64fb..8cc774f01dd 100644
--- edit.h
+++ edit.h
@@ -34,6 +34,12 @@ extern X_chars edchars;
 #define XCF_FULLPATH   BIT(2)  /* command completion: store full path */
 #define XCF_COMMAND_FILE (XCF_COMMAND|XCF_FILE)
 
+/* https://www.xfree86.org/4.7.0/ctlseqs.html#Bracketed%20Paste%20Mode */
+#define BRPASTE_INT"\033[?2004h"
+#define BRPASTE_DEINT  "\033[?2004l"
+#define BRPASTE_PREkb_encode("^[[200~")
+#define BRPASTE_POST   kb_encode("^[[201~")
+
 /* edit.c */
 intx_getc(void);
 void   x_flush(void);
diff --git emacs.c emacs.c
index 1a5ff6e9927..f4d369fbc38 100644
--- emacs.c
+++ emacs.c
@@ -118,6 +118,7 @@ static  char*xmp;   /* mark pointer */
 static char*killstack[KILLSIZE];
 static int killsp, killtp;
 static int x_literal_set;
+static int x_brack_paste;
 static int x_arg_set;
 static char*macro_args;
 static int prompt_skip;
@@ -203,6 +204,8 @@ static int  x_fold_lower(int);
 static int x_fold_upper(int);
 static int x_set_arg(int);
 static int x_comment(int);
+static int x_brack_paste_start(int);
+static int x_brack_paste_end(int);
 #ifdef DEBUG
 static int x_debug_info(int);
 #endif
@@ -260,6 +263,8 @@ static const struct x_ftab x_ftab[] = {
{ x_fold_upper, "upcase-word",  XF_ARG },
{ x_set_arg,"set-arg",  XF_NOBIND },
{ x_comment,"comment",  0 },
+   { x_brack_paste_start,  "bracketed-paste-start",0 },
+   { x_brack_paste_end,"bracketed-paste-end",  0 },
{ 0, 0, 0 },
 #ifdef DEBUG
{ x_debug_info, "debug-info",   0 },
@@ -316,6 +321,8 @@ x_emacs(char *buf, size_t len)
}
 
x_literal_set = 0;
+   x_brack_paste = 0;
+
x_arg = -1;
x_last_command = NULL;
while (1) {
@@ -353,6 +360,13 @@ x_emacs(char *buf, size_t len)
}
}
 
+   /* In bracketed paste mode only allow x_brack_paste_end,
+* to quit this mode, for all other commands insert a literal. 
*/
+   if (x_brack_paste && (submatch == 1 && kmatch)) {
+   if (kmatch->ftab->xf_func != x_brack_paste_end)
+   submatch = 0;
+   }
+
if (submatch == 1 && kmatch) {
if (kmatch->ftab->xf_func == x_ins_string &&
kmatch->args && !macro_args) {
@@ -1479,6 +1493,10 @@ x_init_emacs(void)
 
TAILQ_INIT();
 
+   /* bracketed paste mode */
+   kb_add_string(x_brack_paste_start,  NULL, BRPASTE_PRE);
+   kb_add_string(x_brack_paste_end,NULL, BRPASTE_POST);
+
/* man page order */
kb_add(x_abort, CTRL('G'), 0);
kb_add(x_mv_back,   CTRL('B'), 0);
@@ -1991,6 +2009,21 @@ x_comment(int c)
return KSTD;
 }
 
+int
+x_brack_paste_start(int c)
+{
+   if (Flag(FBBRACKETPASTE))
+   x_brack_paste = 1;
+   return KSTD;
+}
+
+int
+x_brack_paste_end(int c)
+{
+   if (Flag(FBBRACKETPASTE))
+   x_brack_paste = 0;
+   return KSTD;
+}
 
 /* NAME:
  *  x_prev_histword - recover word from prev command
diff --git misc.c misc.c
index 672b5416419..392aa49b990 100644
--- misc.c
+++ misc.c
@@ -123,6 +123,9 @@ const struct option sh_options[] = {
 */
{ "allexport",  'a',OF_ANY },
{ "braceexpand",  0,OF_ANY }, /* non-standard */
+#ifdef EMACS
+   { "bracket-paste", 0,   OF_ANY }, /* non-standard */
+#endif
{ "bgnice",   0,OF_ANY },
{ NULL, 'c',OF_CMDLINE },
{ "csh-history",  0,OF_ANY }, /* non-standard */
diff --git sh.h sh.h
index 93beef31d46..652a1f6dd06 100644
--- sh.h
+++ sh.h
@@ -134,6 +134,9 @@ extern const struct option sh_options[];
 enum sh_flag {
FEXPORT 

Re: timeout: Prettify man page and usage

2021-09-04 Thread Ingo Schwarze
Hi Jason,

Jason McIntyre wrote on Fri, Sep 03, 2021 at 02:46:47PM +0100:
> On Fri, Sep 03, 2021 at 03:42:21PM +0200, Ingo Schwarze wrote:
>> Theo de Raadt wrote on Thu, Sep 02, 2021 at 09:57:11AM -0600:

>>> I think we should list shorts, and longs which have no shorts.

>> I agree, and i think we arrived at the same conclusion in the past.
>> 
>> It applies to both usage() and SYNOPSIS, and ideally, both should
>> match, except maybe in very unusual cases.

> sure. but grep tripped me up, and it's always the page i think of with
> long options. why did we leave --context in SYNOPSIS?

I admit the grep(1) case is slightly confusing, but it is explained
here why it is somewhat special:

  https://cvsweb.openbsd.org/src/usr.bin/grep/grep.1#rev1.47

Yours,
  Ingo



Re: iked(8): make proto option accept lists

2021-09-04 Thread Tobias Heider
Here's an updated diff including the man page bits.  Looking at pf.conf(5)
and ipsec.conf(5), there does not really seem to be a standard way to document
which parameters accept lists.

Index: iked.conf.5
===
RCS file: /cvs/src/sbin/iked/iked.conf.5,v
retrieving revision 1.86
diff -u -p -r1.86 iked.conf.5
--- iked.conf.5 3 Aug 2021 12:46:30 -   1.86
+++ iked.conf.5 4 Sep 2021 09:54:55 -
@@ -93,6 +93,16 @@ keyword, for example:
 .Bd -literal -offset indent
 include "/etc/macros.conf"
 .Ed
+.Pp
+Certain parameters can be expressed as lists, in which case
+.Xr iked 8
+generates all the necessary flow combinations.
+For example:
+.Bd -literal -offset indent
+ikev2 esp proto { tcp, udp } \e
+   from 192.168.1.1 to 10.0.0.18 \e
+   peer 192.168.10.1
+.Ed
 .Sh MACROS
 Macros can be defined that will later be expanded in context.
 Macro names must start with a letter, digit, or underscore,
Index: iked.h
===
RCS file: /cvs/src/sbin/iked/iked.h,v
retrieving revision 1.193
diff -u -p -r1.193 iked.h
--- iked.h  1 Sep 2021 15:30:06 -   1.193
+++ iked.h  4 Sep 2021 09:54:55 -
@@ -242,10 +242,9 @@ struct iked_policy {
 
 #define IKED_SKIP_FLAGS 0
 #define IKED_SKIP_AF1
-#define IKED_SKIP_PROTO 2
-#define IKED_SKIP_SRC_ADDR  3
-#define IKED_SKIP_DST_ADDR  4
-#define IKED_SKIP_COUNT 5
+#define IKED_SKIP_SRC_ADDR  2
+#define IKED_SKIP_DST_ADDR  3
+#define IKED_SKIP_COUNT 4
struct iked_policy  *pol_skip[IKED_SKIP_COUNT];
 
uint8_t  pol_flags;
@@ -265,7 +264,8 @@ struct iked_policy {
int  pol_af;
int  pol_rdomain;
uint8_t  pol_saproto;
-   unsigned int pol_ipproto;
+   unsigned int pol_ipproto[IKED_IPPROTO_MAX];
+   unsigned int pol_nipproto;
 
struct iked_addr pol_peer;
struct iked_static_idpol_peerid;
Index: parse.y
===
RCS file: /cvs/src/sbin/iked/parse.y,v
retrieving revision 1.131
diff -u -p -r1.131 parse.y
--- parse.y 28 May 2021 18:01:39 -  1.131
+++ parse.y 4 Sep 2021 09:54:55 -
@@ -374,7 +374,7 @@ void copy_transforms(unsigned int,
const struct ipsec_xf **, unsigned int,
struct iked_transform **, unsigned int *,
struct iked_transform *, size_t);
-int create_ike(char *, int, uint8_t,
+int create_ike(char *, int, struct ipsec_addr_wrap *,
int, struct ipsec_hosts *,
struct ipsec_hosts *, struct ipsec_mode *,
struct ipsec_mode *, uint8_t,
@@ -388,9 +388,9 @@ uint8_t  x2i(unsigned char *);
 int parsekey(unsigned char *, size_t, struct iked_auth *);
 int parsekeyfile(char *, struct iked_auth *);
 voidiaw_free(struct ipsec_addr_wrap *);
-static int  create_flow(struct iked_policy *pol, struct 
ipsec_addr_wrap *ipa,
+static int  create_flow(struct iked_policy *pol, int, struct 
ipsec_addr_wrap *ipa,
struct ipsec_addr_wrap *ipb);
-static int  expand_flows(struct iked_policy *, struct 
ipsec_addr_wrap *,
+static int  expand_flows(struct iked_policy *, int, struct 
ipsec_addr_wrap *,
struct ipsec_addr_wrap *);
 static struct ipsec_addr_wrap *
 expand_keyword(struct ipsec_addr_wrap *);
@@ -407,7 +407,6 @@ typedef struct {
uint8_t  ikemode;
uint8_t  dir;
uint8_t  satype;
-   uint8_t  proto;
char*string;
uint16_t port;
struct ipsec_hosts  *hosts;
@@ -415,6 +414,7 @@ typedef struct {
struct ipsec_addr_wrap  *anyhost;
struct ipsec_addr_wrap  *host;
struct ipsec_addr_wrap  *cfg;
+   struct ipsec_addr_wrap  *proto;
struct {
char*srcid;
char*dstid;
@@ -449,8 +449,7 @@ typedef struct {
 %token   NUMBER
 %typestring
 %typesatype
-%type proto
-%typeprotoval
+%type proto proto_list 

riscv64: icache flush using sysarch(2)

2021-09-04 Thread Jeremie Courreges-Anglas


The first problem I was able to diagnose using egdb on riscv was
lang/python/2.7 using libffi and aborting in libcompiler-rt (the
compilerrt_abort() call below).

--8<--
#elif defined(__riscv) && defined(__linux__)
#define __NR_riscv_flush_icache (244 + 15)
  register void *start_reg __asm("a0") = start;
  const register void *end_reg __asm("a1") = end;
  const register long flags __asm("a2") = 0;
  const register long syscall_nr __asm("a7") = __NR_riscv_flush_icache;
  __asm __volatile("ecall"
   : "=r"(start_reg)
   : "r"(start_reg), "r"(end_reg), "r"(flags), "r"(syscall_nr));
  assert(start_reg == 0 && "Cache flush syscall failed.");
#else
#if __APPLE__
  // On Darwin, sys_icache_invalidate() provides this functionality
  sys_icache_invalidate(start, end - start);
#else
  compilerrt_abort();
#endif
#endif
}
-->8--

The ususal way we provide this functionality is through sysarch(2).
Since the RISC-V ISA only provides fence.i as an extension, and that
fence.i doesn't support parameters to only act on a specific range,
I figured I would reflect that in the API for the sake of clarity.

If people expect the spec to evolve and new CPUs to ship with
support for finer-grained invalidation, a more forward-looking approach
would be to mimic ARM_SYNC_ICACHE and struct arm_sync_icache_args, and
let the kernel ignore the parameters if appropriate.

In the diff below I'm moving the core of the code to cpu.c since it
doesn't look pmap-specific, but I don't feel strongly about it.
I haven't even built this since I'm still on the way back from k2k21 but
I figured I'd ask for feedback early.  Input welcome.


Index: include/cpufunc.h
===
RCS file: /d/cvs/src/sys/arch/riscv64/include/cpufunc.h,v
retrieving revision 1.4
diff -u -p -r1.4 cpufunc.h
--- include/cpufunc.h   18 May 2021 09:14:49 -  1.4
+++ include/cpufunc.h   4 Sep 2021 08:58:38 -
@@ -92,6 +92,7 @@ extern int64_t icache_line_size;
 extern void (*cpu_dcache_wbinv_range)(paddr_t, psize_t);
 extern void (*cpu_dcache_inv_range)(paddr_t, psize_t);
 extern void (*cpu_dcache_wb_range)(paddr_t, psize_t);
+extern void icache_flush(void);
 
 static __inline void
 load_satp(uint64_t val)
Index: include/sysarch.h
===
RCS file: include/sysarch.h
diff -N include/sysarch.h
--- /dev/null   1 Jan 1970 00:00:00 -
+++ include/sysarch.h   4 Sep 2021 09:12:53 -
@@ -0,0 +1,38 @@
+/* $OpenBSD$   */
+
+/*
+ * Copyright (c) 2021 Jeremie Courreges-Anglas 
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef_RISCV64_SYSARCH_H_
+#define_RISCV64_SYSARCH_H_
+
+/*
+ * Architecture specific syscalls (riscv64)
+ */
+
+#defineRISCV_SYNC_ICACHE_ALL   0
+
+#ifndef _KERNEL
+
+#include 
+
+__BEGIN_DECLS
+intsysarch(int, void *);
+__END_DECLS
+
+#endif /* _KERNEL */
+
+#endif /* _RISCV64_SYSARCH_H_ */
Index: riscv64/cpu.c
===
RCS file: /d/cvs/src/sys/arch/riscv64/riscv64/cpu.c,v
retrieving revision 1.11
diff -u -p -r1.11 cpu.c
--- riscv64/cpu.c   24 Jul 2021 18:15:13 -  1.11
+++ riscv64/cpu.c   4 Sep 2021 09:02:09 -
@@ -26,6 +26,7 @@
 
 #include 
 
+#include 
 #include 
 #include 
 
@@ -300,6 +301,38 @@ cpu_cache_nop_range(paddr_t pa, psize_t 
 void (*cpu_dcache_wbinv_range)(paddr_t, psize_t) = cpu_cache_nop_range;
 void (*cpu_dcache_inv_range)(paddr_t, psize_t) = cpu_cache_nop_range;
 void (*cpu_dcache_wb_range)(paddr_t, psize_t) = cpu_cache_nop_range;
+
+void
+icache_flush(void)
+{
+#ifdef MULTIPROCESSOR
+   CPU_INFO_ITERATOR cii;
+   struct cpu_info *ci;
+   unsigned long hart_mask = 0;
+#endif
+
+   fence_i();
+
+#ifdef MULTIPROCESSOR
+   CPU_INFO_FOREACH(cii, ci) {
+   if (ci == curcpu())
+   continue;
+   hart_mask |= (1UL << ci->ci_hartid);
+   }
+
+   /*
+* From the RISC-V ISA:
+*
+* To make a store to instruction memory visible to all RISC-V
+* harts, the writing hart has to execute a data FENCE before
+* requesting that all remote RISC-V harts execute a FENCE.I.
+*/
+   if 

ASan checkpoint

2021-09-04 Thread Greg Steuck
My aspiration for k2k21 was to get ASan working on OpenBSD. The
following is a dump of the current state and questions about future
directions.

There are roughly two parts to ASan, the compiler instrumentation and
the runtime library. The instrumentation is likely much less system
dependent than the runtime.  There was an unfinished porting attempt in
LLVM tree and a cleanroom libasan runtime by ori@.

Ori had simple programs correctly detect the problems using his
library. Building such programs required a somewhat careful linker
invocation. My first task was to reduce friction in building such
programs. With a lot of help from people in the hackroom we prepared an
LLVM patch[0] with a variation landed[1] in src.

This got me to the point of at least partially reproducing Ori's results
on trivial programs with a simpler clang command line (-fsanitizer is
all you need once the library is in place).

Unfortunately, I couldn't get more complicated programs, like those
using getaddrinfo(3) to work. They crash with a free(): bogus pointer.
I suspected more instrumentation was required and further realized that
there is a major amount of work that went into the original LLVM ASan
runtime. In particular, ASan reports are very usable and actionable.
This does come with extra complexity and more code. Yet, since we looked
last at the tradeoff of developing a cleanroom implementation, some
things have changed. Namely, OpenBSD tree now carries ASan source.  We
might as well try to use it.

This brings me to the second part of this hackathon. Building LLVM ASan
runtime required some sleuthing. In the end, this is enough to get the
builds going after adding some tweaks[2]:

  mkdir build
  cd build
  cmake -G "Unix Makefiles"  -DLLVM_ENABLE_PROJECTS='compiler-rt;clang' ../llvm
  gmake asan
  for i in lib/clang/11.1.0/lib/openbsd/libclang_rt.asan*-x86_64.a; do
p=$(basename $i)
doas install $i /usr/lib/clang/11.1.0/lib/${p%-x86_64.a}.a
  done

A simple program can now be built with these libraries. Sadly, they hang
before hitting main. The reason is mmap interposing is not currently
done correctly. The program is spinning in

  #0  mmap ()
  at 
llvm/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:7181
  #1  0x00694511c368 in MmapNamed ()
  at llvm/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp:389
  #2  MmapOrDie () at 
llvm/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp:46
  #3  0x0069451113cb in Allocate ()
  at llvm/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp:218
  #4  0x006945118594 in __sanitizer::FlagParser::FlagParser() ()
  at llvm/compiler-rt/lib/sanitizer_common/sanitizer_flag_parser.cpp:188

This brings me to the "what's next" part. Obviously the mmap
interception needs to be fixed to get anywhere. MmapNamed invokes
internal_mmap which is defined in sanitizer_openbsd.cpp as:

uptr internal_mmap(void *addr, size_t length, int prot, int flags, int fd,
   u64 offset) {
  return (uptr)mmap(addr, length, prot, flags, fd, offset);
}

This sadly can't work because mmap in sanitizer_common_interceptors.inc
calls internal_mmap if !asan_inited and hence the endless
recursion. Other systems have alternative ways of reaching the original
libc mmap. E.g. directly calling mmap syscall in sanitizer_linux.cpp or
calling __mmap in sanitizer_netbsd.cpp. Neither of these seems to be
available on OpenBSD. So, what can we do to interpose mmap?

Thanks
Greg

[0] https://reviews.llvm.org/D109051
[1] 
https://github.com/openbsd/src/commit/0b99cc4d5d8311a90145e8f4c6ae23275c275c52
[2] 
https://github.com/blackgnezdo/llvm-project/commit/cd697c9c442380c4ed01c21f52b3fea7671ed644