linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] micrel: ksz8851: fixes struct pointer issue
@ 2022-08-22 21:39 Jerry Ray
  2022-08-24 12:10 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Jerry Ray @ 2022-08-22 21:39 UTC (permalink / raw)
  To: David S . Miller ,
	Jakub Kicinski, Jerry Ray, netdev, linux-kernel, UNGLinuxDriver

Issue found during code review. This bug has no impact as long as the
ks8851_net structure is the first element of the ks8851_net_spi structure.
As long as the offset to the ks8851_net struct is zero, the container_of()
macro is subtracting 0 and therefore no damage done. But if the
ks8851_net_spi struct is ever modified such that the ks8851_net struct
within it is no longer the first element of the struct, then the bug would
manifest itself and cause problems.

struct ks8851_net is contained within ks8851_net_spi.
ks is contained within kss.
kss is the priv_data of the netdev structure.

Signed-off-by: Jerry Ray <jerry.ray@microchip.com>
---
 drivers/net/ethernet/micrel/ks8851_spi.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/micrel/ks8851_spi.c b/drivers/net/ethernet/micrel/ks8851_spi.c
index 479406ecbaa3..13c76352ae8d 100644
--- a/drivers/net/ethernet/micrel/ks8851_spi.c
+++ b/drivers/net/ethernet/micrel/ks8851_spi.c
@@ -413,7 +413,8 @@ static int ks8851_probe_spi(struct spi_device *spi)
 
 	spi->bits_per_word = 8;
 
-	ks = netdev_priv(netdev);
+	kss = netdev_priv(netdev);
+	ks = &kss->ks8851;
 
 	ks->lock = ks8851_lock_spi;
 	ks->unlock = ks8851_unlock_spi;
@@ -433,8 +434,6 @@ static int ks8851_probe_spi(struct spi_device *spi)
 		 IRQ_RXPSI)	/* RX process stop */
 	ks->rc_ier = STD_IRQ;
 
-	kss = to_ks8851_spi(ks);
-
 	kss->spidev = spi;
 	mutex_init(&kss->lock);
 	INIT_WORK(&kss->tx_work, ks8851_tx_work);
-- 
2.17.1


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

* Re: [PATCH] micrel: ksz8851: fixes struct pointer issue
  2022-08-22 21:39 [PATCH] micrel: ksz8851: fixes struct pointer issue Jerry Ray
@ 2022-08-24 12:10 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-08-24 12:10 UTC (permalink / raw)
  To: Jerry Ray; +Cc: davem, kuba, netdev, linux-kernel, UNGLinuxDriver

Hello:

This patch was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Mon, 22 Aug 2022 16:39:32 -0500 you wrote:
> Issue found during code review. This bug has no impact as long as the
> ks8851_net structure is the first element of the ks8851_net_spi structure.
> As long as the offset to the ks8851_net struct is zero, the container_of()
> macro is subtracting 0 and therefore no damage done. But if the
> ks8851_net_spi struct is ever modified such that the ks8851_net struct
> within it is no longer the first element of the struct, then the bug would
> manifest itself and cause problems.
> 
> [...]

Here is the summary with links:
  - micrel: ksz8851: fixes struct pointer issue
    https://git.kernel.org/netdev/net-next/c/fef5de753ff0

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2022-08-24 12:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-22 21:39 [PATCH] micrel: ksz8851: fixes struct pointer issue Jerry Ray
2022-08-24 12:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).