From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <buaajxlj@163.com>
Cc: <davem@davemloft.net>, <edumazet@google.com>, <horms@kernel.org>,
<kuba@kernel.org>, <kuniyu@amazon.com>, <liangjie@lixiang.com>,
<linux-kernel@vger.kernel.org>, <mhal@rbox.co>,
<netdev@vger.kernel.org>, <pabeni@redhat.com>
Subject: Re: [PATCH net-next v2] af_unix: Refine UNIX pathname sockets autobind identifier length
Date: Thu, 6 Feb 2025 15:22:17 +0900 [thread overview]
Message-ID: <20250206062217.94843-1-kuniyu@amazon.com> (raw)
In-Reply-To: <20250206054451.4070941-1-buaajxlj@163.com>
> Subject: [PATCH net-next v2] af_unix: Refine UNIX pathname sockets autobind identifier length
s/pathname/abstract/
In the v1 thread, I meant "filesystem-based sockets" is now called
pathname sockets. sockets whose name starts with \0 are abstract
sockets.
From: Liang Jie <buaajxlj@163.com>
Date: Thu, 6 Feb 2025 13:44:51 +0800
> Refines autobind identifier length for UNIX pathname sockets, addressing
same here, abstract sockets.
> issues of memory waste and code readability.
>
> The previous implementation in the unix_autobind function of UNIX pathname
> sockets used hardcoded values such as 16 and 6 for memory allocation and
nit: 6 isn't used for mem alloc.
> setting the length of the autobind identifier, which was not only
> inflexible but also led to reduced code clarity. Additionally, allocating
you need not mention inflexibility as the length are fixed and won't be
changed (it was changed once though)
> 16 bytes of memory for the autobind path was excessive, given that only 6
> bytes were ultimately used.
>
> To mitigate these issues, introduces the following changes:
> - A new macro UNIX_AUTOBIND_LEN is defined to clearly represent the total
> length of the autobind identifier, which improves code readability and
> maintainability. It is set to 6 bytes to accommodate the unique autobind
> process identifier.
> - Memory allocation for the autobind path is now precisely based on
> UNIX_AUTOBIND_LEN, thereby preventing memory waste.
> - To avoid buffer overflow and ensure that only the intended number of
> bytes are written, sprintf is replaced by snprintf with the proper
> buffer size set explicitly.
>
> The modifications result in a leaner memory footprint and elevated code
> quality, ensuring that the functional aspect of autobind behavior in UNIX
> pathname sockets remains intact.
s/pathname/abstract/
Overall, the commit message is a bit wordy. It can be simplified just like
unix_autobind() allocates 16 bytes but uses 6 bytes only.
Let's allocate 6 bytes only and use snprintf() to avoid
unwanted null-termination.
> @@ -1203,12 +1205,12 @@ static int unix_autobind(struct sock *sk)
> goto out;
>
> err = -ENOMEM;
> - addr = kzalloc(sizeof(*addr) +
> - offsetof(struct sockaddr_un, sun_path) + 16, GFP_KERNEL);
> + addr = kzalloc(sizeof(*addr) + offsetof(struct sockaddr_un, sun_path) +
> + UNIX_AUTOBIND_LEN, GFP_KERNEL);
nit: indent is wrong here.
If you are using emacs, add the following to your config:
(setq-default c-default-style "linux")
next prev parent reply other threads:[~2025-02-06 6:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-06 5:44 [PATCH net-next v2] af_unix: Refine UNIX pathname sockets autobind identifier length Liang Jie
2025-02-06 6:22 ` Kuniyuki Iwashima [this message]
2025-02-06 8:19 ` Liang Jie
2025-02-06 8:58 ` Kuniyuki Iwashima
2025-02-06 9:44 ` Liang Jie
2025-02-06 10:09 ` Eric Dumazet
2025-02-08 16:26 ` kernel test robot
2025-02-08 16:26 ` kernel test robot
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=20250206062217.94843-1-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=buaajxlj@163.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=liangjie@lixiang.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhal@rbox.co \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.