From patchwork Sun Jun 2 16:13:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erick Archer X-Patchwork-Id: 13682962 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2046.outbound.protection.outlook.com [40.92.89.46]) (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 CFF884AEEA; Sun, 2 Jun 2024 16:13:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.89.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717344815; cv=fail; b=sujelD5GeGX/1Cfm7H73p5RWJRzg5OA6qLzfzblYCxxbS0Vi4BblEBzUicXkAKSQ6kZaxXXaQPEqdcK34e+W813c31XeFE7moURbHwQsKC8i0LwpitS09I1/2bzVke/HWzofjUqLU0loL76VpT31SFc9+L31m9s+pNRrpWzrHGk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717344815; c=relaxed/simple; bh=mjDoxKsP3WTmpqfBIZbNgtnHfvB287/Sjy/yhhXlE8Y=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=Mf/kMPfAbN+T3T0jUQ2I1045/WJge0rd6UbTYle/3BdCg1OQsyvDDAZxy8uXFi1YGR1/Pf7MDAx0VOydA4yYZGrYLAq2ZtH1pG4W3P6/ipfkf9a62bUNZdwtbETTkasLBk5PgtmjutX9CUZsPSU9miVx1Va0msXItwTDi66W4GA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=uT2BGPXT; arc=fail smtp.client-ip=40.92.89.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="uT2BGPXT" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DcCj5fl8x1O2l8Cm87P29nxDCyPD7nQpOZpmgYY1aN4KdtUUyIuTdYehrmev1Z6Um47DWsHw04fg7SiStgeA+/xme6FDPUN1rEjJO5LXbBVeUAT84Q97hVpIGw2kfYFxdgx4acCP4yzzeZSva6e0yAaZfbjzXK7CjnwitptSqhduo9m13gJbjEV5YfIfZhJrnQPyhw1ZR1qs+qqqpjKW4WYkUU3oj3G/G6NAe7Y0aUm8VmyfshohF5JZobVWSEp8B6FpwrkEbduD+gp1XdywGOSddve5w6dXHqiezXtjDyhE2s1URsf0P1NN2nUJ3l1ckMWJKmMsf7NEXtt3Pd0Dvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3heqShnV9rcsVWKCOJahCr/q/jH5bAyJbwsMOKB7PUg=; b=BnsstJnsJ92ZYTdPyr1o9CqtDs5dEP7YoOxJECfQdLY6UTbivL2dxB8DqYLuyCnokcSfhZf9dOkNkL7sWEI6/Iy+lm6QyvEp02TxIqh57A/+Y17+U13d7hRA/OE67tn3KgLMs+johKGjxcEvYQ9hBkLO4gx66JTP4JZMDqo6HqgovxlDVmGRA5P383v229bQBWvnb/kW9z76UUlGZMyWBllO5c7kCFsbKkw9hhxWmSl3113yeTNJRuK7gTlMcQSrRdZUfjqHxHArryahiwoFVD8iKoHhvODOdoPOg7CqZvlSG64yc9gDAUcKijyvm+vA3lneUDCpbJEf9aCWDVfYpw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3heqShnV9rcsVWKCOJahCr/q/jH5bAyJbwsMOKB7PUg=; b=uT2BGPXTCKhP1I+i61l5CmGWS+iLFr3Rn4m09Qx/ENCas6ZfUBBnK7b8xeG7XS5irxlJUfxux4yTE6Wlhi01CWEQnJZeLBfE1porG5CblJlrePPpzDIYZUuNGLHFfwWcfybNAw/a+AXqfL0YWgXxFPIjjjf/JMiz4pJgoEeuHqW3biHGqHyENV6xHQcGAHZdmM53B9pBNARMMnryfqpF4bszxu2FSgsLDZST7kh6mU6Imsvjc0J2pXcnYPJDZGNhZw6eLHKb7bxeGhR2ZCgpooibAghp4HPux2Mb98OT/IBaZ+XludS/IaVMuur3aIT4afsU8b5FeH6c/M7MO372CA== Received: from AS8PR02MB7237.eurprd02.prod.outlook.com (2603:10a6:20b:3f1::10) by DB8PR02MB5770.eurprd02.prod.outlook.com (2603:10a6:10:fa::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.23; Sun, 2 Jun 2024 16:13:31 +0000 Received: from AS8PR02MB7237.eurprd02.prod.outlook.com ([fe80::409b:1407:979b:f658]) by AS8PR02MB7237.eurprd02.prod.outlook.com ([fe80::409b:1407:979b:f658%5]) with mapi id 15.20.7633.021; Sun, 2 Jun 2024 16:13:31 +0000 From: Erick Archer To: Kalle Valo , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Greg Kroah-Hartman , Johannes Berg , Alan Stern Cc: Erick Archer , linux-wireless@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH 0/2] atmel: at76c50x: improve code robustness Date: Sun, 2 Jun 2024 18:13:08 +0200 Message-ID: X-Mailer: git-send-email 2.25.1 X-TMN: [nFFslZofQzBzvzFCAlgS6ugklWOoWbUC] X-ClientProxiedBy: MA4P292CA0012.ESPP292.PROD.OUTLOOK.COM (2603:10a6:250:2d::9) To AS8PR02MB7237.eurprd02.prod.outlook.com (2603:10a6:20b:3f1::10) X-Microsoft-Original-Message-ID: <20240602161310.5671-1-erick.archer@outlook.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR02MB7237:EE_|DB8PR02MB5770:EE_ X-MS-Office365-Filtering-Correlation-Id: 3fde4410-a189-4712-c0cd-08dc831ef1ca X-MS-Exchange-SLBlob-MailProps: iS5pQZgsAQDCnzYXbDrEqffj9TNTzq274zgD0ghQ6GNBjcM44VqSgrncecWltcTsxG9F+agAJYDXfQx7Gw+Ha9UWJqFVwC6OLiuHQKLkXpnC9+v2MSZU1Az8ZzWqTyW2nuNc0NmdrFhlsH7gLBup3c99BN9ld360rSaxVBF90ztgyuj6I+XsqPo1R5ASMuXEON2lx8vPYH3kVzExqTujOKwmA/yTn9OqRoWEaEmb4bhI7ij9SA768/V7pjF53nzY6ri6lJUI7uKTp/Ye8RA0j/V7zQHE+fgPTXigEhmkbDG0BIlE+92RF1SBH5MykSFS8o16o17mHsuwzMFBdn6Z16+kuvULak3BdZ0MmiLg0uUiqdoYuHYM1XSNa+0hscBP3rC4T7LUL05rkQGggnoavJGXbGd1wovap9uowDKgSJjDOPF3KfS18opUKhJlX7i744uiJ/95Qna4cZu2H5+l19mS1N+fxVrycLDA6zumfycsvYpiae/6/J39o02My3DY3XzfOhuz2nZOHEAO6vfptHHoFMXsbClNIbu9+gYKdjT0eonUuAGTBU4o4dyg0vvUvlzA5gObx1KgxBO0eOR9UH+qOxOfiWmfNq4n8+81G7Wz+rEvu+uue/tFOyPHyZxFkCDK34/rzQe4J+Vox5wpiUTguOMJkXo2vstYVQK8VwzET6Uimg52EgqREcC2rgD0gnDw/NUH9ihUh4Y4Vy3BPuhb2xL1uFcH//OrEbTxw9HEpoSrGoAkLX8a8VpF56BY9MuXXKDak7j/8bZ/0lcC+QtWRk32/1QB4KS4oWLuOmffjVXcOSuqvORD/7hCADJf X-Microsoft-Antispam: BCL:0;ARA:14566002|461199019|1602099003|3412199016|440099019|1710799017; X-Microsoft-Antispam-Message-Info: 9Frcwk+g6ZHSyttjCccOOzao9mUFeshS+SK96HYTA3YK3Jepb49VWTt+GGQ/UbtoDTnpXfeHl+iO1icONYNZ7ZX4ajAJfE7I+9mnYLokUy9TfIdEG+QUaioAVuxlJf50ZOTKRZytPl8OYa2euiuF8877wp0BFkhswVLsBPUzDetFChoqSyORJsQtBMmTnMODr8UIWWJt4PzKBHBqn3ZpVioh1wH7gyq4xSMdogIU/9lgO9ttMvIBnMtIENEfQOf9cbzu2Ser3yIC8k42nbfsQAD/Zb56QYyvajqB4r50BBLWderKmCCjJQ3aHeGzrXING1FjHSlv1rwifl7Nh6f215acm2p7c21msRjbuZuoUwfgyXMf/RTqPDUb8omJWYGMEeozkNHPdbWKpEW40QW9jWZo9+0iryBxOKUweuQwX037i8ekC9A3GoYxXz+wU61O+hi7mrSG3EfoniV4BI5iYyIRAFGhg8EaJ9MCwbz2f17XWI5LpBl8jZkjc381aEjUEbFQk+p7T7lUDrhHtRxaqcCdeGJuxJFBS0n6yGrAG58C/2ocea2+ShJcl0ByHYIFkyi5qwyGaIn1uaTLg6MPm/Q8iymANQB1zjj4M2k2OQosEAPpwp+4DF2C+91LUlc43fBdq55tsCpUgI7v4z0J6EWfSgfgJgN1aabDn4rLzn7qo449i+ibt0LonyPIf3x0skFDWRelEDXSVB3G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8tXVa0fleG4pvRziY5Pmo9fli/LaSAEneglHm+ieR541iAgDsb3QfkFuNXx705ICiDxZUV3G6PGsLFUisEkPmofvixVwLgd6k5D2JE+OXtSq0m2KxJ9WBh3Ye2W16lYaPICGaVopxoaBpHoeCVTyQhvlEh7EZ+9/LAariWEzlXpD1gnu7JqaJg3Zc6Upfs7lVQ5daMuh166OKYNuCIMC+UcSwogGGH3ZpCOOId/SmPUyL0RAlUdHKeawNl1a1PpeiRPohg X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3fde4410-a189-4712-c0cd-08dc831ef1ca X-MS-Exchange-CrossTenant-AuthSource: AS8PR02MB7237.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2024 16:13:31.1643 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR02MB5770 Hi, This series of patches attempts to improve the at76c50x code robustness. In the first patch, it is preferred to use sizeof(*pointer) instead of sizeof(type) due to the type of the variable can change and one needs not change the former (unlike the latter). The second patch is an effort to get rid of all multiplications from allocation functions in order to prevent integer overflows [1][2]. As the "struct at76_command" ends in a flexible array the preferred way in the kernel is to use the struct_size() helper to do the arithmetic instead of the calculation "size + count" in the kmalloc() function. At the same time, prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions). This way, the code is more readable and safer. Regards, Erick Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [1] Link: https://github.com/KSPP/linux/issues/160 [2] --- Erick Archer (2): atmel: at76c50x: use sizeof(*pointer) instead of sizeof(type) atmel: at76c50x: prefer struct_size over open coded arithmetic drivers/net/wireless/atmel/at76c50x-usb.c | 56 ++++++++++------------- drivers/net/wireless/atmel/at76c50x-usb.h | 2 +- 2 files changed, 26 insertions(+), 32 deletions(-)