From patchwork Tue Oct 6 16:20:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 290583 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41E05C41604 for ; Tue, 6 Oct 2020 16:20:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F21D9206F7 for ; Tue, 6 Oct 2020 16:20:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fPCODs0x" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726002AbgJFQUN (ORCPT ); Tue, 6 Oct 2020 12:20:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725902AbgJFQUN (ORCPT ); Tue, 6 Oct 2020 12:20:13 -0400 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CD46C061755 for ; Tue, 6 Oct 2020 09:20:13 -0700 (PDT) Received: by mail-qv1-xf49.google.com with SMTP id s8so5671066qvv.18 for ; Tue, 06 Oct 2020 09:20:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=Kkcvd5AeUHu/7QI5btDqB8/5zh+GBy9XCmSrw8Y+2UA=; b=fPCODs0xooE+a5d2V0S0jOFztMOJ/Kyf9mqCErprr6eVSYKaMnesZJtkO6qDhtd/X/ 3SvhcjWFIdA56kJRtLTdIO0tS4qLDNZaRz3rbX0gzqtbTThxI8FY4i9cUzgCbgUaw3g8 PTKj09wq0wQ74c95B6nkkNf3UX4sdkPVI4LSV1X9ZvUJgE/J+P/4uc3ld76JSjhJbCK+ HGerYqG91YrsvTDnk0iOzDmxMRY0/yMGmFceQdtrQJ3sCzEtvNNo7WjlHOf2FxyWPa8q 5pWF8iREOgBHhFSIraaJGvuwGvh/nysxkizP1YECfZmslOnIcSUHlX0BXzPdSAa2Sd7+ CRsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Kkcvd5AeUHu/7QI5btDqB8/5zh+GBy9XCmSrw8Y+2UA=; b=YsptvYUYNim0q3v2r2+jHefYOuzLxS6XqwJiBJ7Ba0w6ybijQnN+QpWrXVFe09A2Yu NWqwy6ZYlqgZPd35r1Sw1UZGPLRX3/BWW28n0cvzsZtk56ijXORZLoOJ5a+lNkkxdRSI nUguJs7ExCVrCbM963WP+X7y/1m6bCxsPiEG8M10jIsBDtuHCAM0lmil0DofYvjy+G4S GPDpaZQrICEgpGF3iZBnDKqzQ40/jTCqz8K8qRPlT1mwgCYEa+45bDNIsCBwkuj1ZYj9 8ZLmKy1xyf8A/9Vp51sSRJKvhsmUwoVJqhRI1g7zk9u5MO6cB4osfO9JWp1oYyEGPqX2 0CEg== X-Gm-Message-State: AOAM533EYI3tXFbDnyax+3RWT/tnsVylFWev7Fp52CN1dhQWmSQIhtFE 6LGfqU/0Vv1Jois3aO4G8SeAKYzl+5/S0Q== X-Google-Smtp-Source: ABdhPJxd/xgVJqr1AhI2WELy4n26SGJ0aX9Ur3GsQZdbPUU7dKeKgt51JRIvdI0Qy7eQ33vcg2GQDKKcN+hb/w== Sender: "gprocida via sendgmr" X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:110:a6ae:11ff:fe11:4f04]) (user=gprocida job=sendgmr) by 2002:a05:6214:1752:: with SMTP id dc18mr5690393qvb.10.1602001212340; Tue, 06 Oct 2020 09:20:12 -0700 (PDT) Date: Tue, 6 Oct 2020 17:20:00 +0100 In-Reply-To: <20201006135228.113259-2-gprocida@google.com> Message-Id: <20201006162000.1146391-1-gprocida@google.com> Mime-Version: 1.0 References: <20201006135228.113259-2-gprocida@google.com> X-Mailer: git-send-email 2.28.0.806.g8561365e88-goog Subject: [PATCH v2 1/1] drm/syncobj: Fix drm_syncobj_handle_to_fd refcount leak From: Giuliano Procida To: gregkh@linuxfoundation.org, stable@vger.kernel.org Cc: Giuliano Procida Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Commit 5fb252cad61f20ae5d5a8b199f6cc4faf6f418e1, a cherry-pick of upstream commit e7cdf5c82f1773c3386b93bbcf13b9bfff29fa31, introduced a refcount imbalance and thus a struct drm_syncobj object leak which can be triggered with DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD. The function drm_syncobj_handle_to_fd first calls drm_syncobj_find which increments the refcount of the object on success. In all of the drm_syncobj_handle_to_fd error paths, the refcount is decremented, but in the success path the refcount should remain at +1 as the struct drm_syncobj now belongs to the newly opened file. Instead, the refcount was incremented again to +2. Fixes: 5fb252cad61f ("drm/syncobj: Stop reusing the same struct file for all syncobj -> fd") Signed-off-by: Giuliano Procida --- drivers/gpu/drm/drm_syncobj.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c index 889c95d4feec..3f71bc3d93fe 100644 --- a/drivers/gpu/drm/drm_syncobj.c +++ b/drivers/gpu/drm/drm_syncobj.c @@ -355,7 +355,6 @@ static int drm_syncobj_handle_to_fd(struct drm_file *file_private, return PTR_ERR(file); } - drm_syncobj_get(syncobj); fd_install(fd, file); *p_fd = fd;