Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2207086iof; Tue, 7 Jun 2022 23:12:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqYlpvMpVwERsMS4LnKGzXDxnBaLog0Acx7+od3G48akswny/Boy0hPCW9KG5WhZ8Jyldv X-Received: by 2002:a65:6a16:0:b0:39d:4f3:67e6 with SMTP id m22-20020a656a16000000b0039d04f367e6mr28902242pgu.84.1654668755021; Tue, 07 Jun 2022 23:12:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654668755; cv=none; d=google.com; s=arc-20160816; b=UKxKG8MOoU7lwQCQveOEjE5vjXdW2Uaoys7+IESp2to7D9pR5YsVpreDra9aJPO5XQ atwpuM4XmxZTYNTKR3GzysJ9MB5oK1A6kkDgmm6HM4ZOb5MQH8SL97sZZs49o5QNTEdE 8vhP66uHHNZmLiysB0ubyU7qLj8OJqAgJXmjunYAqP7xNNTezgoTR+AVehvzPzATQ5Qs FhJRbqLysNKWeUUHgnAN9S9Ebg/ib9wR7Ocj9fqxORboZCrgGbCOehi4av6jvet5MLzE uNuUgvUwWrbWirkJggWuXJzjwWspjtp6yJOoTB0Uts20z+NqzD8f2UrTsEWAe0TmrfgL O2LA== 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=8FHBQtp0bevU0ZW+Uip/iK/s8OiUO8GXtle7O195HNw=; b=H7Kn+dk7D8LVSqL+OPpSsRnr2UgtaYGuN1EaXJylfmQcpdErQbW2nd9HDtGSx0QWhE /0KJ2SEE8NrI1YZ8odkdeQzzzGb4PnNhPjqx0MuHb2vds+AG+J/na61TRzYbjhR50GrS twAUYuh1oDYUgUt2Q/bLqzYOsSbD8VQTU7K4f1Dum7tPcdhUr9JGnE1V7n9D5jfhJuuM kr5BzJpx0Pzi9tzhtBjUk+/jejRiuiokueWfnnx9mambNg3hLvFdUCzgGhXv7ZREuKgU rVZraV1YkEO6N7Q3VDqQxVLPZ0j8Qq8227SPVucfeXx/qAeSojUMFWcpsha/OnXhQ8c8 ntvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zKAho9U6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x191-20020a6386c8000000b003fd9bbea2cesi12672952pgd.334.2022.06.07.23.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 23:12:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zKAho9U6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5FDB635639E; Tue, 7 Jun 2022 22:35:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1390213AbiFHBqu (ORCPT + 99 others); Tue, 7 Jun 2022 21:46:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383420AbiFGVxK (ORCPT ); Tue, 7 Jun 2022 17:53:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45E82244466; Tue, 7 Jun 2022 12:11:44 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 7275C612EC; Tue, 7 Jun 2022 19:11:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E525C385A2; Tue, 7 Jun 2022 19:11:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629102; bh=TGEP3+wcP3I5eC612IMnC6aIjznzCHpeaDh26azRWDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zKAho9U6ApxJIkbjtNluWJxsr9s/OIXBpqffmNkVHVp0Q6KjRPoTHKaBWLJfchJrV boYkjZSxbNXyXknpSP0gcROdc7z7l7L/J62fbHR3UGiSec/M6zsGCvRq1z+gP+OoR1 PXAjMfWVc6nFDovMegYs/nvunnZjqdL9AqZJE+Xg= 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.18 570/879] misc: ocxl: fix possible double free in ocxl_file_register_afu Date: Tue, 7 Jun 2022 19:01:28 +0200 Message-Id: <20220607165019.402781669@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 d881f5e40ad9..6777c419a8da 100644 --- a/drivers/misc/ocxl/file.c +++ b/drivers/misc/ocxl/file.c @@ -556,7 +556,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