Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7830852rwb; Tue, 6 Dec 2022 10:20:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf6wKuWrYvGcf1L9xYyxp7I+Qm/Kpzx0xvbAo19jl/MvHA0O0SEWigyYegwJ8HBXEt1V3bFw X-Received: by 2002:a17:902:be01:b0:186:7db1:d2a4 with SMTP id r1-20020a170902be0100b001867db1d2a4mr74406331pls.84.1670350854902; Tue, 06 Dec 2022 10:20:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670350854; cv=none; d=google.com; s=arc-20160816; b=0rq0qUyR3/eupeSw1oHCLLVPi0KiVHK3UFm2bXE/k+aC/U2VgmgPU6anrGSr7Ufjox j4zpVDm/TTqsjky6KMffOHnhveEAsWAyCjzcOs50erY5IBoOaoZm7A2fGRtX+Xuqawp0 QJ8uM+vqyM2iLdXRmtXW5m9ma1XBL2puJ3GedceQIYGlHSfdTQU2cBHDXgyAfDkHytIy LiCKQlUnW0nKwtT28eovVUIKV2BOMi/2bEh/DdarvgTjlsd2RpP3kFzm/TGYXCO1ADpj SCXmmLoLBGcMg2E4gdgiA6tZmfvKyT8n3WzG5iSzx9tTJSOVcKS63zEZtb7263R9Soue rAYg== 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=CWev+jDg0dJZ3iRe8fmDv7sVMbP2pNiYIK+0iXz8Ozw=; b=IHcyG7zFd6AeDsHymDJHsCLovC2A4dDHCAPeqZz0/Jj57jJ9p+VQDOVQZrLdT3H5nT vTbvBdm6mPG1XUNXkO0PK0YkMcYidTBEvGX7i9oP95c53n6WhJd9tmkPM3CJd7+zMaS4 MpWamhR7O6nwP8egUY9ROkTb2Pw85aSDRcsxkh+6p4atSNBlTYPQQknw+Uc2ZNcE2mbC SNJVFUl5FQTx5PQVsj+RuZ8KbhXuAEBu4MNxbb4SbScJQAYbE+HAePEjRXlfsSSPMx0s fLzxfNuT+RuQaMJKYSs8bNhgN4ZmYaszHbvvRMsGGq7kUFF/dEz9vaVg3P0RBhDOpAol +XnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gGQ4+B1A; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a12-20020a631a0c000000b0046ee9f16e3dsi18285628pga.671.2022.12.06.10.20.44; Tue, 06 Dec 2022 10:20:54 -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=@gmail.com header.s=20210112 header.b=gGQ4+B1A; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229701AbiLFSJZ (ORCPT + 77 others); Tue, 6 Dec 2022 13:09:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229673AbiLFSJY (ORCPT ); Tue, 6 Dec 2022 13:09:24 -0500 Received: from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com [IPv6:2001:4860:4864:20::2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BAAA3AC16; Tue, 6 Dec 2022 10:09:23 -0800 (PST) Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-1447c7aa004so10235318fac.11; Tue, 06 Dec 2022 10:09:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=CWev+jDg0dJZ3iRe8fmDv7sVMbP2pNiYIK+0iXz8Ozw=; b=gGQ4+B1AD0prkHHQTMEZSg0B+Po3EeECzMeGxLiglZQCMnadIghRxwxHWlMxquyKfM lZYGC0USPIpX+prT+vtaowDIjN0L6IDesiXaKcbI0I8Tf/Z5LyT4gabJEv7w2YrxbBxc nJedvuGElXiXAtWQ49k9akfBY7U9WtFgCQBOsm9B/E0SzOXZcYBq6tVQYi5feQ5RS90Y 1W2VHnpMB1vz/6R4PSPHvA596hjbHdO/46l/DkU8+E0w9rIvWwzQ/U77GhiuIEEoy1iz d0xHLBpDdDsSdRW7StAyzBge8nQ6rho0G8KlYlfjVf2WzxzHKCi0pwRxnXGf7nOZRWlW 2SNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CWev+jDg0dJZ3iRe8fmDv7sVMbP2pNiYIK+0iXz8Ozw=; b=nad3VrToehX+U3e0+A2x3TACDLFEdXV8+fKVubxnoQNNGqhVUVgkoYMzWvjsyL/mSr AoJYu6eSJq7Gm1W7yYpjb4XGtbX3mpLzze7UlGR/NVHgvBCrop19L6NNRTF1gERkV0bV pQvH22al+ZX5fQGQvVSyZwcAbMxRp9pTy/ERb81N4tssgSpd8zvMu97lIIeWryOlVxTm nEY55X/r/596qERE5f9aSv1ZElB/1zCCC789Fe1epsLHnsaveDYHn3X/ssIFNSIWSTKb qPCCt5g1ygK2zz6exwpjluXHuZIosV+ep9FkR185Ta7l5dPnZBAr9jC7ZGY5rNI50IC1 NIdA== X-Gm-Message-State: ANoB5pmjEKNZxZuN/M/yDAMFIACpvANKhmQ4+H3X9OjQYInEgJyOeAoA PMaTD24spsdUEtKgDh4dVrTGvrDteoWspP06UhA= X-Received: by 2002:a05:6870:e749:b0:144:5f0d:9fcb with SMTP id t9-20020a056870e74900b001445f0d9fcbmr8272974oak.38.1670350162551; Tue, 06 Dec 2022 10:09:22 -0800 (PST) MIME-Version: 1.0 References: <20221130185748.357410-1-robdclark@gmail.com> <20221130185748.357410-2-robdclark@gmail.com> <3e9e157d-e740-ee5b-b8d3-07822b2c9a9b@collabora.com> In-Reply-To: <3e9e157d-e740-ee5b-b8d3-07822b2c9a9b@collabora.com> From: Rob Clark Date: Tue, 6 Dec 2022 10:09:16 -0800 Message-ID: Subject: Re: [PATCH v2 1/2] drm/shmem-helper: Remove errant put in error path To: Dmitry Osipenko Cc: dri-devel@lists.freedesktop.org, 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 Sun, Dec 4, 2022 at 12:45 PM Dmitry Osipenko wrote: > > 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; > Yes, it seems that way.. I wish the shmem helpers worked in a less "special" way with regards to refcnting :-( BR, -R