On Thu, Nov 25, 2021 at 10:59:25PM +0100, Alexander Bluhm wrote:
> On Thu, Nov 25, 2021 at 05:13:16PM +0100, Tobias Heider wrote:
> > Now with the missing parts from pfkeyv2.c as noticed by Hrvoje.
> 
> We have this code in pfkeyv2_send()
> 
>                         if (headers[SADB_EXT_ADDRESS_SRC] ||
>                             headers[SADB_EXT_ADDRESS_PROXY]) {
>                                 tdb_unlink(sa2);
>                                 import_address((struct sockaddr 
> *)&sa2->tdb_src,
>                                     headers[SADB_EXT_ADDRESS_SRC]);
>                                 import_address((struct sockaddr 
> *)&sa2->tdb_dst,
>                                     headers[SADB_EXT_ADDRESS_PROXY]);
>                                 puttdb(sa2);
>                         }
>                 }
>                 NET_UNLOCK();
> 
> Without the deleted flag, the pointers removed by tdb_unlink() and
> set by puttdb() guarantee that tdb_delete() is not called twice.
> In this piece of code they are missing for a short time.
> 
> Net lock takes care of this.  There should be a comment that describes
> this.
> 
>                               /*
>                                * NET_LOCK prevents tdb_delete() between
>                                * tdb_unlink() and puttdb().
>                                */
>                                 tdb_unlink(sa2);
>                               ...
>                                 puttdb(sa2);
> 
> Or we don't want to rely on net lock.  Then we need a common mutex
> to pretect this.
> 
>                               mtx_enter(&tdb_sadb_mtx);
>                               tdb_unlink_locked(tdbp);
>                               ...
>                               puttdb_locked(sa2);
>                               mtx_leave(&tdb_sadb_mtx);
> 

Without regarding on this diff this could be right direction because
`tdb_sadb_mtx' mutex(9) protects TDB hash consistency.

Reply via email to