Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1152527rwb; Wed, 14 Dec 2022 07:08:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf6ZeMzWcqVVANOEojA6sebMBfx+yme/6+fMBsRZji52IcRYZgAiarKElkwCK1xeUBuTU5uP X-Received: by 2002:a17:906:408e:b0:7c0:eba3:e2e with SMTP id u14-20020a170906408e00b007c0eba30e2emr19471498ejj.31.1671030529900; Wed, 14 Dec 2022 07:08:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671030529; cv=none; d=google.com; s=arc-20160816; b=b4NqY89/mp1y3/baGIRqF4n+VD2iBYG1mUlLtQ69f0t3jKlCfyA8pwZrjfUOWHrwS2 EFbc2RrurbqmTEIYi/oV/pS5HDEPxaUbyEfDiQsQ8PdDXRamLQzRB9F3alvb8dGmDnLZ han58DjFQJU/ls5jXS2G4rCS30FhFm584MBZijKBt/S5n+lA56SgeI4GYh/IAYUd1b0/ QYqws+iQaFzQr5I50PmI5h4CCmjQhsBrBFpgQe7v1h/5vTw6p6mpaO0ly273jbCXLumH ydCN5ARqz1Y4V4+saNSB1VmJ8eGJwjr8aLvXVPqkvjzyH5wPL7FLg7xS//S7fUsqhc82 UZZg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=CMKkUm9EoW1v/EipPniqrQVVNfBsKuQ4FADQvEKyy6A=; b=Jks9jTcK8RdIiAcGk0iHGwwgVJJIPXu9bfB2YCRDqzW8YbH1U9UBTCjkzUeyEMsgql wNgwcsxb9T+5vM8pvGcntkq07yq7efQ1C+zODz+FjFHVGs2ykBMaCPrjkknSN26Swq7i Hxh9+rczpZXSb4W39sF8uBLAYfRA8A0xDK35zbr140wYg36jEXkza8LNmMexUqUcP4eo CEnly2Wktvh6WOO3Du0JXlc4Q3J0n9cHFC3+LdePQLB+JXgv6hLDeMp7+eZhY82M7NQT PeWx30Oge8Tidjl56y0YbNzD9lYoKaBJpsuXb7KJ42FbGWBunRVnmwlctYf90kblTNHM Rqaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ajJ3KAk6; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gh4-20020a170906e08400b00787803711f9si9218200ejb.353.2022.12.14.07.08.23; Wed, 14 Dec 2022 07:08:49 -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=@intel.com header.s=Intel header.b=ajJ3KAk6; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238697AbiLNOuc (ORCPT + 69 others); Wed, 14 Dec 2022 09:50:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238363AbiLNOu3 (ORCPT ); Wed, 14 Dec 2022 09:50:29 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13FA42F3; Wed, 14 Dec 2022 06:50:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671029429; x=1702565429; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=XTkX6HcEGJ1UBW6COm+l+2Y+4S1QKisQtPhX0zyA/4c=; b=ajJ3KAk6t0Lpca42PuzNnOzTw8LloHU1gZ6WSgaULN61VsIwuuajU6zA muAg/w6iKjhtSVfFAHZTGeotfS7/cZwylnTZYOKqWRe0B/9P7oip5PYPj jrj5ir1hTV7XOIOoLAWsesylMjl//iseGVYJ7dq1J3Z9OsHc7FA9wzbxe DPdQv27d/HWaxOS+uShFpeDElNLVTblHrfUAt+RMb6pOzNo3K81+kRd9i T2WY4YTTJ92aDZbXJ1U/SseatWtYsPRORW3ZOSZWrstA3ONksCDIFfE9v relQmzwbvYkar6NKpB48LGKA06ONgab+aaGQkLhHFNyPShPBPi5wY+pn6 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="320278599" X-IronPort-AV: E=Sophos;i="5.96,244,1665471600"; d="scan'208";a="320278599" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2022 06:50:27 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="977856375" X-IronPort-AV: E=Sophos;i="5.96,244,1665471600"; d="scan'208";a="977856375" Received: from pnasahl-mobl.ger.corp.intel.com (HELO ijarvine-MOBL2.ger.corp.intel.com) ([10.252.61.89]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2022 06:50:11 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: Russ Weight , Moritz Fischer , Wu Hao , Xu Yilun , Tom Rix , linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Matthew Gerlach , Marco Pagani Subject: [PATCH v2 1/1] fpga: m10bmc-sec: Fix probe rollback Date: Wed, 14 Dec 2022 16:49:52 +0200 Message-Id: <20221214144952.8392-1-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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 Handle probe error rollbacks properly to avoid leaks. Fixes: 5cd339b370e2 ("fpga: m10bmc-sec: add max10 secure update functions") Reviewed-by: Matthew Gerlach Reviewed-by: Russ Weight Reviewed-by: Marco Pagani Signed-off-by: Ilpo Järvinen --- I don't know if the previous one fell through cracks so resending this. v2: - Resending v1 with Marco's Rev-by drivers/fpga/intel-m10-bmc-sec-update.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/fpga/intel-m10-bmc-sec-update.c b/drivers/fpga/intel-m10-bmc-sec-update.c index 79d48852825e..03f1bd81c434 100644 --- a/drivers/fpga/intel-m10-bmc-sec-update.c +++ b/drivers/fpga/intel-m10-bmc-sec-update.c @@ -574,20 +574,27 @@ static int m10bmc_sec_probe(struct platform_device *pdev) len = scnprintf(buf, SEC_UPDATE_LEN_MAX, "secure-update%d", sec->fw_name_id); sec->fw_name = kmemdup_nul(buf, len, GFP_KERNEL); - if (!sec->fw_name) - return -ENOMEM; + if (!sec->fw_name) { + ret = -ENOMEM; + goto fw_name_fail; + } fwl = firmware_upload_register(THIS_MODULE, sec->dev, sec->fw_name, &m10bmc_ops, sec); if (IS_ERR(fwl)) { dev_err(sec->dev, "Firmware Upload driver failed to start\n"); - kfree(sec->fw_name); - xa_erase(&fw_upload_xa, sec->fw_name_id); - return PTR_ERR(fwl); + ret = PTR_ERR(fwl); + goto fw_uploader_fail; } sec->fwl = fwl; return 0; + +fw_uploader_fail: + kfree(sec->fw_name); +fw_name_fail: + xa_erase(&fw_upload_xa, sec->fw_name_id); + return ret; } static int m10bmc_sec_remove(struct platform_device *pdev) -- 2.30.2