From patchwork Sun Oct 30 15:44:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 13010 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1851421wru; Sun, 30 Oct 2022 08:46:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5BWMy1DqBPwEGM9RgIOSRzMlZwQD46BEYO2aft5whHyBIXyWqr2UT1/D6fZ6cFCixPlbUb X-Received: by 2002:a63:914a:0:b0:46f:7e1c:6584 with SMTP id l71-20020a63914a000000b0046f7e1c6584mr8564870pge.562.1667144775044; Sun, 30 Oct 2022 08:46:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667144775; cv=none; d=google.com; s=arc-20160816; b=sb/rM+qEn5O+ftCasG++CPcD3Em24SKnkmAuU76mpiMQLCsO3Hv36AeK9oB2NqOQUT GzuoGgJgawU/4AZFRXYFbsgoB1FnZowkd9XXPD2hNNIxTVJEtJ7Xujj7+lGjFuIpQEJ2 1YtAIyXNfjYrq2tFCYmcFQhAkZ7aq/ybiQrfFXFHUFQsySZyIfDwGi0/lVv3y6zcnQ5e CBC3lJOtCU+MFPqSXFJem4LuRM2tGXuAREMCCE/QeY7cZ7v4KgXDJoAJRrSoq5kHnEtL FNbbU3e8SNT4GZ6Dngy7249UTjl8OnvbCFAjn4x5biOnqpOF0lWzQWoZjPx/vZv5LMT8 40KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iJohQunT65bp1W4F8MRDap9SXeNOcfbklKB9UOjNr4M=; b=UMrVDgUZ0x0Tm9Rnxtx5if0hOCvvbDy/WIXe7/OgoAiwrNAZfoAPbCdAvLJo+Rd5as tY7Zd/nFpLjFEVcSp118gKXkZJd32OZCc3pZXiVLeXB2tOYN9KMH9HcnxWk+UNIJJCvf MlvUzFQK5qlQC423tU4Na/WkGuiTNpm4+Jl5mt1neQridEOq8mHRP4820RMWhTCjUV9l ReTN1H8ES4Qht95jI89qIWZu5wetkC7T6YNIizUnWrB3lqYt4b4BEEnSJVrn2eCgXKcz uRxYKeczSTodxjwC5QkcgQasLHHaowiwloyH3eDPDTuQR6PnK+VBEiF3UE5CmhMgGSWr FKag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=NrgMQ4JJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bf6-20020a170902b90600b0017a08290efbsi5052993plb.558.2022.10.30.08.46.02; Sun, 30 Oct 2022 08:46:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=NrgMQ4JJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229827AbiJ3Po6 (ORCPT + 99 others); Sun, 30 Oct 2022 11:44:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229717AbiJ3Pox (ORCPT ); Sun, 30 Oct 2022 11:44:53 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C85FB1D8 for ; Sun, 30 Oct 2022 08:44:52 -0700 (PDT) Received: from dimapc.. (unknown [109.252.112.196]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id 539C7660225F; Sun, 30 Oct 2022 15:44:49 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1667144690; bh=9L1UGeJdnkFYaRnE59XJ8gv48CnIdhLcIsE2uZ/nI0w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NrgMQ4JJcS/wCdnXA8AG/2ltnRc/459pzQVz+tPEzTYMw+l7wUlkqJ3gZn7BQsjRv 9EqSxbTZQnHVfP80TN7xvKFBhY/gqWfvUuzxwqLZJzFlY/fllOOfADR9n2UjVY/Ovw vC2W3JH7CUfTxnn47rZPq8ltpqZkp44vY1VcNNd7WV7ugzd5Wn+KLCw30/TaqhP6IR BTFkOYacsIhlK0YpHKh2lzNCdwaG/NrrN6UBYAaGFaRd+fLrIv1r9kp7pMPoIXazJr hYSBvQpvrwDbcLRpxvHRM31eY6ni/XCZvj9Zmntx78pHz5itR4y+dreooXnjBow/ia PZ8gz0SH1PJQg== From: Dmitry Osipenko To: Maarten Lankhorst , Maxime Ripard , Sumit Semwal , Thomas Zimmermann , =?utf-8?q?Christian_K=C3=B6nig?= , David Airlie , Daniel Vetter , noralf@tronnes.org, Dan Carpenter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] dma-buf: Make locking consistent in dma_buf_detach() Date: Sun, 30 Oct 2022 18:44:11 +0300 Message-Id: <20221030154412.8320-2-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221030154412.8320-1-dmitry.osipenko@collabora.com> References: <20221030154412.8320-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748127999428221357?= X-GMAIL-MSGID: =?utf-8?q?1748127999428221357?= The dma_buf_detach() locks attach->dmabuf->resv and then unlocks dmabuf->resv, which could be a two different locks from a static code checker perspective. In particular this triggers Smatch to report the "double unlock" error. Make the locking pointers consistent. Reported-by: Dan Carpenter Reviewed-by: Christian König Link: https://lore.kernel.org/dri-devel/Y1fLfsccW3AS%2Fo+%2F@kili/ Fixes: 809d9c72c2f8 ("dma-buf: Move dma_buf_attach() to dynamic locking specification") Signed-off-by: Dmitry Osipenko --- drivers/dma-buf/dma-buf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index c40d72d318fd..13bfd2d09c56 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -995,10 +995,10 @@ static void __unmap_dma_buf(struct dma_buf_attachment *attach, */ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach) { - if (WARN_ON(!dmabuf || !attach)) + if (WARN_ON(!dmabuf || !attach || dmabuf != attach->dmabuf)) return; - dma_resv_lock(attach->dmabuf->resv, NULL); + dma_resv_lock(dmabuf->resv, NULL); if (attach->sgt) { From patchwork Sun Oct 30 15:44:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 13011 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1855625wru; Sun, 30 Oct 2022 08:57:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6FlDUIlHuRc9AWi7sKzPradtCojiDEumzHqKu0SaOjIA6qTpmWq538Ku2qgnKLpUh8Anif X-Received: by 2002:a17:907:7283:b0:7ad:8bc6:4cbf with SMTP id dt3-20020a170907728300b007ad8bc64cbfmr8608791ejc.415.1667145459030; Sun, 30 Oct 2022 08:57:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667145459; cv=none; d=google.com; s=arc-20160816; b=iImQzxROn9mjIbLQScCw6T9cvM0uHo1EtF1aeXikAkFPCvE8x4e6TmjECHP3Tc3CU4 FOmkAuyJP8a67H/qSAfYSuW0uL8cuVPY+TazbZ8ebVhrLN1couE9RGEOWH5KjP/2tpEk PN0o+QdIhrZxVXoncNB17+YRTrJsTCa+z+tCyRjTfBn/B+F/OCwqIUZHYLGcCYGRSOYt FH6TPGov0C8ihbKxlv9RnVcJqPd2frhE9m9hZMC9dco4ikXeHPDzw+p8FeFwTDhJqm7y E4rvFuNx6xD5e70wMHW8mGBwbhkJDKbEqmFXLkjTswRv90fJcWlt4A63iCq3+lgEs3BW EIiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CCbTzwV+nVOQMVPJZzNbONnS+wlOv6FTitqVsiB+8I8=; b=pSXpuW606yIResgH51k4mYx6MR1ITnAMefBCaLaABPAquKTjwhj8obj6vfqT/XphpB 6+fOTTkhZAj0xwSuN2skmmt0upz49HKooXsUo4CFWr2HbMv3IEtkXUi+PejpLJuzpbiY EFI6ChVd39XyKwMHGEwbifSLMMenptmE8yk0usotaHn1NHBshbwQP0vxd/dZteOgL9Bz a2AvmFzirECs4mofD9ujnWl4GHFY3aCkOY1VdnO45k/zPEt599x/NcVNYuVmpHgMwMze vk7qOlZR8qADWLeR4rWFPaADX9CMa6258Kw8IqT7XabDoy9hFuxIcWjl1hZXoaj1PSlk JD4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=D77hkyxo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d15-20020a056402516f00b004617d769429si4505673ede.459.2022.10.30.08.57.14; Sun, 30 Oct 2022 08:57:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=D77hkyxo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229845AbiJ3PpB (ORCPT + 99 others); Sun, 30 Oct 2022 11:45:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229770AbiJ3Pox (ORCPT ); Sun, 30 Oct 2022 11:44:53 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07A03B1DE for ; Sun, 30 Oct 2022 08:44:53 -0700 (PDT) Received: from dimapc.. (unknown [109.252.112.196]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id E00E066022A2; Sun, 30 Oct 2022 15:44:50 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1667144691; bh=Jr+CDx/FOmbAS4EXsPeToboJf/vzEdDZoQONhOc44DE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D77hkyxoateNQYLF7wJaHR+9csvedoBuzF1VEUTMenUkMjtdSeyXUAhgE0j4RXuLL Linbwa8HPzpUigLIVoxs7LY25ZnDHWu77L1e1Q7YGyXwmOKgD3BcSzOhrRNW06qo8h vIMEKpXsMe8QU+z9CDPFk7/fR+FFtgzo3b4+FJjHQYU9K1kXH8ISUBV8sOjaF86c1g oPB4Zkj4zO4tGmixIgmZ0m4jNShlzyv6vRfkWt4KlbW+uX+eJypQ916ceOZdx6DhKc dbOzHIpE1tWqNwSK2G/EjpcU6QwFq2DrhD7r7oTmaWUaCYVeTLqy3SkZoLn2Oi//WB i4qutZJMPkWVA== From: Dmitry Osipenko To: Maarten Lankhorst , Maxime Ripard , Sumit Semwal , Thomas Zimmermann , =?utf-8?q?Christian_K=C3=B6nig?= , David Airlie , Daniel Vetter , noralf@tronnes.org, Dan Carpenter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] drm/client: Prevent NULL dereference in drm_client_buffer_delete() Date: Sun, 30 Oct 2022 18:44:12 +0300 Message-Id: <20221030154412.8320-3-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221030154412.8320-1-dmitry.osipenko@collabora.com> References: <20221030154412.8320-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748128716971133850?= X-GMAIL-MSGID: =?utf-8?q?1748128716971133850?= The drm_gem_vunmap() will crash with a NULL dereference if the passed object pointer is NULL. It wasn't a problem before we added the locking support to drm_gem_vunmap function because the mapping argument was always NULL together with the object. Make drm_client_buffer_delete() to check whether GEM is NULL before trying to unmap the GEM, it will happen on framebuffer creation error. Reported-by: Dan Carpenter Link: https://lore.kernel.org/dri-devel/Y1kFEGxT8MVlf32V@kili/ Fixes: 79e2cf2e7a19 ("drm/gem: Take reservation lock for vmap/vunmap operations") Signed-off-by: Dmitry Osipenko Reviewed-by: Christian König --- drivers/gpu/drm/drm_client.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c index 38e1be991caa..fd67efe37c63 100644 --- a/drivers/gpu/drm/drm_client.c +++ b/drivers/gpu/drm/drm_client.c @@ -235,10 +235,10 @@ static void drm_client_buffer_delete(struct drm_client_buffer *buffer) { struct drm_device *dev = buffer->client->dev; - drm_gem_vunmap_unlocked(buffer->gem, &buffer->map); - - if (buffer->gem) + if (buffer->gem) { + drm_gem_vunmap_unlocked(buffer->gem, &buffer->map); drm_gem_object_put(buffer->gem); + } if (buffer->handle) drm_mode_destroy_dumb(dev, buffer->handle, buffer->client->file);