Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp444623iog; Mon, 13 Jun 2022 06:07:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwq/EkUpwgfzT2krvsulYardXFUe10Jt7LHroNN+21RFzVunulTQMCyURozY/vmZXuRUZQ9 X-Received: by 2002:a63:9752:0:b0:3c6:5a7a:5bd6 with SMTP id d18-20020a639752000000b003c65a7a5bd6mr52581399pgo.390.1655125659727; Mon, 13 Jun 2022 06:07:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125659; cv=none; d=google.com; s=arc-20160816; b=wkp89gOpoEHlctaAsS0eGog3UIH/cls+hqg+CVlU5qyQQr6g20VcdWJq9Gr4zoLOlk KgoMMd/eJ7mvmm8jMCntjsITNsLW8Y4FcpykbKMLT339y2V108pnUkLp0YiB3ba1GSZI LStwWBkLmrJpVqzp8liV5bNIJqzqQkaCSaIEt3GeGIiDQI/FucVo+uZZTcj3HrvtZLA5 IB89PoyOCvFoJhhpQtEOi7hRFyeZ2EzxIPShy/PioyTQEDsAO1TLtZlMGKPeC8TuZqg8 Ggz3ZWUeG/LRHHyvAfGWntFa8HQqVw6n2V2LRKfvPNT1XVPP+fixKmbXcf5FOvtZ3xn2 pFBw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SBQzFomissCQ0CT16k9yprlvypW37SaMuVvdnRybTS4=; b=KJT8xWCNg/ocPXGHYWhOtCUxPt0dUH36cimO7C0IHvPTFre9MyIyKgDec7pMsGPQsB QpXI+7GSWQGxOtIwSxXVuVePog0j4IxFZYxD9+TCpxsgvgIpRleH5B9b+4t29J5U3kGT zq2ipngKDY0AwHCqKEw9btf1ngTpzImTM6MQbweb1IswbXt5CKYaV7bU/tyIcFDyxk7O gRhGiGld7Lmu4dDbiQM6Oikh2zLsNk9xnxOhq2BCIVWSsGESmVgqTCPiTJWJb2zi4voJ WP+zF1fauDEm5lcQLI002kBhG1wiVatoKSbs8C+28LvwIBCCGgJkYtERO59aOujfuOlP /dpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hOUjWI1z; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x191-20020a6386c8000000b003c5a1baf6acsi9349533pgd.503.2022.06.13.06.07.24; Mon, 13 Jun 2022 06:07: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=@linuxfoundation.org header.s=korg header.b=hOUjWI1z; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353204AbiFMLXU (ORCPT + 99 others); Mon, 13 Jun 2022 07:23:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353706AbiFMLQO (ORCPT ); Mon, 13 Jun 2022 07:16:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2520C13E02; Mon, 13 Jun 2022 03:39:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D767AB80E94; Mon, 13 Jun 2022 10:39:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45D40C34114; Mon, 13 Jun 2022 10:39:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655116763; bh=2D9KikUe9oTYeuBe7GwvUaWVp/nisnI0acN44yzsfe8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hOUjWI1zVvUjjjPMhkseE4KhijVoZFtcfAVtRITK0PNaN1DACY8KD6sgyS6vZkcjG B2XGG/5VbBhCk2QqAqD+Xd8yAyp/YT9td+jssVnCE8hjwNTGOESiAcFbyi87sU/ErN Y+UHE6ARKjY2Ys7ofETd+0D6Sew6UmlK7bFIPP7c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hangyu Hua , Frederic Barrat , Michael Ellerman , Sasha Levin Subject: [PATCH 5.4 168/411] misc: ocxl: fix possible double free in ocxl_file_register_afu Date: Mon, 13 Jun 2022 12:07:21 +0200 Message-Id: <20220613094933.698473941@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Hangyu Hua [ Upstream commit 950cf957fe34d40d63dfa3bf3968210430b6491e ] info_release() will be called in device_unregister() when info->dev's reference count is 0. So there is no need to call ocxl_afu_put() and kfree() again. Fix this by adding free_minor() and return to err_unregister error path. Fixes: 75ca758adbaf ("ocxl: Create a clear delineation between ocxl backend & frontend") Signed-off-by: Hangyu Hua Acked-by: Frederic Barrat Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20220418085758.38145-1-hbh25y@gmail.com Signed-off-by: Sasha Levin --- drivers/misc/ocxl/file.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/misc/ocxl/file.c b/drivers/misc/ocxl/file.c index 4d1b44de1492..c742ab02ae18 100644 --- a/drivers/misc/ocxl/file.c +++ b/drivers/misc/ocxl/file.c @@ -558,7 +558,9 @@ int ocxl_file_register_afu(struct ocxl_afu *afu) err_unregister: ocxl_sysfs_unregister_afu(info); // safe to call even if register failed + free_minor(info); device_unregister(&info->dev); + return rc; err_put: ocxl_afu_put(afu); free_minor(info); -- 2.35.1