Development discussion of WireGuard
 help / color / Atom feed
From: godisgovernment at gmail.com (Shawn Hoffman)
Subject: [PATCH 2/3] use ExEnterCriticalRegionAndAcquireResourceExclusive and ExReleaseResourceAndLeaveCriticalRegion
Date: Sat, 25 Apr 2020 20:52:53 -0700
Message-ID: <CAPqQDTDPUH17QUQG4xehfiM9zFGw7PVQu=u00v5x15ts=L7SVQ@mail.gmail.com> (raw)
In-Reply-To: <20200424234327.1814-2-godisgovernment@gmail.com>

Looking back over this, the enter+acquire of the existing code is
shared here, so replacing with exclusive will change behavior.
For now, please ignore this patch.


On Fri, Apr 24, 2020 at 4:44 PM Shawn Hoffman <godisgovernment at gmail.com> wrote:
>
> Signed-off-by: Shawn Hoffman <godisgovernment at gmail.com>
> ---
>  wintun.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/wintun.c b/wintun.c
> index 90e7930..00ac378 100644
> --- a/wintun.c
> +++ b/wintun.c
> @@ -884,15 +884,13 @@ TunDispatchDeviceControl(DEVICE_OBJECT *DeviceObject, IRP *Irp)
>      switch (Stack->Parameters.DeviceIoControl.IoControlCode)
>      {
>      case TUN_IOCTL_REGISTER_RINGS: {
> -        KeEnterCriticalRegion();
> -        ExAcquireResourceSharedLite(&TunDispatchCtxGuard, TRUE);
> +        ExEnterCriticalRegionAndAcquireResourceExclusive(&TunDispatchCtxGuard);
>  #pragma warning(suppress : 28175)
>          TUN_CTX *Ctx = DeviceObject->Reserved;
>          Status = NDIS_STATUS_ADAPTER_NOT_READY;
>          if (Ctx)
>              Status = TunRegisterBuffers(Ctx, Irp);
> -        ExReleaseResourceLite(&TunDispatchCtxGuard);
> -        KeLeaveCriticalRegion();
> +        ExReleaseResourceAndLeaveCriticalRegion(&TunDispatchCtxGuard);
>          break;
>      }
>      case TUN_IOCTL_FORCE_CLOSE_HANDLES:
> @@ -913,14 +911,12 @@ _Use_decl_annotations_
>  static NTSTATUS
>  TunDispatchClose(DEVICE_OBJECT *DeviceObject, IRP *Irp)
>  {
> -    KeEnterCriticalRegion();
> -    ExAcquireResourceSharedLite(&TunDispatchCtxGuard, TRUE);
> +    ExEnterCriticalRegionAndAcquireResourceExclusive(&TunDispatchCtxGuard);
>  #pragma warning(suppress : 28175)
>      TUN_CTX *Ctx = DeviceObject->Reserved;
>      if (Ctx)
>          TunUnregisterBuffers(Ctx, IoGetCurrentIrpStackLocation(Irp)->FileObject);
> -    ExReleaseResourceLite(&TunDispatchCtxGuard);
> -    KeLeaveCriticalRegion();
> +    ExReleaseResourceAndLeaveCriticalRegion(&TunDispatchCtxGuard);
>      return NdisDispatchClose(DeviceObject, Irp);
>  }
>
> --
> 2.26.2.windows.1
>


  reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-24 23:43 [PATCH 1/3] fix possible TunDispatchSecurityDescriptor leak godisgovernment
2020-04-24 23:43 ` [PATCH 2/3] use ExEnterCriticalRegionAndAcquireResourceExclusive and ExReleaseResourceAndLeaveCriticalRegion godisgovernment
2020-04-26  3:52   ` godisgovernment [this message]
2020-04-24 23:43 ` [PATCH 3/3] use RtlSubAuthoritySid instead of directly poking SID godisgovernment
  -- strict thread matches above, loose matches on Subject: below --
2020-04-24 18:59 [PATCH 0/3] misc code cleanup godisgovernment
2020-04-24 18:59 ` [PATCH 2/3] use ExEnterCriticalRegionAndAcquireResourceExclusive and ExReleaseResourceAndLeaveCriticalRegion godisgovernment

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPqQDTDPUH17QUQG4xehfiM9zFGw7PVQu=u00v5x15ts=L7SVQ@mail.gmail.com' \
    --to= \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Development discussion of WireGuard

Archives are clonable: git clone --mirror http://inbox.vuxu.org/wireguard

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.wireguard


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git