lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 2 Jun 2024 18:21:06 +0200
From: Andrew Lunn <andrew@...n.ch>
To: Yojana Mallik <y-mallik@...com>
Cc: schnelle@...ux.ibm.com, wsa+renesas@...g-engineering.com,
	diogo.ivo@...mens.com, rdunlap@...radead.org, horms@...nel.org,
	vigneshr@...com, rogerq@...com, danishanwar@...com,
	pabeni@...hat.com, kuba@...nel.org, edumazet@...gle.com,
	davem@...emloft.net, netdev@...r.kernel.org,
	linux-kernel@...r.kernel.org, srk@...com, rogerq@...nel.org
Subject: Re: [PATCH net-next v2 1/3] net: ethernet: ti: RPMsg based shared
 memory ethernet driver

> +struct request_message {
> +	u32 type; /* Request Type */
> +	u32 id;	  /* Request ID */
> +} __packed;
> +
> +struct response_message {
> +	u32 type;	/* Response Type */
> +	u32 id;		/* Response ID */
> +} __packed;
> +
> +struct notify_message {
> +	u32 type;	/* Notify Type */
> +	u32 id;		/* Notify ID */
> +} __packed;

These are basically identical.

The packed should not be needed, since these structures are naturally
aligned. The compiler will do the right thing without the
__packet. And there is a general dislike for __packed. It is better to
layout your structures correctly so they are not needed.

> +struct message_header {
> +	u32 src_id;
> +	u32 msg_type; /* Do not use enum type, as enum size is compiler dependent */
> +} __packed;
> +
> +struct message {
> +	struct message_header msg_hdr;
> +	union {
> +		struct request_message req_msg;
> +		struct response_message resp_msg;
> +		struct notify_message notify_msg;
> +	};

Since they are identical, why bother with a union?  It could be argued
it allows future extensions, but i don't see any sort of protocol
version here so you can tell if extra fields have been added.

> +static int icve_rpmsg_cb(struct rpmsg_device *rpdev, void *data, int len,
> +			 void *priv, u32 src)
> +{
> +	struct icve_common *common = dev_get_drvdata(&rpdev->dev);
> +	struct message *msg = (struct message *)data;
> +	u32 msg_type = msg->msg_hdr.msg_type;
> +	u32 rpmsg_type;
> +
> +	switch (msg_type) {
> +	case ICVE_REQUEST_MSG:
> +		rpmsg_type = msg->req_msg.type;
> +		dev_dbg(common->dev, "Msg type = %d; RPMsg type = %d\n",
> +			msg_type, rpmsg_type);
> +		break;
> +	case ICVE_RESPONSE_MSG:
> +		rpmsg_type = msg->resp_msg.type;
> +		dev_dbg(common->dev, "Msg type = %d; RPMsg type = %d\n",
> +			msg_type, rpmsg_type);
> +		break;
> +	case ICVE_NOTIFY_MSG:
> +		rpmsg_type = msg->notify_msg.type;
> +		dev_dbg(common->dev, "Msg type = %d; RPMsg type = %d\n",
> +			msg_type, rpmsg_type);

This can be flattened to:

> +	case ICVE_REQUEST_MSG:
> +	case ICVE_RESPONSE_MSG:
> +	case ICVE_NOTIFY_MSG:
> +		rpmsg_type = msg->notify_msg.type;
> +		dev_dbg(common->dev, "Msg type = %d; RPMsg type = %d\n",
> +			msg_type, rpmsg_type);

which makes me wounder about the value of this. Yes, later patches are
going to flesh this out, but what value is there in printing the
numerical value of msg_type, when you could easily have the text
"Request", "Response", and "Notify". And why not include src_id and id
in this debug output? If you are going to add debug output, please
make it complete, otherwise it is often not useful.

> +		break;
> +	default:
> +		dev_err(common->dev, "Invalid msg type\n");
> +		break;

That is a potential way for the other end to DoS you. It also makes
changes to the protocol difficult, since you cannot add new messages
without DoS a machine using the old protocol. It would be better to
just increment a counter and keep going.

> +static void icve_rpmsg_remove(struct rpmsg_device *rpdev)
> +{
> +	dev_info(&rpdev->dev, "icve rpmsg client driver is removed\n");

Please don't spam the logs. dev_dbg(), or nothing at all.

	Andrew

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ