Netdev List
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: cugyly@163.com
Cc: netdev@vger.kernel.org, Linyu.Yuan@alcatel-sbell.com.cn
Subject: Re: [PATCH] scm: remove use CMSG{_COMPAT}_ALIGN(sizeof(struct {compat_}cmsghdr))
Date: Wed, 04 Jan 2017 13:24:52 -0500 (EST)	[thread overview]
Message-ID: <20170104.132452.646592152519338774.davem@davemloft.net> (raw)
In-Reply-To: <1483447337-4976-1-git-send-email-cugyly@163.com>

From: yuan linyu <cugyly@163.com>
Date: Tue,  3 Jan 2017 20:42:17 +0800

> From: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
> 
> sizeof(struct cmsghdr) and sizeof(struct compat_cmsghdr) already aligned.
> remove use CMSG_ALIGN(sizeof(struct cmsghdr)) and
> CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) keep code consistent.
> 
> Signed-off-by: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>

Applied, and I added the following commit which will make sure our
analysis is accurate.

====================
[PATCH] net: Assert at build time the assumptions we make about the CMSG header.

It must always be the case that CMSG_ALIGN(sizeof(hdr)) == sizeof(hdr).

Otherwise there are missing adjustments in the various calculations
that parse and build these things.

Signed-off-by: David S. Miller <davem@davemloft.net>
---
 net/compat.c | 3 +++
 net/socket.c | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/net/compat.c b/net/compat.c
index 4e27dd1..ba3ac72 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -130,6 +130,9 @@ int cmsghdr_from_user_compat_to_kern(struct msghdr *kmsg, struct sock *sk,
 	__kernel_size_t kcmlen, tmp;
 	int err = -EFAULT;
 
+	BUILD_BUG_ON(sizeof(struct compat_cmsghdr) !=
+		     CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)));
+
 	kcmlen = 0;
 	kcmsg_base = kcmsg = (struct cmsghdr *)stackbuf;
 	ucmsg = CMSG_COMPAT_FIRSTHDR(kmsg);
diff --git a/net/socket.c b/net/socket.c
index 8487bf1..5f3b5a2 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1948,6 +1948,8 @@ static int ___sys_sendmsg(struct socket *sock, struct user_msghdr __user *msg,
 		ctl_buf = msg_sys->msg_control;
 		ctl_len = msg_sys->msg_controllen;
 	} else if (ctl_len) {
+		BUILD_BUG_ON(sizeof(struct cmsghdr) !=
+			     CMSG_ALIGN(sizeof(struct cmsghdr)));
 		if (ctl_len > sizeof(ctl)) {
 			ctl_buf = sock_kmalloc(sock->sk, ctl_len, GFP_KERNEL);
 			if (ctl_buf == NULL)
-- 
2.4.11

  reply	other threads:[~2017-01-04 18:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-03 12:42 [PATCH] scm: remove use CMSG{_COMPAT}_ALIGN(sizeof(struct {compat_}cmsghdr)) yuan linyu
2017-01-04 18:24 ` David Miller [this message]
2017-01-04 23:45   ` YUAN Linyu

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=20170104.132452.646592152519338774.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=Linyu.Yuan@alcatel-sbell.com.cn \
    --cc=cugyly@163.com \
    --cc=netdev@vger.kernel.org \
    /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