Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2679017pxj; Mon, 31 May 2021 08:05:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUlUscINMiK69XthThH16YWCsE2Fx915ue6E9dlhh7ArsqQN6+ofJH9ZvyL6CyAouOI2de X-Received: by 2002:a05:6638:2643:: with SMTP id n3mr20788962jat.104.1622473529155; Mon, 31 May 2021 08:05:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622473529; cv=none; d=google.com; s=arc-20160816; b=ejXl8+gXotuzVdHZOKAuIl7o8ogx4F9XXwv30j57B6kEBDwQcM8MGhw9v9/WyUjZ20 bi3EJm+klr1Kc3GaeCD7scT4xQVZQ+fl64ZZ4JfviSrnmybuFyBz8Wv6BM0LgZRhButU t91LrEr3o1c6/TUREdkLawuseWU8/BDQETZPnarwmvRAgTAKTZK1yKCGWTs4Dzaobj+I Yry8eq07SGClDE+pKXD3nqz5BMI5Uhd0A3d5PyiMO5n/p4RMpOrn0FqVDRRehBA+uXs2 0rXTJxc+aEjZ6SnSJQDPS9YHfDIAhw75MYVlJ2JHdu7I0Jl0Nhy8mhxXDYm5r6IdjgPe x3Dg== 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=aAegHPFwT32++klpZIQZGmvgbvAl1VfuFYSWiODDyyI=; b=fPqECQdDvzk0rHCNFvNYzuwUkV/WQRETbMLU5i7En9v1b7rqY2ElG8CL76QZkIPCzo 5G6b7TMxKpeHSbXJv66cwLPushsqJGkGzWUGi7BW68wWcr3d1uexwly4J5xMcQOnG2Dw PvVFrduP1Dv5cb4GL19+vqzERaYTq5x2/gI3apXUwiXiAK5XJ903rP7pe8MlnjpSC6Kx 6JJ29o+robGMHqF0rK9fORyZe1BWKjTfHM4kFnGjGXcRJ9q8jWl6sXGgxt1RIHhoWnpW wAisRL9WcmY0ni4mYPxr5IcF4l4ZMrFgah5BBUF0QcPZ69JsgVXia4BdjUIrOKLH81yb cF/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bgD8aIps; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q8si14229857ior.12.2021.05.31.08.05.15; Mon, 31 May 2021 08:05:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bgD8aIps; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234558AbhEaPEi (ORCPT + 99 others); Mon, 31 May 2021 11:04:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:40230 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232641AbhEaOHf (ORCPT ); Mon, 31 May 2021 10:07:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B92E26140D; Mon, 31 May 2021 13:39:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468364; bh=7cBwNGJ4XnuLLx9x++da50kJ15B5g5p8WyjwJlCQIJY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bgD8aIpsUD4X94rIPNjSSDoeSk0LnkW9mckv/43vBPXDF9KgehjdOBHGg+VMdjHqB 1VyQOtN22q4HbCYb9vNfYsToM2hyoRCnPVfyr46A31njhjJNXgrDBYssWRWCGQEQdu R/ZkkIOMmmM+VpRo1hJdWhFgLsp4DNsljbT6WFmg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Julian Wiedmann , Karsten Graul , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 215/252] net/smc: remove device from smcd_dev_list after failed device_add() Date: Mon, 31 May 2021 15:14:40 +0200 Message-Id: <20210531130705.318275352@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Julian Wiedmann [ Upstream commit 444d7be9532dcfda8e0385226c862fd7e986f607 ] If the device_add() for a smcd_dev fails, there's no cleanup step that rolls back the earlier list_add(). The device subsequently gets freed, and we end up with a corrupted list. Add some error handling that removes the device from the list. Fixes: c6ba7c9ba43d ("net/smc: add base infrastructure for SMC-D and ISM") Signed-off-by: Julian Wiedmann Signed-off-by: Karsten Graul Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/smc/smc_ism.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/net/smc/smc_ism.c b/net/smc/smc_ism.c index 024ca21392f7..8e33c0128d73 100644 --- a/net/smc/smc_ism.c +++ b/net/smc/smc_ism.c @@ -331,6 +331,8 @@ EXPORT_SYMBOL_GPL(smcd_alloc_dev); int smcd_register_dev(struct smcd_dev *smcd) { + int rc; + mutex_lock(&smcd_dev_list.mutex); if (list_empty(&smcd_dev_list.list)) { u8 *system_eid = NULL; @@ -350,7 +352,14 @@ int smcd_register_dev(struct smcd_dev *smcd) dev_name(&smcd->dev), smcd->pnetid, smcd->pnetid_by_user ? " (user defined)" : ""); - return device_add(&smcd->dev); + rc = device_add(&smcd->dev); + if (rc) { + mutex_lock(&smcd_dev_list.mutex); + list_del(&smcd->list); + mutex_unlock(&smcd_dev_list.mutex); + } + + return rc; } EXPORT_SYMBOL_GPL(smcd_register_dev); -- 2.30.2