Re: smtpd: add support for cidr in hostname resolution for spf walk

2019-11-23 Thread Quentin Rameau
> Hello

Hi Eric,

> > Hello,
> > 
> > Here's a patch for smtpctl spf resolution, adding support for target
> > specified as a hostname + cidr.
> > 
> > Yes, SPF lets you specify targets like a:example.com/24.
> > 
> > Due to the async and recursive nature of DNS resolution in spfwalk.c,
> > it's kind of hard to pass data around without too much memory
> > allocation, so I decided to just pass cidr(s) as integer value instead
> > of keeping the original string and passing pointers around.
> > 
> > Comments welcome, thanks!  
> 
> I find it confusing that everything is stuffed into the sender struct,
> including the callback.  I don't really see the point. If you don't
> need to pass the target value over to the callback, there is no need
> to have it in the struct either, especially since the pointer is only
> valid at the time you call the lookup function.

Indeed, passing the target around isn't strictly needed, this is rather
a leftover from a previous implementation were both CIDRs were string
pointers pointing to the target.
 
> Another point, I don't understand how the parse_sender() function is
> supposed to work. Can you give examples with cidr4 and cidr6?

Per the SPF RFC[0], the "a" and "mx" mechanism can have an IPv4 cidr,
or an IPv6 cidr, or both like “a:example.com/24”, “a:example.com//64”,
or “a:example.com/24/64” which specifies both cidr for the IPv4 and cidr
for the IPv6 resolutions of the name.

And yes, those are actually used out there, like by my bank company.

So the function parses the target for a "/cidr4" and strtonum() it to
cidr4, then parses for another "/cidr6" and strtonum() to cidr6.

[0] https://tools.ietf.org/rfc/rfc7208.txt

Here's an updated patch, plus two independant fixes for smtpd.h
(missing header limits.h for PATH_MAX and imsg.h for img structure).

struct sender target removed
smtpd.h header added for xmalloc()
fixed parse_sender for CIDRs like "//num".

Index: usr.sbin/smtpd/smtpd.h
===
RCS file: /var/cvs/src/usr.sbin/smtpd/smtpd.h,v
retrieving revision 1.642
diff -u -r1.642 smtpd.h
--- usr.sbin/smtpd/smtpd.h  3 Nov 2019 23:58:51 -   1.642
+++ usr.sbin/smtpd/smtpd.h  23 Nov 2019 20:19:17 -
@@ -22,6 +22,8 @@
 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
 #endif
 
+#include 
+#include 
 #include 
 #include 
 #include 
Index: usr.sbin/smtpd/spfwalk.c
===
RCS file: /var/cvs/src/usr.sbin/smtpd/spfwalk.c,v
retrieving revision 1.15
diff -u -r1.15 spfwalk.c
--- usr.sbin/smtpd/spfwalk.c11 Nov 2019 17:20:25 -  1.15
+++ usr.sbin/smtpd/spfwalk.c23 Nov 2019 21:13:11 -
@@ -35,20 +35,28 @@
 #include 
 
 #define LINE_MAX 1024
+#include "smtpd.h"
 #include "smtpd-defines.h"
 #include "smtpd-api.h"
 #include "unpack_dns.h"
 #include "parser.h"
 
+struct sender {
+   void(*cb)(struct dns_rr *, struct sender *);
+   int   cidr4;
+   int   cidr6;
+};
+
 int spfwalk(int, struct parameter *);
 
-static voiddispatch_txt(struct dns_rr *);
-static voiddispatch_mx(struct dns_rr *);
-static voiddispatch_a(struct dns_rr *);
-static voiddispatch_(struct dns_rr *);
-static voidlookup_record(int, const char *, void (*)(struct dns_rr *));
+static voiddispatch_txt(struct dns_rr *, struct sender *);
+static voiddispatch_mx(struct dns_rr *, struct sender *);
+static voiddispatch_a(struct dns_rr *, struct sender *);
+static voiddispatch_(struct dns_rr *, struct sender *);
+static voidlookup_record(int, const char *, struct sender *);
 static voiddispatch_record(struct asr_result *, void *);
 static ssize_t parse_txt(const char *, size_t, char *, size_t);
+static int parse_sender(char *, struct sender *);
 
 int ip_v4 = 0;
 int ip_v6 = 0;
@@ -59,6 +67,7 @@
 int
 spfwalk(int argc, struct parameter *argv)
 {
+   struct sendersdr;
const char  *ip_family = NULL;
char*line = NULL;
size_t   linesize = 0;
@@ -81,12 +90,15 @@
dict_init();
event_init();
 
+   sdr.cidr4 = sdr.cidr6 = -1;
+   sdr.cb = dispatch_txt;
+
while ((linelen = getline(, , stdin)) != -1) {
while (linelen-- > 0 && isspace(line[linelen]))
line[linelen] = '\0';
 
if (linelen > 0)
-   lookup_record(T_TXT, line, dispatch_txt);
+   lookup_record(T_TXT, line, );
}
 
free(line);
@@ -100,20 +112,23 @@
 }
 
 void
-lookup_record(int type, const char *record, void (*cb)(struct dns_rr *))
+lookup_record(int type, const char *record, struct sender *sdr)
 {
struct asr_query *as;
+   struct sender *nsdr;
 
as = res_query_async(record, C_IN, type, NULL);
if (as == NULL)
err(1, "res_query_async");
-   event_asr_run(as, dispatch_record, cb);
+   nsdr 

Re: smtpd: add support for cidr in hostname resolution for spf walk

2019-11-23 Thread Eric Faurot
On Tue, Nov 12, 2019 at 02:16:25PM +0100, Quentin Rameau wrote:

Hello

> Hello,
> 
> Here's a patch for smtpctl spf resolution, adding support for target
> specified as a hostname + cidr.
> 
> Yes, SPF lets you specify targets like a:example.com/24.
> 
> Due to the async and recursive nature of DNS resolution in spfwalk.c,
> it's kind of hard to pass data around without too much memory
> allocation, so I decided to just pass cidr(s) as integer value instead
> of keeping the original string and passing pointers around.
> 
> Comments welcome, thanks!

I find it confusing that everything is stuffed into the sender struct,
including the callback.  I don't really see the point. If you don't
need to pass the target value over to the callback, there is no need
to have it in the struct either, especially since the pointer is only
valid at the time you call the lookup function.

Another point, I don't understand how the parse_sender() function is
supposed to work. Can you give examples with cidr4 and cidr6?

Eric.

> 
> Index: usr.sbin/smtpd/spfwalk.c
> ===
> RCS file: /var/cvs/src/usr.sbin/smtpd/spfwalk.c,v
> retrieving revision 1.15
> diff -u -r1.15 spfwalk.c
> --- usr.sbin/smtpd/spfwalk.c  11 Nov 2019 17:20:25 -  1.15
> +++ usr.sbin/smtpd/spfwalk.c  12 Nov 2019 12:43:25 -
> @@ -40,15 +40,24 @@
>  #include "unpack_dns.h"
>  #include "parser.h"
>  
> +struct sender {
> + void(*cb)(struct dns_rr *, struct sender *);
> + char *target;
> + int   cidr4;
> + int   cidr6;
> +};
> +
> +void *xmalloc(size_t);
>  int spfwalk(int, struct parameter *);
>  
> -static void  dispatch_txt(struct dns_rr *);
> -static void  dispatch_mx(struct dns_rr *);
> -static void  dispatch_a(struct dns_rr *);
> -static void  dispatch_(struct dns_rr *);
> -static void  lookup_record(int, const char *, void (*)(struct dns_rr *));
> +static void  dispatch_txt(struct dns_rr *, struct sender *);
> +static void  dispatch_mx(struct dns_rr *, struct sender *);
> +static void  dispatch_a(struct dns_rr *, struct sender *);
> +static void  dispatch_(struct dns_rr *, struct sender *);
> +static void  lookup_record(int, struct sender *);
>  static void  dispatch_record(struct asr_result *, void *);
>  static ssize_t   parse_txt(const char *, size_t, char *, size_t);
> +static int   parse_sender(struct sender *);
>  
>  int ip_v4 = 0;
>  int ip_v6 = 0;
> @@ -59,6 +68,7 @@
>  int
>  spfwalk(int argc, struct parameter *argv)
>  {
> + struct sendersdr;
>   const char  *ip_family = NULL;
>   char*line = NULL;
>   size_t   linesize = 0;
> @@ -81,12 +91,17 @@
>   dict_init();
>   event_init();
>  
> + sdr.cidr4 = sdr.cidr6 = -1;
> + sdr.cb = dispatch_txt;
> +
>   while ((linelen = getline(, , stdin)) != -1) {
>   while (linelen-- > 0 && isspace(line[linelen]))
>   line[linelen] = '\0';
>  
> - if (linelen > 0)
> - lookup_record(T_TXT, line, dispatch_txt);
> + if (linelen > 0) {
> + sdr.target = line;
> + lookup_record(T_TXT, );
> + }
>   }
>  
>   free(line);
> @@ -100,20 +115,23 @@
>  }
>  
>  void
> -lookup_record(int type, const char *record, void (*cb)(struct dns_rr *))
> +lookup_record(int type, struct sender *sdr)
>  {
>   struct asr_query *as;
> + struct sender *nsdr;
>  
> - as = res_query_async(record, C_IN, type, NULL);
> + as = res_query_async(sdr->target, C_IN, type, NULL);
>   if (as == NULL)
>   err(1, "res_query_async");
> - event_asr_run(as, dispatch_record, cb);
> + nsdr = xmalloc(sizeof(*nsdr));
> + *nsdr = *sdr;
> + event_asr_run(as, dispatch_record, (void *)nsdr);
>  }
>  
>  void
>  dispatch_record(struct asr_result *ar, void *arg)
>  {
> - void (*cb)(struct dns_rr *) = arg;
> + struct sender *sdr = arg;
>   struct unpack pack;
>   struct dns_header h;
>   struct dns_query q;
> @@ -121,7 +139,7 @@
>  
>   /* best effort */
>   if (ar->ar_h_errno && ar->ar_h_errno != NO_DATA)
> - return;
> + goto end;
>  
>   unpack_init(, ar->ar_data, ar->ar_datalen);
>   unpack_header(, );
> @@ -130,19 +148,22 @@
>   for (; h.ancount; h.ancount--) {
>   unpack_rr(, );
>   /**/
> - cb();
> + sdr->cb(, sdr);
>   }
> +end:
> + free(sdr);
>  }
>  
>  void
> -dispatch_txt(struct dns_rr *rr)
> +dispatch_txt(struct dns_rr *rr, struct sender *sdr)
>  {
> + char buf[4096];
> + char *argv[512];
> + char buf2[512];
> + struct sender lsdr;
>   struct in6_addr ina;
> -char buf[4096];
> -char buf2[512];
> -char *in = buf;
> -char *argv[512];
> -char **ap = argv;
> + char **ap = argv;
> + char *in = buf;
>   char 

utwitch(4): tsleep -> tsleep_nsec(9)

2019-11-23 Thread Scott Cheloha
Who knew we had a driver for something like this?  :)

This is a ticks -> milliseconds conversion.

ok?

Index: utwitch.c
===
RCS file: /cvs/src/sys/dev/usb/utwitch.c,v
retrieving revision 1.17
diff -u -p -r1.17 utwitch.c
--- utwitch.c   8 Apr 2017 02:57:25 -   1.17
+++ utwitch.c   23 Nov 2019 17:52:49 -
@@ -278,7 +278,7 @@ utwitch_set_mode(struct utwitch_softc *s
}
 
/* wait ack */
-   tsleep(>sc_sensortask, 0, "utwitch", (1000*hz+999)/1000 + 1);
+   tsleep_nsec(>sc_sensortask, 0, "utwitch", MSEC_TO_NSEC(1000));
 }
 
 void
@@ -296,7 +296,7 @@ utwitch_read_value_request(struct utwitc
return;
 
/* wait till sensor data are updated, 500ms will be enough */
-   tsleep(>sc_sensortask, 0, "utwitch", (500*hz+999)/1000 + 1);
+   tsleep_nsec(>sc_sensortask, 0, "utwitch", MSEC_TO_NSEC(500));
 }
 
 void
@@ -319,5 +319,5 @@ utwitch_write_value_request(struct utwit
return;
 
/* wait till sensor data are updated, 250ms will be enough */
-   tsleep(>sc_sensortask, 0, "utwitch", (250*hz+999)/1000 + 1);
+   tsleep_nsec(>sc_sensortask, 0, "utwitch", MSEC_TO_NSEC(250));
 }



Re: cardbus(4): tsleep -> tsleep_nsec(9)

2019-11-23 Thread Scott Cheloha
*ahem*

jca@ has pointed out a dumb mistake in the prior diff.

This is what I meant to send.

Index: cardbus.c
===
RCS file: /cvs/src/sys/dev/cardbus/cardbus.c,v
retrieving revision 1.51
diff -u -p -r1.51 cardbus.c
--- cardbus.c   28 Aug 2015 00:03:53 -  1.51
+++ cardbus.c   23 Nov 2019 17:19:08 -
@@ -408,8 +408,8 @@ cardbus_attach_card(struct cardbus_softc
if (cold) { /* before kernel thread invoked */
delay(100*1000);
} else {/* thread context */
-   if (tsleep((void *)sc, PCATCH, "cardbus",
-   hz/10) != EWOULDBLOCK) {
+   if (tsleep_nsec(sc, PCATCH, "cardbus",
+   MSEC_TO_NSEC(100)) != EWOULDBLOCK) {
break;
}
}



update: X server to version 1.20.6

2019-11-23 Thread Matthieu Herrb
Hi,

The diff below update the X server to version 1.20.6.
See ChangeLog for changes.

Testing and oks are welcome.

Index: ChangeLog
===
RCS file: /cvs/OpenBSD/xenocara/xserver/ChangeLog,v
retrieving revision 1.33
diff -u -p -u -r1.33 ChangeLog
--- ChangeLog   27 Jul 2019 07:57:06 -  1.33
+++ ChangeLog   23 Nov 2019 11:51:22 -
@@ -1,3 +1,929 @@
+commit 6b3fafa9bfa94b9b04a1a44dc52afb7c4bc250ce
+Author: Matt Turner 
+Date:   Fri Nov 22 17:52:04 2019 -0500
+
+xserver 1.20.6
+
+Signed-off-by: Matt Turner 
+
+commit 88f12aa74bf4fea25d5b8d8002b3088432feb405
+Author: Matt Turner 
+Date:   Thu Nov 21 11:23:18 2019 -0500
+
+xfree86: Test presence of isastream()
+
+isastream() was never more than a stub in glibc, and was removed in
+glibc-2.30 by commit a0a0dc83173c ("Remove obsolete, never-implemented
+XSI STREAMS declarations").
+
+Bug: https://bugs.gentoo.org/700838
+Reviewed-by: Julien Cristau 
+Signed-off-by: Matt Turner 
+(cherry picked from commit e6ab7f9f342f463092c45226f3294074351fdd5e)
+
+commit 0e60139064b84b856c59e5a456e26c60710b1b69
+Author: Olivier Fourdan 
+Date:   Mon Nov 18 17:28:45 2019 +0100
+
+present/wnmd: Relax assertion on CRTC on abort_vblank()
+
+Currently, the function `present_wnmd_abort_vblank()` would fail if the
+given `crtc` is NULL.
+
+However, `xwl_present_get_crtc()` can return `NULL` under some
+circumstances, which would cause an unexpected termination of Xwayland
+in such a case, caused by the assertion failure being triggered.
+
+Remove the assertion, considering that the `crtc` isn't actually used in
+neither `present_wnmd_abort_vblank()` nor `xwl_present_abort_vblank()`.
+
+Signed-off-by: Olivier Fourdan 
+Reviewed-by: Michel Dänzer 
+Closes: https://gitlab.freedesktop.org/xorg/xserver/issues/937
+(cherry picked from commit 4f984fc06bd57cabfa38f6191f10714878dc8969)
+
+commit 2edadf26f1f8deddbe171115fa502337ac62df02
+Author: Aaron Plattner 
+Date:   Tue Nov 19 10:08:51 2019 -0800
+
+os: Don't crash in AttendClient if the client is gone
+
+If a client is in the process of being closed down, then its 
client->osPrivate
+pointer will be set to NULL by CloseDownConnection. This can cause a crash 
if
+freeing the client's resources results in a call to AttendClient. For 
example,
+if the client has a pending sync fence:
+
+ Thread 1 "X" received signal SIGSEGV, Segmentation fault.
+ AttendClient (client=0x5571c4aed9a0) at ../os/connection.c:942
+ (gdb) bt
+ #0  AttendClient (client=0x5571c4aed9a0) at ../os/connection.c:942
+ #1  0x5571c3dbb865 in SyncAwaitTriggerFired (pTrigger=) at ../Xext/sync.c:694
+ #2  0x5571c3dd5749 in miSyncDestroyFence (pFence=0x5571c5063980) at 
../miext/sync/misync.c:120
+ #3  0x5571c3dbbc69 in FreeFence (obj=, id=) at ../Xext/sync.c:1909
+ #4  0x5571c3d7a01d in doFreeResource (res=0x5571c506e3d0, 
skip=skip@entry=0) at ../dix/resource.c:880
+ #5  0x5571c3d7b1dc in FreeClientResources (client=0x5571c4aed9a0) at 
../dix/resource.c:1146
+ #6  FreeClientResources (client=0x5571c4aed9a0) at ../dix/resource.c:1109
+ #7  0x5571c3d5525f in CloseDownClient (client=0x5571c4aed9a0) at 
../dix/dispatch.c:3473
+ #8  0x5571c3d55eeb in Dispatch () at ../dix/dispatch.c:492
+ #9  0x5571c3d59e96 in dix_main (argc=3, argv=0x7ffe7854bc28, 
envp=) at ../dix/main.c:276
+ #10 0x7fea4837cb6b in __libc_start_main (main=0x5571c3d1d060 , 
argc=3, argv=0x7ffe7854bc28, init=, fini=, 
rtld_fini=, stack_end=0x7ffe7854bc18) at ../csu/libc-start.c:308
+ #11 0x5571c3d1d09a in _start () at ../Xext/sync.c:2378
+ (gdb) print client->osPrivate
+ $1 = (void *) 0x0
+
+Since the client is about to be freed, its ignore count doesn't matter and
+AttendClient can simply be a no-op. Check for client->clientGone in 
AttendClient
+and remove similar checks from two callers that had them.
+
+Signed-off-by: Aaron Plattner 
+(cherry picked from commit 4308f5d3d1fbd0f5dce81e22c0c3f08c65a7c9d8)
+
+commit 68cfee97bc59580724d594c82f5ee55a980dadf0
+Author: Adam Jackson 
+Date:   Wed Oct 9 11:57:18 2019 -0400
+
+dix: Call SourceValidate before GetImage
+
+This ensures that any prep work for the drawable we're about to read
+from is already done before we call down to GetImage. This should be no
+functional change as most of the callers with a non-trivial
+SourceValidate are already wrapping GetImage and doing the equivalent
+thing, but we'll be simplifying that shortly.
+
+More importantly this ensures that if any of that prep work would
+generate events - like automatic compositing flushing rendering to a
+parent pixmap which then triggers damage - then it happens entirely
+before we start writing the GetImage 

Re: envy(4): *sleep(9) -> *sleep_nsec(9)

2019-11-23 Thread Alexandre Ratchov
On Fri, Nov 22, 2019 at 06:41:25PM -0600, Scott Cheloha wrote:
> ok?
> 

sure, thanks



uvideo(4) stream buffer malloc

2019-11-23 Thread Marcus Glocker
Some video apps like ffmpeg are quite aggressive in requesting stream
buffers from the driver.  E.g. when I want to record 1920x1080 with
ffmpeg and my Logitech Webcam C930e, ffmpeg will request 256 buffers
via VIDIOC_REQBUFS which we will limit to 32 first, but still will end
up in a ~132MB (!) malloc request - Which finally fails.

Instead of just hard aborting in that case, the following diff will try
to decrease the buffers by a quarter until we are low enough to malloc
the memory.

This makes 1920x1080 work for me finally with 8 buffers, which is still
high enough IMO.

OK?


Index: uvideo.c
===
RCS file: /cvs/src/sys/dev/usb/uvideo.c,v
retrieving revision 1.205
diff -u -p -u -p -r1.205 uvideo.c
--- uvideo.c14 Oct 2019 09:20:48 -  1.205
+++ uvideo.c23 Nov 2019 07:49:09 -
@@ -3294,12 +3294,15 @@ uvideo_reqbufs(void *v, struct v4l2_requ
sc->sc_mmap_count = 0;
return (EINVAL);
}
-   buf_size_total = sc->sc_mmap_count * buf_size;
-   buf_size_total = round_page(buf_size_total); /* page align buffer */
-   sc->sc_mmap_buffer = malloc(buf_size_total, M_DEVBUF, M_NOWAIT);
+   while (sc->sc_mmap_count > 0) {
+   buf_size_total = round_page(sc->sc_mmap_count * buf_size);
+   sc->sc_mmap_buffer = malloc(buf_size_total, M_DEVBUF, M_NOWAIT);
+   if (sc->sc_mmap_buffer != NULL)
+   break;
+   sc->sc_mmap_count = sc->sc_mmap_count / 4;
+   }
if (sc->sc_mmap_buffer == NULL) {
printf("%s: can't allocate mmap buffer!\n", DEVNAME(sc));
-   sc->sc_mmap_count = 0;
return (EINVAL);
}
sc->sc_mmap_buffer_size = buf_size_total;