Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3032866pxj; Mon, 14 Jun 2021 12:46:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxq8BBE0hrkmWu0qbaSl5m1DsUwqkntmph0aIDT4FN08o30z5/DqZrd7ytQlaQsfcmg4rAI X-Received: by 2002:a05:6402:419:: with SMTP id q25mr11447210edv.331.1623699973345; Mon, 14 Jun 2021 12:46:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623699973; cv=none; d=google.com; s=arc-20160816; b=tHiPPmPR0GrRxq51LYDyyyrWPgHjbWNZyE6fsLkEHHso2XRZzW1xAjoFZBAZ3b+DTE HflrlG3ggRewLrtGjoweFYXBPllTkud/yaqVoAzqLBzW4OHd7C8vlde5U95UM5y7h/hY R4iclxxQJFfCmuokY4G+MSPEYO60C62wsX0DHsvyklVqWTGE+LYryuDw9eY23i/tsRtj G1SlKaWprtPTYB0RxwaNJ8/9XmTC5J3LJMun8KlCC7zWhU+lMs1t59fbnbMTDxvUJHTX txafvmX55joo9cI6yNfFFM61BXatyKweQUM+MYuj5WwV67M9DFDttlKqv6YhYYlpf3qJ 3U1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=YSHdbBdLxbYZlWemrHLO8rn/WxjGLmePBCR/uXkKydQ=; b=Sdo34viu7mI31x4wtcyVIy0vt07sl+8aHLqPJONmzKxMO3X85AKSCrqWENitL7ZIKA 98IvX1k+JuqoixT/DCHLbMIbynFIB2JymeXO2eNeqJcCgtmU1hrC85qCjlquMPN7s6tN xMm6Xi8EPGx57hbXUVXAeIuPxH5g/tCkStjJoo35wtHWb70K+NDfYGZ4zxfhObZJTlKt GZMFqrcqI6ZBtTMBnwCZ2eE5droCojKWtJWRpPrfp+mejspVp7vEC7FWQqtXoqI6kbtR c5/M03vQ3hkHMWJf73FdnksvlYLi/FNehijy8qzs3UBmKf1CHntOwRZKmRKfOMERLHfI gP2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gXbiB53z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f26si13401187ejl.276.2021.06.14.12.45.50; Mon, 14 Jun 2021 12:46:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gXbiB53z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234483AbhFNTon (ORCPT + 99 others); Mon, 14 Jun 2021 15:44:43 -0400 Received: from mail-vs1-f45.google.com ([209.85.217.45]:40570 "EHLO mail-vs1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234280AbhFNTol (ORCPT ); Mon, 14 Jun 2021 15:44:41 -0400 Received: by mail-vs1-f45.google.com with SMTP id b1so8452359vsh.7 for ; Mon, 14 Jun 2021 12:42:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=YSHdbBdLxbYZlWemrHLO8rn/WxjGLmePBCR/uXkKydQ=; b=gXbiB53zsC9A0e6yeqxynJ8K2CU29DzKA4rzf1CmwQvBwYBn+qnXX00hnKL5om0qVR cZYQavTAVYQMj1TX1A03OZ0h8xN0QWjRi+Ot6oIO5CtnxrYernwAO+aRzRp3yH64G1rr ayU0qODqGk8qCobFP6cO3js4NbtPKGRSEHEZha27t/AxNpXM90jHZFHYCV199wbhQJwc 8y1yo+s1VL5UTlxtX51mcg1lHVG49NvzDvT7V0wTFv/iEdQe8jPd4hqxvYzOUN702JC8 /3JI292H5UcLiwYfN8HGcIP4pH2klkqR0/tKzMJjkhtUPZFpAe8tFKz3PscRB4LnvXz6 lufg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=YSHdbBdLxbYZlWemrHLO8rn/WxjGLmePBCR/uXkKydQ=; b=l8owYRtfQ3Ffr+b8xfHyfG4gbIb/N/LQVyeftoe/etZynREf9aFyivaDj5bCIVRhff UN+uMcG3W1xKxqWXpYWero+vEC1pK3tYwH3wvJepe5yGFEMHtglWIQ8hDzUy4NFJpegG /S26W3ItVGwakBKfzFfesbkpyX8w/2wP2J9IweQRqG65Wg7iqrXWjHLj5zkmdcuBxUZV k3D1WtWl9QYR+FehPnZu9LMYnIZ3nf4avYN1d6i52PJEXRNiBlHgecjiH1s4MNhw2K+L y3L6RfuMf8yG0frPaJUkPgsesQBvN6W4x4yyjOG4/GCtrWl4QNVavb5tyjgLWTSMgmBZ 9yCg== X-Gm-Message-State: AOAM530tGZRtWFbYKyT4T6KkjCd+jt7NvRUJKYSvpzfFSR3FktpmxS7h VTQlPSpsEXs0xEV1Rsc/rWMqweG8+own5QZ9w70= X-Received: by 2002:a05:6102:2159:: with SMTP id h25mr1281799vsg.19.1623699697567; Mon, 14 Jun 2021 12:41:37 -0700 (PDT) MIME-Version: 1.0 References: <20210612125426.6451-1-desmondcheongzx@gmail.com> <20210612125426.6451-3-desmondcheongzx@gmail.com> In-Reply-To: <20210612125426.6451-3-desmondcheongzx@gmail.com> From: Emil Velikov Date: Mon, 14 Jun 2021 20:41:26 +0100 Message-ID: Subject: Re: [PATCH 2/2] drm: Protect drm_master pointers in drm_lease.c To: Desmond Cheong Zhi Xi Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Dave Airlie , Daniel Vetter , Greg Kroah-Hartman , "Linux-Kernel@Vger. Kernel. Org" , ML dri-devel , Daniel Vetter , skhan@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 12 Jun 2021 at 13:55, Desmond Cheong Zhi Xi wrote: > > This patch ensures that the device's master mutex is acquired before > accessing pointers to struct drm_master that are subsequently > dereferenced. Without the mutex, the struct drm_master may be freed > concurrently by another process calling drm_setmaster_ioctl(). This > could then lead to use-after-free errors. > > Reported-by: Daniel Vetter > Signed-off-by: Desmond Cheong Zhi Xi > --- > @@ -578,6 +594,7 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev, > /* Hook up the fd */ > fd_install(fd, lessee_file); > > + mutex_unlock(&dev->master_mutex); I was going to suggest pushing the unlock call further up - after the drm_lease_create call. Although that would make the error path rather messy, so let's keep it as-is. > @@ -662,7 +684,7 @@ int drm_mode_get_lease_ioctl(struct drm_device *dev, > struct drm_mode_get_lease *arg = data; > __u32 __user *object_ids = (__u32 __user *) (uintptr_t) (arg->objects_ptr); > __u32 count_objects = arg->count_objects; > - struct drm_master *lessee = lessee_priv->master; > + struct drm_master *lessee; > struct idr *object_idr; > int count; > void *entry; > @@ -678,8 +700,10 @@ int drm_mode_get_lease_ioctl(struct drm_device *dev, > > DRM_DEBUG_LEASE("get lease for %d\n", lessee->lessee_id); > > + mutex_lock(&dev->master_mutex); As-is we're dereferencing an uninitialised pointer in DRM_DEBUG_LEASE. Move the lock and assignment before the DRM_DEBUG_LEASE, just like you've done in the list ioctl. With this fix, the patch is; Reviewed-by: Emil Velikov -Emil