netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org,
	linux-can@vger.kernel.org, kernel@pengutronix.de,
	Oliver Hartkopp <socketcan@hartkopp.net>,
	Dan Carpenter <dan.carpenter@linaro.org>
Subject: Re: [PATCH net-next 22/23] can: canxl: add virtual CAN network identifier support
Date: Mon, 19 Feb 2024 08:39:10 +0000	[thread overview]
Message-ID: <20240219083910.GR40273@kernel.org> (raw)
In-Reply-To: <20240213113437.1884372-23-mkl@pengutronix.de>

+Dan Carpenter

On Tue, Feb 13, 2024 at 12:25:25PM +0100, Marc Kleine-Budde wrote:
> From: Oliver Hartkopp <socketcan@hartkopp.net>
> 
> CAN XL data frames contain an 8-bit virtual CAN network identifier (VCID).
> A VCID value of zero represents an 'untagged' CAN XL frame.
> 
> To receive and send these optional VCIDs via CAN_RAW sockets a new socket
> option CAN_RAW_XL_VCID_OPTS is introduced to define/access VCID content:
> 
> - tx: set the outgoing VCID value by the kernel (one fixed 8-bit value)
> - tx: pass through VCID values from the user space (e.g. for traffic replay)
> - rx: apply VCID receive filter (value/mask) to be passed to the user space
> 
> With the 'tx pass through' option CAN_RAW_XL_VCID_TX_PASS all valid VCID
> values can be sent, e.g. to replay full qualified CAN XL traffic.
> 
> The VCID value provided for the CAN_RAW_XL_VCID_TX_SET option will
> override the VCID value in the struct canxl_frame.prio defined for
> CAN_RAW_XL_VCID_TX_PASS when both flags are set.
> 
> With a rx_vcid_mask of zero all possible VCID values (0x00 - 0xFF) are
> passed to the user space when the CAN_RAW_XL_VCID_RX_FILTER flag is set.
> Without this flag only untagged CAN XL frames (VCID = 0x00) are delivered
> to the user space (default).
> 
> The 8-bit VCID is stored inside the CAN XL prio element (only in CAN XL
> frames!) to not interfere with other CAN content or the CAN filters
> provided by the CAN_RAW sockets and kernel infrastruture.
> 
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
> Link: https://lore.kernel.org/all/20240212213550.18516-1-socketcan@hartkopp.net
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

Hi Oliver and Marc,

I understand this pull-request has been accepted.
But I noticed the problem described below which
seems worth bringing to your attention.

...

> @@ -786,6 +822,21 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,
>  		val = &ro->xl_frames;
>  		break;
>  
> +	case CAN_RAW_XL_VCID_OPTS:
> +		/* user space buffer to small for VCID opts? */
> +		if (len < sizeof(ro->raw_vcid_opts)) {
> +			/* return -ERANGE and needed space in optlen */
> +			err = -ERANGE;
> +			if (put_user(sizeof(ro->raw_vcid_opts), optlen))
> +				err = -EFAULT;
> +		} else {
> +			if (len > sizeof(ro->raw_vcid_opts))
> +				len = sizeof(ro->raw_vcid_opts);
> +			if (copy_to_user(optval, &ro->raw_vcid_opts, len))
> +				err = -EFAULT;
> +		}
> +		break;
> +
>  	case CAN_RAW_JOIN_FILTERS:
>  		if (len > sizeof(int))
>  			len = sizeof(int);

At the end of the switch statement the following code is present:


	if (put_user(len, optlen))
		return -EFAULT;
	if (copy_to_user(optval, val, len))
		return -EFAULT;
	return 0;

And the call to copy_to_user() depends on val being set.

It appears that for all other cases handled by the switch statement,
either val is set or the function returns. But neither is the
case for CAN_RAW_XL_VCID_OPTS which seems to mean that val may be used
uninitialised.

Flagged by Smatch.

...

  reply	other threads:[~2024-02-19  8:39 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-13 11:25 [PATCH net-next 0/23] pull-request: can-next 2024-02-13 Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 01/23] can: bcm: add recvmsg flags for own, local and remote traffic Marc Kleine-Budde
2024-02-14 10:10   ` patchwork-bot+netdevbpf
2024-02-13 11:25 ` [PATCH net-next 02/23] can: isotp: support dynamic flow control parameters Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 03/23] MAINTAINERS: add Stefan Mätje as maintainer for the esd electronics GmbH PCIe/402 CAN drivers Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 04/23] can: esd: add support for esd GmbH PCIe/402 CAN interface family Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 05/23] can: m_can: Start/Cancel polling timer together with interrupts Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 06/23] can: m_can: Move hrtimer init to m_can_class_register Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 07/23] can: m_can: Write transmit header and data in one transaction Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 08/23] can: m_can: Implement receive coalescing Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 09/23] can: m_can: Implement transmit coalescing Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 10/23] can: m_can: Add rx coalescing ethtool support Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 11/23] can: m_can: Add tx " Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 12/23] can: m_can: Use u32 for putidx Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 13/23] can: m_can: Cache tx putidx Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 14/23] can: m_can: Use the workqueue as queue Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 15/23] can: m_can: Introduce a tx_fifo_in_flight counter Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 16/23] can: m_can: Use tx_fifo_in_flight for netif_queue control Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 17/23] can: m_can: Implement BQL Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 18/23] can: m_can: Implement transmit submission coalescing Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 19/23] can: change can network drivers maintainer Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 20/23] can: kvaser_pciefd: Add support for Kvaser M.2 PCIe 4xCAN Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 21/23] can: softing: remove redundant NULL check Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 22/23] can: canxl: add virtual CAN network identifier support Marc Kleine-Budde
2024-02-19  8:39   ` Simon Horman [this message]
2024-02-19  9:41     ` Marc Kleine-Budde
2024-02-19 20:15       ` Oliver Hartkopp
2024-02-20  7:29         ` Marc Kleine-Budde
2024-02-13 11:25 ` [PATCH net-next 23/23] MAINTAINERS: can: xilinx_can: remove Naga Sureshkumar Relli Marc Kleine-Budde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240219083910.GR40273@kernel.org \
    --to=horms@kernel.org \
    --cc=dan.carpenter@linaro.org \
    --cc=davem@davemloft.net \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=socketcan@hartkopp.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).