Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1918505lqb; Mon, 27 May 2024 01:37:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUsRi6qgnEoRc9NbXwPMkXQndR8uQFniG7h0ailC8VP2VwKRMc1owDJCR4fAjxmPCF/e251ZreofsSF/2WUOC5hlUYjL0LAbygtxn8g6w== X-Google-Smtp-Source: AGHT+IEKUkbBhVgOrwt+MGvB3qQcnWGyx4KQ06Wkf0XV1+T1XFflX0U1+0rXTCmSMVYJ+T+/LRSd X-Received: by 2002:a17:906:aa4c:b0:a59:cf38:5338 with SMTP id a640c23a62f3a-a62641c8f04mr595871566b.19.1716799035728; Mon, 27 May 2024 01:37:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716799035; cv=pass; d=google.com; s=arc-20160816; b=WcS9HaDzPwLgm9zmcdigfJ5ZAryyCx0L5+AgCMXj0r8AyRhKmXpygVJqZIRi2lFHq2 ve+mtsgx9cMnZRSAlgRBbMbTJOu7GejBL6UM3S5VceoUb1HpWKbweHblyKD9BK4x2T+w DYfwPSjkuh/2ubLokdoOFrcbpC8tdYggpozbLnjqGpnXGjzc942AHeGUr3osPTaj5F3H JMe4guSjJUm9aJfHkKrOMjLBAI47ZlA/ypkwSMrVaj3ZZMe7U85IJJ3FMPZ+r2WsaZ8l rKx6N5V2M6l4/ocF8XLtCW8Iw7AobsgyRadlzScvgwZCnvQe8jhSEHiuet0sj06Gfc+I +C4Q== 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:dkim-signature; bh=6ewc2LUQ94iYhmeL+MlQNu0aDN9jkcSs6LpUL6X+zlA=; fh=jL3G/tszWpWpIzXUhlBMvVtqf+VDp7ZS/MjfnC3r/IU=; b=UBFlZ7SZsBLqnK5zPVgOwfflJXvYs2OlJmOOdRhiEiN7yAQVBDDLEJNod62tqua3Ns 6Qg2/MOrijW3LlZCqgEOYMGIbqFtkwAvfaQ1LEIkuGBmi3SL1JN+DsdOs95hMzqAQnPR 29tK/9OQEuPQH5AgBmD8gNRlDR7yG6w6MTADKWMW3Q8nKKHbML7IvED23C5dMKnzAXls Ezlh76DAGhyzUP1FfW0CrhDfyrIKxKMQ5J9glkkQp5GHkuf9tucWIofz6OjzqLLL3X+w nM+YmKGEsptkk/86iX7yVvXQmHWHTOK6E0npxs+HOovv8S789PiJapnzGSV/MMXDT4ew cZQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@toblux-com.20230601.gappssmtp.com header.s=20230601 header.b=DOoj805X; arc=pass (i=1 dkim=pass dkdomain=toblux-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-190226-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190226-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a626cc36e55si357827766b.385.2024.05.27.01.37.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 01:37:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190226-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@toblux-com.20230601.gappssmtp.com header.s=20230601 header.b=DOoj805X; arc=pass (i=1 dkim=pass dkdomain=toblux-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-190226-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190226-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 78FB61F2155A for ; Mon, 27 May 2024 08:37:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 415515C603; Mon, 27 May 2024 08:37:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toblux-com.20230601.gappssmtp.com header.i=@toblux-com.20230601.gappssmtp.com header.b="DOoj805X" Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35F7A5FB9A for ; Mon, 27 May 2024 08:37:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716799028; cv=none; b=fLhZAidoCv0Qj7OMCh6mlieVMePF1Cl5BzH0gS2zb7tDfpnwj7KRNzZPQGXtFJGTgu0GeSL2ESof+w05/hnqLFNiz8FOF67hgo+r6KIxpp40YFlvUVKfRqs0NApvwRUM2vwzy43i3d8twCpsQeMQx5Po3dY7Crd+fMJrnIo4uVY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716799028; c=relaxed/simple; bh=RbipRVg2tNyaG/cNib+sJw6bO31urPkoIZPQqa/oGQk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jKj8fdahgF49gKNZ9/UEyIqhqOcrK/rmCTYDj9S/5+H810k6vDLyNs37yM1YvZzxO32H6IZ0CeOnspkOxwSwzyZ6dY1ZJtHT7CLOZF7cgXnK9ZxSNTHyQ2Zg5UXyMALpfUc7CTuz+WN9ahmUGP2qz6+qC8UQ/HRW8Im35nX72Fw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toblux.com; spf=none smtp.mailfrom=toblux.com; dkim=pass (2048-bit key) header.d=toblux-com.20230601.gappssmtp.com header.i=@toblux-com.20230601.gappssmtp.com header.b=DOoj805X; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toblux.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toblux.com Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a6266ffdba8so210729766b.1 for ; Mon, 27 May 2024 01:37:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toblux-com.20230601.gappssmtp.com; s=20230601; t=1716799024; x=1717403824; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6ewc2LUQ94iYhmeL+MlQNu0aDN9jkcSs6LpUL6X+zlA=; b=DOoj805XSVFbKD3bZVlHXVl8s32C7iAYJCcCknY/L3SNIeVgbM5YvY9q6fuOkl4N0S Ia/23DbBjbuhibIq0rAadV99BO2SMFXQaD7sL1CrI8h7n8d+2H8Amm/3Bw2oInRoxMKu 8f+l83vPRHrjaBDT1x3ceLWHPSXhy8U4zXb1Freno6koiRkPG9ryFTnScaIMO0kNOi7W yx0vU6cifcDLlUW/Nd45FT/QycyQcbFgtVwmhXdEia0zN8wofoB7G2PXP7PX6L/4Mjbh Ebc5riB/8hqyq7JzhzcIsVe2dyElc/T6879XDZNChMhDSvWV89O0qmCSnmbDgLGmX+3t UggA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716799024; x=1717403824; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6ewc2LUQ94iYhmeL+MlQNu0aDN9jkcSs6LpUL6X+zlA=; b=rNSwhy6WLMGhngHgQ4843F1gF1jfW7fld50CRkayCWM6edalFbmv1u7w+vXeZabvRi JSWDA2q1BVOSNm+HpSA547UKaVBKW1R4a/Kcynmc0JlFGadhPA1ZHj9aGZYgvEpSRPmW VBBONHDSe1UMBhbojAxl2Cj08pjr8CIXKyIMcQ+XrTA0+2/9wtAJHIZkRlOp1ElCdqnZ 0f6MB94CZO4nnUk1lylH50xRC5LgHzCReeaaB88aIgpbN1AVVVLDYlnFSQhK+9cxiQRP 3qnvZPoCporxZ1Qz8SWes/hN3eGCVmSqWhIqaJA1HazuAKNUmoO9QPDj83euS+srf1LT zheQ== X-Forwarded-Encrypted: i=1; AJvYcCVZEYzFe0HVjpx1g7Wb88TYVotUVh8q9LlgsCd/UKqL56FpPgCZHn6ap7hIjJVbBq8OyjyoaMzSHCOz7rWI6KGqPUSJbboZn7CvOLyM X-Gm-Message-State: AOJu0YyNL5vWdI3drFlTM0xRd3raME3yG0SBDm7XDo1D6bPbJbGGxWqx xSAR9c/2NZ9tWxU4/mFnHSjCqJXTRieyv3x0C78/72C4nHaTKE8mqv8cKNpY8VU= X-Received: by 2002:a17:906:2a8b:b0:a59:9b8e:aa61 with SMTP id a640c23a62f3a-a62643e1448mr582253266b.35.1716799024362; Mon, 27 May 2024 01:37:04 -0700 (PDT) Received: from fedora.fritz.box (aftr-62-216-208-100.dynamic.mnet-online.de. [62.216.208.100]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a62f546025esm91292366b.56.2024.05.27.01.37.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 01:37:04 -0700 (PDT) From: Thorsten Blum To: markus.elfring@web.de Cc: Shyam-sundar.S-k@amd.com, hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org, thorsten.blum@toblux.com Subject: [PATCH v2] platform/x86/amd/pmf: Use memdup_user() Date: Mon, 27 May 2024 10:36:29 +0200 Message-ID: <20240527083628.210491-2-thorsten.blum@toblux.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <50d10f0b-d108-4057-be9c-a90e2398e810@web.de> References: <50d10f0b-d108-4057-be9c-a90e2398e810@web.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Switch to memdup_user() to overwrite the allocated memory only once instead of initializing the allocated memory to zero with kzalloc() and then immediately overwriting it with copy_from_user(). Fix the following Coccinelle/coccicheck warning reported by memdup_user.cocci: WARNING opportunity for memdup_user Signed-off-by: Thorsten Blum --- Changes in v2: - Update patch description after feedback from Markus Elfring --- drivers/platform/x86/amd/pmf/tee-if.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index b438de4d6bfc..1b53cabc9aa2 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -301,14 +301,9 @@ static ssize_t amd_pmf_get_pb_data(struct file *filp, const char __user *buf, return -EINVAL; /* re-alloc to the new buffer length of the policy binary */ - new_policy_buf = kzalloc(length, GFP_KERNEL); - if (!new_policy_buf) - return -ENOMEM; - - if (copy_from_user(new_policy_buf, buf, length)) { - kfree(new_policy_buf); - return -EFAULT; - } + new_policy_buf = memdup_user(buf, length); + if (IS_ERR(new_policy_buf)) + return PTR_ERR(new_policy_buf); kfree(dev->policy_buf); dev->policy_buf = new_policy_buf; -- 2.45.1