<feed xmlns='http://www.w3.org/2005/Atom'>
<title>wireguard-openbsd/sys/kern, branch master</title>
<subtitle>WireGuard implementation for the OpenBSD kernel</subtitle>
<id>https://git.zx2c4.com/wireguard-openbsd/atom/sys/kern?h=master</id>
<link rel='self' href='https://git.zx2c4.com/wireguard-openbsd/atom/sys/kern?h=master'/>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/'/>
<updated>2021-04-13T05:47:30Z</updated>
<entry>
<title>Add refcnt_take_if_gt()</title>
<updated>2021-04-13T05:47:30Z</updated>
<author>
<name>Matt Dunwoodie</name>
<email>ncon@noconroy.net</email>
</author>
<published>2021-04-03T13:15:47Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=e447e5e6911f4dc85b71b8683614807a4bf342e1'/>
<id>urn:sha1:e447e5e6911f4dc85b71b8683614807a4bf342e1</id>
<content type='text'>
This function (or of similar nature) is required to safely use a refcnt
and smr_entry together. Such functions exist on other platforms as
kref_get_unless_zero (on Linux) and refcount_acquire_if_gt (on FreeBSD).

The following diagram details the following situation with and without
refcnt_take_if_gt in 3 cases, with the first showing the "invalid" use
of refcnt_take.

Situation:

Thread #1 is removing the global referenc (o).
Thread #2 wants to reference an object (r), using a thread pointer (t).

Case:

1) refcnt_take after Thread #1 has released "o"
2) refcnt_take_if_gt before Thread #1 has released "o"
3) refcnt_take_if_gt after Thread #1 has released "o"

Data:

struct obj {
	struct smr_entry smr;
	struct refcnt    refcnt;
} *o, *r, *t1, *t2;

          Thread #1              |               Thread #2
---------------------------------+------------------------------------
                                 | r = NULL;
 rw_enter_write(&amp;lock);          | smr_read_enter();
                                 |
 t1 = SMR_PTR_GET_LOCKED(&amp;o);    | t2 = SMR_PTR_GET(&amp;o);
 SMR_PTR_SET_LOCKED(&amp;o, NULL);   |
                                 |
 if (refcnt_rele(&amp;t1-&gt;refcnt)    |
   smr_call(&amp;t1-&gt;smr, free, t1); |
                                 | if (t2 != NULL) {
                                 |   refcnt_take(&amp;t2-&gt;refcnt);
                                 |   r = t2;
                                 | }
 rw_exit_write(&amp;lock);           | smr_read_exit();
                               .....
 // called by smr_thread         |
 free(t1);                       |
                               .....
                                 | // use after free
                                 | *r
---------------------------------+------------------------------------
                                 | r = NULL;
 rw_enter_write(&amp;lock);          | smr_read_enter();
                                 |
 t1 = SMR_PTR_GET_LOCKED(&amp;o);    | t2 = SMR_PTR_GET(&amp;o);
 SMR_PTR_SET_LOCKED(&amp;o, NULL);   |
                                 |
 if (refcnt_rele(&amp;t1-&gt;refcnt)    |
   smr_call(&amp;t1-&gt;smr, free, t1); |
                                 | if (t2 != NULL &amp;&amp;
                                 |  refcnt_take_if_gt(&amp;t2-&gt;refcnt, 0))
                                 |   r = t2;
 rw_exit_write(&amp;lock);           | smr_read_exit();
                               .....
 // called by smr_thread         | // we don't have a valid reference
 free(t1);                       | assert(r == NULL);
---------------------------------+------------------------------------
                                 | r = NULL;
 rw_enter_write(&amp;lock);          | smr_read_enter();
                                 |
 t1 = SMR_PTR_GET_LOCKED(&amp;o);    | t2 = SMR_PTR_GET(&amp;o);
 SMR_PTR_SET_LOCKED(&amp;o, NULL);   |
                                 | if (t2 != NULL &amp;&amp;
                                 |  refcnt_take_if_gt(&amp;t2-&gt;refcnt, 0))
                                 |   r = t2;
 if (refcnt_rele(&amp;t1-&gt;refcnt)    |
   smr_call(&amp;t1-&gt;smr, free, t1); |
 rw_exit_write(&amp;lock);           | smr_read_exit();
                               .....
                                 | // we need to put our reference
                                 | if (refcnt_rele(&amp;t2-&gt;refcnt))
                                 |   smr_call(&amp;t2-&gt;smr, free, t2);
                               .....
 // called by smr_thread         |
 free(t1);                       |
---------------------------------+------------------------------------

Currently it uses atomic_add_int_nv to atomically read the refcnt,
but I'm open to suggestions for better ways.

The atomic_cas_uint is used to ensure that refcnt hasn't been modified
since reading `old`.
</content>
</entry>
<entry>
<title>Permit kern.somaxconn when the unix pledge is used. Previously this was only</title>
<updated>2021-03-25T21:27:45Z</updated>
<author>
<name>abieber</name>
<email>abieber@openbsd.org</email>
</author>
<published>2021-03-25T21:27:45Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=2e384c95b2c4c0c66e56742bbffb7e20579c2488'/>
<id>urn:sha1:2e384c95b2c4c0c66e56742bbffb7e20579c2488</id>
<content type='text'>
allowed when inet was used.

This lets Go programs use 'unix' without also including 'inet'.

from Josh Rickmar

ok / tree review from deraadt@, commit message cluestick from tb@
</content>
</entry>
<entry>
<title>Make a child execute fork_return() only if PTRACE_FORK has been specified.</title>
<updated>2021-03-23T10:30:40Z</updated>
<author>
<name>mpi</name>
<email>mpi@openbsd.org</email>
</author>
<published>2021-03-23T10:30:40Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=af8964917e47849e103b45f84b226601281e0495'/>
<id>urn:sha1:af8964917e47849e103b45f84b226601281e0495</id>
<content type='text'>
fork_return() does an additional check to send a SIGTRAP (for a debugger)
but this signal might overwrite the SIGSTOP generated by the parent doing
a PT_ATTACH before the child has a change to execute any instruction.

Prevent a race visible only on SP system with regress/sys/kern/ptrace2.

ok kettenis@
</content>
</entry>
<entry>
<title>Skip first frame when saving stacktraces, it's always witness_checkorder().</title>
<updated>2021-03-23T10:22:20Z</updated>
<author>
<name>mpi</name>
<email>mpi@openbsd.org</email>
</author>
<published>2021-03-23T10:22:20Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=cb55d4750a53b14e91e62240a8a2cb53357ffd2f'/>
<id>urn:sha1:cb55d4750a53b14e91e62240a8a2cb53357ffd2f</id>
<content type='text'>
ok visa@
</content>
</entry>
<entry>
<title>makes `struct execsw' to:</title>
<updated>2021-03-21T11:29:38Z</updated>
<author>
<name>semarie</name>
<email>semarie@openbsd.org</email>
</author>
<published>2021-03-21T11:29:38Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=c49c61c6189f292e7cc497671b99c396a5890d71'/>
<id>urn:sha1:c49c61c6189f292e7cc497671b99c396a5890d71</id>
<content type='text'>
- use C99-style initialization (grep works better with that)
- use const as execsw is not modified during runtime

ok mpi@
</content>
</entry>
<entry>
<title>Use uppercases for defines.</title>
<updated>2021-03-21T10:24:36Z</updated>
<author>
<name>mpi</name>
<email>mpi@openbsd.org</email>
</author>
<published>2021-03-21T10:24:36Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=58ea3020aa556302036dbceae90c657300c06510'/>
<id>urn:sha1:58ea3020aa556302036dbceae90c657300c06510</id>
<content type='text'>
No functional change.

ok semarie@
</content>
</entry>
<entry>
<title>namei: reorganize a bit the error path for simples cases</title>
<updated>2021-03-20T11:26:07Z</updated>
<author>
<name>semarie</name>
<email>semarie@openbsd.org</email>
</author>
<published>2021-03-20T11:26:07Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=c2dd98f25b9d7181da4818325a7770905922ca39'/>
<id>urn:sha1:c2dd98f25b9d7181da4818325a7770905922ca39</id>
<content type='text'>
- move 'fail' label to end of function (instead of using the first
  if-condition)

- merge the most simples error code paths idioms from 'cleanup+return'
  to 'goto-fail'

ok mpi@
</content>
</entry>
<entry>
<title>regen</title>
<updated>2021-03-18T08:44:59Z</updated>
<author>
<name>mvs</name>
<email>mvs@openbsd.org</email>
</author>
<published>2021-03-18T08:44:59Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=1a45b5b6e341aafc249501a50d7a0f9ed64b7957'/>
<id>urn:sha1:1a45b5b6e341aafc249501a50d7a0f9ed64b7957</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Unlock sendsyslog(2). Console output still requires kernel lock to be</title>
<updated>2021-03-18T08:43:38Z</updated>
<author>
<name>mvs</name>
<email>mvs@openbsd.org</email>
</author>
<published>2021-03-18T08:43:38Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=87131069daeaefa13c7d980a429556ff59da3ba7'/>
<id>urn:sha1:87131069daeaefa13c7d980a429556ff59da3ba7</id>
<content type='text'>
held but this path is only followed while `syslogf' socket is not set.

New `syslogf_rwlock' used to protect `syslogf' access.

ok bluhm@
</content>
</entry>
<entry>
<title>handle theoretical case of sigfillsz not being pow2-sized on some</title>
<updated>2021-03-16T16:32:22Z</updated>
<author>
<name>deraadt</name>
<email>deraadt@openbsd.org</email>
</author>
<published>2021-03-16T16:32:22Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=d5ee67c8efc01e3ba4716c001a1db11220dbf9cc'/>
<id>urn:sha1:d5ee67c8efc01e3ba4716c001a1db11220dbf9cc</id>
<content type='text'>
architecture.
from miod
</content>
</entry>
</feed>
