Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5026813rwb; Sun, 4 Dec 2022 12:53:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf61I3rEhcnPG3eBF7sBTlArv0Q5hohUCkaO60ce/cgLL+vM3CMVZ/LSAoBpzwk/m82Ucjv7 X-Received: by 2002:a17:906:3087:b0:7bd:bb10:b5f8 with SMTP id 7-20020a170906308700b007bdbb10b5f8mr35091383ejv.659.1670187208985; Sun, 04 Dec 2022 12:53:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670187208; cv=none; d=google.com; s=arc-20160816; b=y9FDzseSbP+xeS1tqdvxuTxwyIDMd3ccxi2EPsVyAnnXIgiOH1H8wi1UyRlXgjW870 SDiNcXly6FPu5iTtT6zachNI71vOVdULAqYGHpW7HJag4DqmLtFQm+iwwHALPimnL2GG ZjKJQ5KwBMRNBtPs0qLyInaHlU6sPxyMqNAh5McNQxZGviORUA2IAgHw7QxFhTPkURca AMEfLUMHg9k2OMJJCzP+yDHpfz6iNRpmmlthu+/0igtzl0o9S6XQHZ2YZFOxw/BtkGKl n8ecHlAfPiTwLv4xE4PVfDMYKy6ABF/SV3ywEwG/ShFYwTnlzmL3+ewJQA6nTSzBb044 zDNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=G5eYyc5H5V2VWS8946tFrcoaO49rxtAy0xjDGJWveSE=; b=cK0Ol4yLVgbBnvjjO7B0Fw8wLxgSZfEyNfgWYr8XfYLwfeqRJa066cjj0rk7EzgiqE QOpV8XpJSDp46RX4C7ZZ8Sj7lHvjewO9fDzWHvNSoPPDag5T19eEncctLUa78IMNUyw7 PAJ9uzZxCr6VUU4gdaNg2fCQKYngYFKfpnSse495Uh3QkKUE58+lYxc9bg25PZHoHXxi DcmwlN5WfZhMPIPYZugJbPMvLTB+YVVKgVSwLR1i0TKZmwpxJzD7sRG+crILQFifjwzt gcrlBRMVfX/DkoTg83c8BaxF5zuETEW0uTRs1yVKmaayiTaC9He3lMROkzsLC8ALmtlC tuWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=P78D5Qej; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw10-20020a170906478a00b007919c624eadsi5387060ejc.522.2022.12.04.12.53.09; Sun, 04 Dec 2022 12:53:28 -0800 (PST) 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=P78D5Qej; 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 S230344AbiLDUpj (ORCPT + 82 others); Sun, 4 Dec 2022 15:45:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229949AbiLDUph (ORCPT ); Sun, 4 Dec 2022 15:45:37 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D55B11C23; Sun, 4 Dec 2022 12:45:35 -0800 (PST) Received: from [192.168.2.103] (109-252-124-61.nat.spd-mgts.ru [109.252.124.61]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 5C5D6660035C; Sun, 4 Dec 2022 20:45:32 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1670186733; bh=UMQoP9W0p04vTQUQWO237zkx10mRI/dKkIw7Lig3+Kc=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=P78D5QejvBCnU95dIIBU2WXl6Y/iMoyzuJoF+NatKvsMyvwrDBD5o/N4WFQifIVaB Jxb5iwKC7SUiUyWiaFzTbw04in4CDe/uC8+3un87bqKREnzMMsfm4Vgfp811B9Qr7s EL/5hBesdvE0ONOBqssdnuJUc+U1fzPUjQ2NJBA43X5vD5zpqp6MTNq5qXTzuqefBH lYBp9BZ5qUZhgaEb9K+TeRK8i8Ooano/6isOBSuC8dVv9VJQbfouTUIJ3Yiq3ZgYYE NLuTSbzWwZIHU2mTJPcFMEsMG2t3vBXrK1KVkfeJPhqGyjC79HlE4qkLuPM94ZDicR tDR7M5h7cTk+A== Message-ID: <3e9e157d-e740-ee5b-b8d3-07822b2c9a9b@collabora.com> Date: Sun, 4 Dec 2022 23:45:26 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH v2 1/2] drm/shmem-helper: Remove errant put in error path Content-Language: en-US To: Rob Clark , dri-devel@lists.freedesktop.org Cc: Rob Clark , Thomas Zimmermann , Daniel Vetter , open list , stable@vger.kernel.org, Eric Anholt , =?UTF-8?Q?Noralf_Tr=c3=b8nnes?= , syzbot+c8ae65286134dd1b800d@syzkaller.appspotmail.com References: <20221130185748.357410-1-robdclark@gmail.com> <20221130185748.357410-2-robdclark@gmail.com> From: Dmitry Osipenko In-Reply-To: <20221130185748.357410-2-robdclark@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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 On 11/30/22 21:57, Rob Clark wrote: > From: Rob Clark > > drm_gem_shmem_mmap() doesn't own this reference, resulting in the GEM > object getting prematurely freed leading to a later use-after-free. > > Link: https://syzkaller.appspot.com/bug?extid=c8ae65286134dd1b800d > Reported-by: syzbot+c8ae65286134dd1b800d@syzkaller.appspotmail.com > Fixes: 2194a63a818d ("drm: Add library for shmem backed GEM objects") > Cc: stable@vger.kernel.org > Signed-off-by: Rob Clark > Reviewed-by: Daniel Vetter > --- > drivers/gpu/drm/drm_gem_shmem_helper.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c > index 35138f8a375c..3b7b71391a4c 100644 > --- a/drivers/gpu/drm/drm_gem_shmem_helper.c > +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c > @@ -622,10 +622,8 @@ int drm_gem_shmem_mmap(struct drm_gem_shmem_object *shmem, struct vm_area_struct > } > > ret = drm_gem_shmem_get_pages(shmem); > - if (ret) { > - drm_gem_vm_close(vma); > + if (ret) > return ret; > - } > > vma->vm_flags |= VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP; > vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); AFAICS, the dmabuf mmaping code path needs a similar fix, isn't it? - /* Drop the reference drm_gem_mmap_obj() acquired.*/ - drm_gem_object_put(obj); vma->vm_private_data = NULL; - return dma_buf_mmap(obj->dma_buf, vma, 0); + ret = dma_buf_mmap(obj->dma_buf, vma, 0); + + /* Drop the reference drm_gem_mmap_obj() acquired.*/ + if (!ret) + drm_gem_object_put(obj); + + return ret; -- Best regards, Dmitry