public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] firewire: cdev: Fix function cast error
@ 2021-09-24 10:57 Gustavo A. R. Silva
  2021-09-24 12:47 ` Kees Cook
  0 siblings, 1 reply; 3+ messages in thread
From: Gustavo A. R. Silva @ 2021-09-24 10:57 UTC (permalink / raw)
  To: Stefan Richter
  Cc: linux1394-devel, linux-kernel, Gustavo A. R. Silva,
	linux-hardening

Fix the following function cast error when building with
-Wcast-function-type:

drivers/firewire/core-cdev.c: In function ‘ioctl_create_iso_context’:
drivers/firewire/core-cdev.c:985:8: error: cast between incompatible function types from ‘void (*)(struct fw_iso_context *, dma_addr_t,  void *)’ {aka ‘void (*)(struct fw_iso_context *, long long unsigned int,  void *)’} to ‘void (*)(struct fw_iso_context *, u32,  size_t,  void *, void *)’ {aka ‘void (*)(struct fw_iso_context *, unsigned int,  long unsigned int,  void *, void *)’} [-Werror=cast-function-type]
  985 |   cb = (fw_iso_callback_t)iso_mc_callback;
      |        ^
cc1: all warnings being treated as errors

This helps with the ongoing efforts to globally enable -Wcast-function-type,
so when Control Flow Integrity checking lands in the kernel, incompatible
function type casting doesn't interfere with it.

Link: https://github.com/KSPP/linux/issues/20
Link: https://github.com/KSPP/linux/issues/102
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 drivers/firewire/core-cdev.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
index fb6c651214f3..fd2923599667 100644
--- a/drivers/firewire/core-cdev.c
+++ b/drivers/firewire/core-cdev.c
@@ -957,7 +957,10 @@ static int ioctl_create_iso_context(struct client *client, union ioctl_arg *arg)
 {
 	struct fw_cdev_create_iso_context *a = &arg->create_iso_context;
 	struct fw_iso_context *context;
-	fw_iso_callback_t cb;
+	union callback {
+		fw_iso_callback_t sc;
+		fw_iso_mc_callback_t mc;
+	} cb;
 	int ret;
 
 	BUILD_BUG_ON(FW_CDEV_ISO_CONTEXT_TRANSMIT != FW_ISO_CONTEXT_TRANSMIT ||
@@ -970,7 +973,7 @@ static int ioctl_create_iso_context(struct client *client, union ioctl_arg *arg)
 		if (a->speed > SCODE_3200 || a->channel > 63)
 			return -EINVAL;
 
-		cb = iso_callback;
+		cb.sc = iso_callback;
 		break;
 
 	case FW_ISO_CONTEXT_RECEIVE:
@@ -978,11 +981,11 @@ static int ioctl_create_iso_context(struct client *client, union ioctl_arg *arg)
 		    a->channel > 63)
 			return -EINVAL;
 
-		cb = iso_callback;
+		cb.sc = iso_callback;
 		break;
 
 	case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL:
-		cb = (fw_iso_callback_t)iso_mc_callback;
+		cb.mc = iso_mc_callback;
 		break;
 
 	default:
@@ -990,7 +993,7 @@ static int ioctl_create_iso_context(struct client *client, union ioctl_arg *arg)
 	}
 
 	context = fw_iso_context_create(client->device->card, a->type,
-			a->channel, a->speed, a->header_size, cb, client);
+			a->channel, a->speed, a->header_size, cb.sc, client);
 	if (IS_ERR(context))
 		return PTR_ERR(context);
 	if (client->version < FW_CDEV_VERSION_AUTO_FLUSH_ISO_OVERFLOW)
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] firewire: cdev: Fix function cast error
  2021-09-24 10:57 [PATCH][next] firewire: cdev: Fix function cast error Gustavo A. R. Silva
@ 2021-09-24 12:47 ` Kees Cook
  2021-09-24 13:04   ` Gustavo A. R. Silva
  0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2021-09-24 12:47 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Stefan Richter
  Cc: linux1394-devel, linux-kernel, linux-hardening



On September 24, 2021 3:57:33 AM PDT, "Gustavo A. R. Silva" <gustavoars@kernel.org> wrote:
>Fix the following function cast error when building with
>-Wcast-function-type:
>
>drivers/firewire/core-cdev.c: In function ‘ioctl_create_iso_context’:
>drivers/firewire/core-cdev.c:985:8: error: cast between incompatible function types from ‘void (*)(struct fw_iso_context *, dma_addr_t,  void *)’ {aka ‘void (*)(struct fw_iso_context *, long long unsigned int,  void *)’} to ‘void (*)(struct fw_iso_context *, u32,  size_t,  void *, void *)’ {aka ‘void (*)(struct fw_iso_context *, unsigned int,  long unsigned int,  void *, void *)’} [-Werror=cast-function-type]
>  985 |   cb = (fw_iso_callback_t)iso_mc_callback;
>      |        ^
>cc1: all warnings being treated as errors
>
>This helps with the ongoing efforts to globally enable -Wcast-function-type,
>so when Control Flow Integrity checking lands in the kernel, incompatible
>function type casting doesn't interfere with it.
>
>Link: https://github.com/KSPP/linux/issues/20
>Link: https://github.com/KSPP/linux/issues/102
>Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

I thought this looked familiar...

https://lore.kernel.org/lkml/20200530090839.7895-1-oscar.carter@gmx.com/

I think someone just needs to pick this up since it got past review, etc.

-Kees


>---
> drivers/firewire/core-cdev.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
>diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
>index fb6c651214f3..fd2923599667 100644
>--- a/drivers/firewire/core-cdev.c
>+++ b/drivers/firewire/core-cdev.c
>@@ -957,7 +957,10 @@ static int ioctl_create_iso_context(struct client *client, union ioctl_arg *arg)
> {
> 	struct fw_cdev_create_iso_context *a = &arg->create_iso_context;
> 	struct fw_iso_context *context;
>-	fw_iso_callback_t cb;
>+	union callback {
>+		fw_iso_callback_t sc;
>+		fw_iso_mc_callback_t mc;
>+	} cb;
> 	int ret;
> 
> 	BUILD_BUG_ON(FW_CDEV_ISO_CONTEXT_TRANSMIT != FW_ISO_CONTEXT_TRANSMIT ||
>@@ -970,7 +973,7 @@ static int ioctl_create_iso_context(struct client *client, union ioctl_arg *arg)
> 		if (a->speed > SCODE_3200 || a->channel > 63)
> 			return -EINVAL;
> 
>-		cb = iso_callback;
>+		cb.sc = iso_callback;
> 		break;
> 
> 	case FW_ISO_CONTEXT_RECEIVE:
>@@ -978,11 +981,11 @@ static int ioctl_create_iso_context(struct client *client, union ioctl_arg *arg)
> 		    a->channel > 63)
> 			return -EINVAL;
> 
>-		cb = iso_callback;
>+		cb.sc = iso_callback;
> 		break;
> 
> 	case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL:
>-		cb = (fw_iso_callback_t)iso_mc_callback;
>+		cb.mc = iso_mc_callback;
> 		break;
> 
> 	default:
>@@ -990,7 +993,7 @@ static int ioctl_create_iso_context(struct client *client, union ioctl_arg *arg)
> 	}
> 
> 	context = fw_iso_context_create(client->device->card, a->type,
>-			a->channel, a->speed, a->header_size, cb, client);
>+			a->channel, a->speed, a->header_size, cb.sc, client);
> 	if (IS_ERR(context))
> 		return PTR_ERR(context);
> 	if (client->version < FW_CDEV_VERSION_AUTO_FLUSH_ISO_OVERFLOW)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] firewire: cdev: Fix function cast error
  2021-09-24 12:47 ` Kees Cook
@ 2021-09-24 13:04   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2021-09-24 13:04 UTC (permalink / raw)
  To: Kees Cook, Gustavo A. R. Silva, Stefan Richter
  Cc: linux1394-devel, linux-kernel, linux-hardening



On 9/24/21 07:47, Kees Cook wrote:

> I thought this looked familiar...
> 
> https://lore.kernel.org/lkml/20200530090839.7895-1-oscar.carter@gmx.com/

Oh, cool. :)

> I think someone just needs to pick this up since it got past review, etc.

Yeah. I can take it in my -next tree if nobody cares.

Thanks
--
Gustavo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-24 13:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-24 10:57 [PATCH][next] firewire: cdev: Fix function cast error Gustavo A. R. Silva
2021-09-24 12:47 ` Kees Cook
2021-09-24 13:04   ` Gustavo A. R. Silva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox