From patchwork Wed Nov 13 14:04:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 843071 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 486901F4FC6; Wed, 13 Nov 2024 14:04:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731506690; cv=none; b=ifRFFqk9vZIq9f4HcWeBfNRkqAkgULK0wzL320LKhlR2X6kmjhOrQNJizLCgCI6gOsgh5Tf6s1TYAD2pAFIhp9VTzKG1Kfy8Y1TdiU5jEKxSToLsmbKQEQi7SHlY6oxQbEcjRYjXvaVFAUvqC80IsErPn4Lv+/kNlyKnAGcEyng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731506690; c=relaxed/simple; bh=xEIsm82Us/2uPAaz8oc2KoXxc6pXZstnJKLajTBWF3w=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=KVgSI7NoQ/u9gIlgLD6Yc6kjI6KtLQwf5flopE12JIzkpKJrMqT3UUyN+JI0gXEnK2/kcIszxkYfh9vDOdl+fEiHel8eEwjBN7Rb+FqbB0m2+eqPs6cXQ3UTndV0OPVO2PFkOsjHvFLCA2YeuRAkJnNWM5YPXKJk0Ib1qqu8xlM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=uOvyWuzG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="uOvyWuzG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CFE6C4CED2; Wed, 13 Nov 2024 14:04:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1731506689; bh=xEIsm82Us/2uPAaz8oc2KoXxc6pXZstnJKLajTBWF3w=; h=From:To:Cc:Subject:Date:From; b=uOvyWuzGRZMZ3v8WO8IC97opH+xrf2NHI3nX2a9dd8qxplPBFinZD231V7lqkN7OB j6/SSUqK2XWYSKmnPrpxfKp9x4juyh7zXg+WNdGmtgOZnALVKD1TaLFXtqe+TqnBbi YAZ5QiwQ5L2zHXf3SilNlwgptxSYActnR2rr/H+A= From: Greg Kroah-Hartman To: linux-usb@vger.kernel.org Cc: stern@rowland.harvard.edu, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, Johan Hovold , Grant Grundler , Yajun Deng , Oliver Neukum , Douglas Anderson Subject: [PATCH v2 1/2] USB: make to_usb_driver() use container_of_const() Date: Wed, 13 Nov 2024 15:04:40 +0100 Message-ID: <2024111339-shaky-goldsmith-b233@gregkh> X-Mailer: git-send-email 2.47.0 Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2292; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=xEIsm82Us/2uPAaz8oc2KoXxc6pXZstnJKLajTBWF3w=; b=owGbwMvMwCRo6H6F97bub03G02pJDOkmG7+z/Tt2R0tJ+FKhXnzxCbMHB7Z8lJb+JTLTKcd8g 7hKSuOVjlgWBkEmBlkxRZYv23iO7q84pOhlaHsaZg4rE8gQBi5OAZgIFwfD/OhtkttPJP65/eS8 p8qOWTb19rk5Sxjml/8+VfPrwuok9W9mD+b2Mj+vSPDnAgA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Turns out that we have some const pointers being passed to to_usb_driver() but were not catching this. Change the macro to properly propagate the const-ness of the pointer so that we will notice when we try to write to memory that we shouldn't be writing to. This requires fixing up the usb_match_dynamic_id() function as well, because it can handle a const * to struct usb_driver. Cc: Johan Hovold Cc: Alan Stern Cc: Grant Grundler Cc: Yajun Deng Cc: Oliver Neukum Cc: Douglas Anderson Cc: linux-usb@vger.kernel.org Signed-off-by: Greg Kroah-Hartman Reviewed-by: Douglas Anderson --- v2: reordered patches, goes on top of series submitted at https://lore.kernel.org/r/2024111322-kindly-finalist-d247@gregkh drivers/usb/core/driver.c | 4 ++-- include/linux/usb.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 9ea955a3d115..bc5c561bdbd5 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -228,7 +228,7 @@ static void usb_free_dynids(struct usb_driver *usb_drv) } static const struct usb_device_id *usb_match_dynamic_id(struct usb_interface *intf, - struct usb_driver *drv) + const struct usb_driver *drv) { struct usb_dynid *dynid; @@ -890,7 +890,7 @@ static int usb_device_match(struct device *dev, const struct device_driver *drv) } else if (is_usb_interface(dev)) { struct usb_interface *intf; - struct usb_driver *usb_drv; + const struct usb_driver *usb_drv; const struct usb_device_id *id; /* device drivers never match interfaces */ diff --git a/include/linux/usb.h b/include/linux/usb.h index b66b1af3e439..7a9e96f9d886 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -1243,7 +1243,7 @@ struct usb_driver { unsigned int disable_hub_initiated_lpm:1; unsigned int soft_unbind:1; }; -#define to_usb_driver(d) container_of(d, struct usb_driver, driver) +#define to_usb_driver(d) container_of_const(d, struct usb_driver, driver) /** * struct usb_device_driver - identifies USB device driver to usbcore From patchwork Wed Nov 13 14:04:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 843458 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2BC02259C; Wed, 13 Nov 2024 14:04:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731506687; cv=none; b=kSiO12f7Rt1KGXRfRIHOZTmrNGe44LlmCT+r+ureGYeG1cVO67XEaW3w248yn0UGpGl870uLFAgBrwEsxxmBjdAjzB2obZomgjvW2H35UIXhs3MXh6CsHtkzej9xliuFQ882ZOeW/4zxQafbpXNxiTJM6gqk1DiHmq5imAda1ZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731506687; c=relaxed/simple; bh=Kuwa1HPUSpT4CGmTqdocbMhT6tHj/MeXv9HrB20dCqg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PJRdvLrkj9NLIUyG79v/WaZzu6Kx5uT12G/RjjOfFSyP5nRqQGVHcj0M4L+7e1qjbeVo05dBl1vgT6w8dNkMLJA0uZEoCKxqixauBJBjSgm5NsnjSHRD4pypd4+jWg1HPjJihe2x1jGtTn00tnoee5ikH9SUiZe2FgiQB+yrMYc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ZnxD/2RM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ZnxD/2RM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E830AC4CEC3; Wed, 13 Nov 2024 14:04:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1731506686; bh=Kuwa1HPUSpT4CGmTqdocbMhT6tHj/MeXv9HrB20dCqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZnxD/2RMVZS5ae0umyTA0TheVwk0nRHZecueoWKMIeSwmpmVNDyz4UZ0F8N10tOqt +AsQnrY3C4XYy40AJ4w3YuVfu+S5pW0JTAkygX4oUaNOnu0RJ9Gt1KB4RnhCsKBgLv LQpP3/+2tihLLkkUZKcTy+kim7+fHYsAlBIHWMWs= From: Greg Kroah-Hartman To: linux-usb@vger.kernel.org Cc: stern@rowland.harvard.edu, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, Johan Hovold , Grant Grundler , Yajun Deng , Oliver Neukum , Douglas Anderson Subject: [PATCH v2 2/2] USB: make to_usb_device_driver() use container_of_const() Date: Wed, 13 Nov 2024 15:04:41 +0100 Message-ID: <2024111342-lagoon-reapprove-5e49@gregkh> X-Mailer: git-send-email 2.47.0 In-Reply-To: <2024111339-shaky-goldsmith-b233@gregkh> References: <2024111339-shaky-goldsmith-b233@gregkh> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3207; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=Kuwa1HPUSpT4CGmTqdocbMhT6tHj/MeXv9HrB20dCqg=; b=owGbwMvMwCRo6H6F97bub03G02pJDOkmG39tml/umaMoMW39rWmih2S4ulOuB713sHwruKuqP NRRe+K9jlgWBkEmBlkxRZYv23iO7q84pOhlaHsaZg4rE8gQBi5OAZiIVxnDfJ8lsff3Xfwz98K7 3ssW3qdmmRxOY2VYcEL4VJSE8JeZe+SOqSzY95HrvPycUgA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Turns out that we have some const pointers being passed to to_usb_device_driver() but were not catching this. Change the macro to properly propagate the const-ness of the pointer so that we will notice when we try to write to memory that we shouldn't be writing to. This requires fixing up the usb_driver_applicable() function as well, because it can handle a const * to struct usb_driver. Cc: Johan Hovold Cc: Alan Stern Cc: Grant Grundler Cc: Yajun Deng Cc: Oliver Neukum Cc: Douglas Anderson Cc: linux-usb@vger.kernel.org Signed-off-by: Greg Kroah-Hartman Reviewed-by: Douglas Anderson --- v2: reordered patches, goes on top of series submitted at https://lore.kernel.org/r/2024111322-kindly-finalist-d247@gregkh drivers/usb/core/driver.c | 4 ++-- drivers/usb/core/usb.h | 2 +- include/linux/usb.h | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index bc5c561bdbd5..f203fdbfb6f6 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -850,7 +850,7 @@ const struct usb_device_id *usb_device_match_id(struct usb_device *udev, EXPORT_SYMBOL_GPL(usb_device_match_id); bool usb_driver_applicable(struct usb_device *udev, - struct usb_device_driver *udrv) + const struct usb_device_driver *udrv) { if (udrv->id_table && udrv->match) return usb_device_match_id(udev, udrv->id_table) != NULL && @@ -870,7 +870,7 @@ static int usb_device_match(struct device *dev, const struct device_driver *drv) /* devices and interfaces are handled separately */ if (is_usb_device(dev)) { struct usb_device *udev; - struct usb_device_driver *udrv; + const struct usb_device_driver *udrv; /* interface drivers never match devices */ if (!is_usb_device_driver(drv)) diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index b8324ea05b20..a9b37aeb515b 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h @@ -75,7 +75,7 @@ extern int usb_match_device(struct usb_device *dev, extern const struct usb_device_id *usb_device_match_id(struct usb_device *udev, const struct usb_device_id *id); extern bool usb_driver_applicable(struct usb_device *udev, - struct usb_device_driver *udrv); + const struct usb_device_driver *udrv); extern void usb_forced_unbind_intf(struct usb_interface *intf); extern void usb_unbind_and_rebind_marked_interfaces(struct usb_device *udev); diff --git a/include/linux/usb.h b/include/linux/usb.h index 7a9e96f9d886..cfa8005e24f9 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -1294,8 +1294,7 @@ struct usb_device_driver { unsigned int supports_autosuspend:1; unsigned int generic_subclass:1; }; -#define to_usb_device_driver(d) container_of(d, struct usb_device_driver, \ - driver) +#define to_usb_device_driver(d) container_of_const(d, struct usb_device_driver, driver) /** * struct usb_class_driver - identifies a USB driver that wants to use the USB major number