From patchwork Wed Jan 24 01:29:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Liu X-Patchwork-Id: 191283 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp711986dyi; Tue, 23 Jan 2024 17:30:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFC+qPkbMBkvMCgB3sK9luw19+25GEzll9jZM0F7Gw9HfJ67j5dqkgCw8RBGhekUD3A8bnk X-Received: by 2002:a05:6e02:14b:b0:361:9394:7d07 with SMTP id j11-20020a056e02014b00b0036193947d07mr715824ilr.72.1706059832117; Tue, 23 Jan 2024 17:30:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706059832; cv=pass; d=google.com; s=arc-20160816; b=wKVmaYQciKybcRpVzkNhmFtnVCJdwANKY+n2IiqK37JbUFA4c2uHSJUwlHgFo/oTRO 9DFdHV8aUZQ+shchfNhLtG7JxCYZuceS5oRAmoHawiaH6xuT8HPOMs5WXwvAwQJlefrS wPifaXshGuTvIDMX67xkVdAiKlJEJmDqTniN7tUkJsEEggqz7BUTUcs3sb2SgN5Bs5eV N7xnnroz2HvUp6NLf6Jex4txRPjbrA6maRnHFPPLoorR3o0+3iPasb43jdCrbNOgMFTR NH7UV8Rshu++eWJes6uan3sHb5JLslG++tFcDEHFQnKe7N2e/+xFFFzGrqgjhA4moI58 jaDw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=vRuqzJZeUMkGrO0OcibaLH5Z7734A2xckhVZhAjAGUQ=; fh=pJI5lEHVsaJKAqmP8lIqGrCWqYsdqLAA5SzlO10RYNQ=; b=AjfmTtJ9MjZBmOusDD5B2lJLY9LDf5f/AIDXW0dG5VqnTpS1cl4FyfmIzdpGy+i02H fV09PRoPAB915vZgzdUdpRFSzsJSpc+JsyOhoCZaei0xw036TALyqmYrv1LgfNgUW4hM F9oZwBY0FjJR9MTSdyd7UtMp9rgzURPE9oc/8mJKBv8D/1KUZ0ohfJ66wzU40YBzeaiT NFaZf31t2XmdXyURT4EOaK7j3+g6ABV+vO5LuOf7ci8klzHEjrRjUOVtCeq+pE6j2qY8 0f9209xLrTJDvZTi1oTVpe0opsZx8YxXHkwBtbR5lBTTgnGeE/DQlE7XA/p+ii/nRzWP Irzg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=kylinos.cn); spf=pass (google.com: domain of linux-kernel+bounces-36273-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36273-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id x37-20020a634865000000b005ceef3c53a1si10512999pgk.635.2024.01.23.17.30.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 17:30:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36273-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=kylinos.cn); spf=pass (google.com: domain of linux-kernel+bounces-36273-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36273-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C8574283A3F for ; Wed, 24 Jan 2024 01:30:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6F2D13C15; Wed, 24 Jan 2024 01:30:14 +0000 (UTC) Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FEE41842; Wed, 24 Jan 2024 01:30:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706059812; cv=none; b=fMaayZpveHBrBgIwQXZboIcdVjc7qsmb8mfms/IAuLuvDoB53Tnxkg7oe6QgajQ+DmDcgRLVTy8dG4HDUYN5ZTPJe+ESYMn9JUpJvGmqWwDNgkpG/3r4D2RvgvuZb+Zw/+QvvX1EcCzMo475syILa/1HOEN3U0D52KOJqJ59uAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706059812; c=relaxed/simple; bh=NtAGrG5ZVUfxOpHnwIUN/o79MwAWDi+dzyZYGdfD7Hs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HnOVpzj6XvD4WEVs4tORMAuM6k92sXjxegRsOQXB1ZMwtldkhpkhwgPZtZIpGzjHlOj5B7ugdyygnk86anIVK3lEByRUmBI2Qj0rwizLwuRvwnSemMavFpq16UyhbeQXbaNZnLNVQo/XLe/jA3M01ALJjUmmBVuIWgZXzzwANj8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 0bbcbf84f5b84bd5b7f9669488c5eb53-20240124 X-CID-O-RULE: Release_Ham X-CID-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.35,REQID:cd248ffa-ee3d-4b45-8f20-b57da0cb9ae0,IP:15, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:0 X-CID-INFO: VERSION:1.1.35,REQID:cd248ffa-ee3d-4b45-8f20-b57da0cb9ae0,IP:15,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:0 X-CID-META: VersionHash:5d391d7,CLOUDID:e9a613fe-c16b-4159-a099-3b9d0558e447,B ulkID:240124093002G6S37MJB,BulkQuantity:0,Recheck:0,SF:66|38|24|17|19|44|1 02,TC:nil,Content:0,EDM:-3,IP:-2,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,CO L:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_FSD,TF_CID_SPAM_FSI,TF_CID_SPAM_SNR,TF_CID_SPAM_FAS X-UUID: 0bbcbf84f5b84bd5b7f9669488c5eb53-20240124 X-User: liucong2@kylinos.cn Received: from localhost.localdomain [(116.128.244.171)] by mailgw (envelope-from ) (Generic MTA) with ESMTP id 1784765844; Wed, 24 Jan 2024 09:30:01 +0800 From: Cong Liu To: shyam-sundar.s-k@amd.com, Shyam Sundar S K , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Mario Limonciello Cc: linux-kernel@vger.kernel.org, liucong2@kylinos.cn, platform-driver-x86@vger.kernel.org Subject: [PATCH v2] platform/x86/amd/pmf: Fix memory leak in amd_pmf_get_pb_data() Date: Wed, 24 Jan 2024 09:29:38 +0800 Message-Id: <20240124012939.6550-1-liucong2@kylinos.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788845642319715281 X-GMAIL-MSGID: 1788933394600077850 amd_pmf_get_pb_data() will allocate memory for the policy buffer, but does not free it if copy_from_user() fails. This leads to a memory leak. Fixes: 10817f28e533 ("platform/x86/amd/pmf: Add capability to sideload of policy binary") Reviewed-by: Shyam Sundar S K Signed-off-by: Cong Liu --- drivers/platform/x86/amd/pmf/tee-if.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index 502ce93d5cdd..f8c0177afb0d 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -298,8 +298,10 @@ static ssize_t amd_pmf_get_pb_data(struct file *filp, const char __user *buf, if (!new_policy_buf) return -ENOMEM; - if (copy_from_user(new_policy_buf, buf, length)) + if (copy_from_user(new_policy_buf, buf, length)) { + kfree(new_policy_buf); return -EFAULT; + } kfree(dev->policy_buf); dev->policy_buf = new_policy_buf;