From patchwork Fri Jan 5 16:39:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harshit Mogalapalli X-Patchwork-Id: 185466 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp6336920dyb; Fri, 5 Jan 2024 08:48:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IG4nthrZJM065C21aiGpe16uh/UtcK0fQAGTJraOA/tqI/NmXOGnUvlTv39NeW3tVhJ/GB9 X-Received: by 2002:a17:906:db06:b0:a27:fc45:f4a0 with SMTP id xj6-20020a170906db0600b00a27fc45f4a0mr1167660ejb.134.1704473282406; Fri, 05 Jan 2024 08:48:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704473282; cv=none; d=google.com; s=arc-20160816; b=ATaBxbNV1QF+LeTqNNCBL2dhWSTH8N3rZ2IcFWJiGold2Z0IPaasYFJ6Wo38av6NDp DcGTTb3Z40t0IbAJOdva33pVRoMuW8BodSVgE0SM66MytOHU8QU9hvBv9M9Z3wJCzLxH /aon/cbKRhnXn2eht//xdO8Fyw80tTw2xVT1XSdngHBRK4Zv9AytzA+CT+w6GLXJWoed 2QMLS0S2azO9/E76jC4NejXoNtIY40ZS6P3qTC6e0cHxXQdmqtgdq/u8A8t4Y5GjOyN0 GHMF4UG5vm1q2JBAnbeEbskYgiGkxDUbkIXNtf/9u3LxJ5ENIgF5hr6s2YurMpQRnHEM hlPQ== ARC-Message-Signature: i=1; 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:message-id:date:subject:cc:to :from:dkim-signature; bh=gUFjJnldcCaXe2pdA55QFTTausQXLS6J9u68Q5ncGio=; fh=KmUzFFddG7KZNYCkeCIDi1bxmjcaqdx+Y3806NbOsYk=; b=LJX3f2cLGvjZ1otqb2CZ5gQ+CaSyY1JFEHMxlvMKnVBhrUTC/vL4jjVveN1/kzrgth tKrunrU3N79rHlR8+xwCYdEuQHLzpiJugLkqqKYEBMEIrVjmGzixjuh0yqpvl6eCMJl9 g32L++iLenv4m3PA7MTaBz/mfn4tCs9voLPoCK1DzTZeuJH2dsXI6r86RWXh+HriyQ4I 5SZ29ceDnpUNYJiwZ1rayTQWd/tOZVyCYntrnNmVrPxI5AEwFLuzAPuWgJ7u7QYDhft3 Z8qNW0Phw+MTZKBJ12KngpDhmXa2t9xHm4BmRuozt6eO8xYbXtOgyRO5/R3SSYsRbG47 tonA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-11-20 header.b=ORqlR1ML; spf=pass (google.com: domain of linux-kernel+bounces-18084-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18084-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id d4-20020a17090648c400b00a26b448eb77si727286ejt.71.2024.01.05.08.48.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 08:48:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18084-ouuuleilei=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=@oracle.com header.s=corp-2023-11-20 header.b=ORqlR1ML; spf=pass (google.com: domain of linux-kernel+bounces-18084-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18084-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com 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 0AC6F1F22CE4 for ; Fri, 5 Jan 2024 16:48:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E34032196; Fri, 5 Jan 2024 16:47:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="ORqlR1ML" X-Original-To: linux-kernel@vger.kernel.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 76A6531A9D; Fri, 5 Jan 2024 16:47:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 405GAdea015401; Fri, 5 Jan 2024 16:47:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=corp-2023-11-20; bh=gUFjJnldcCaXe2pdA55QFTTausQXLS6J9u68Q5ncGio=; b=ORqlR1MLCCOIG3+daQXHeCYON933hpPYh1ILuhU9wykDfFhUV1aZvhxhaVDrx1p9D6fM 2aOJ1h4hYvfz4DAwvprwtZmJ2jHZnGqqsAJOzW4DoqUIeh+ahTsnTlrkWOeQsxEDEBH+ 58mvhVBxMkClJada3G5MCHNPLvif8uekBuHnVPl0uTPPIshFvsyZJcb9swErMvQ/Ilte Jdig8AWksgxJW7NYXu360LlrWwbGhya4QPR6ysxkOa6sTgWPydKrGfQx90NCFwTYfdSP ljhvsM94B+9YdMumhgqDZV77kleNfrvyRaUUMZXLQyjF1y4Pd1DIhkxNUHPHiMO3Fjn6 4A== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ven25g3h4-16 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 05 Jan 2024 16:47:28 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 405G5Uiw009401; Fri, 5 Jan 2024 16:40:17 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3ve12hxey5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 05 Jan 2024 16:40:17 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 405GeGlf009736; Fri, 5 Jan 2024 16:40:17 GMT Received: from ca-dev112.us.oracle.com (ca-dev112.us.oracle.com [10.129.136.47]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3ve12hxewn-1; Fri, 05 Jan 2024 16:40:16 +0000 From: Harshit Mogalapalli To: linux-hardening@vger.kernel.org, keescook@chromium.org, error27@gmail.com, gustavoars@kernel.org, Bryan Tan , Vishnu Dasa , VMware PV-Drivers Reviewers , Arnd Bergmann , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Cc: vegard.nossum@oracle.com, darren.kenny@oracle.com, harshit.m.mogalapalli@oracle.com Subject: [PATCH v2 1/2] VMCI: Use struct_size() in kmalloc() Date: Fri, 5 Jan 2024 08:39:59 -0800 Message-ID: <20240105164001.2129796-1-harshit.m.mogalapalli@oracle.com> X-Mailer: git-send-email 2.42.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-05_08,2024-01-05_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 suspectscore=0 phishscore=0 adultscore=0 spamscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401050137 X-Proofpoint-ORIG-GUID: kgrNTprd204Py8fGpk9BJG_QYnC6j41a X-Proofpoint-GUID: kgrNTprd204Py8fGpk9BJG_QYnC6j41a X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787269776636113529 X-GMAIL-MSGID: 1787269776636113529 Use struct_size() instead of open coding. Suggested-by: Gustavo A. R. Silva Signed-off-by: Harshit Mogalapalli Reviewed-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/misc/vmw_vmci/vmci_datagram.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/misc/vmw_vmci/vmci_datagram.c b/drivers/misc/vmw_vmci/vmci_datagram.c index f50d22882476..ac6cb0c8d99b 100644 --- a/drivers/misc/vmw_vmci/vmci_datagram.c +++ b/drivers/misc/vmw_vmci/vmci_datagram.c @@ -224,8 +224,8 @@ static int dg_dispatch_as_host(u32 context_id, struct vmci_datagram *dg) return VMCI_ERROR_NO_MEM; } - dg_info = kmalloc(sizeof(*dg_info) + - (size_t) dg->payload_size, GFP_ATOMIC); + dg_info = kmalloc(struct_size(dg_info, msg_payload, dg->payload_size), + GFP_ATOMIC); if (!dg_info) { atomic_dec(&delayed_dg_host_queue_size); vmci_resource_put(resource);