All of lore.kernel.org
 help / color / mirror / Atom feed
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 17:58:34 +0900	[thread overview]
Message-ID: <20250206085834.17590-1-kuniyu@amazon.com> (raw)
In-Reply-To: <20250206081905.83029-1-buaajxlj@163.com>

From: Liang Jie <buaajxlj@163.com>
Date: Thu,  6 Feb 2025 16:19:05 +0800
> Hi Kuniyuki,
> 
> The logs from 'netdev/build_allmodconfig_warn' is as follows:
>   ../net/unix/af_unix.c: In function ‘unix_autobind’:
>   ../net/unix/af_unix.c:1222:52: warning: ‘snprintf’ output truncated before the last format character [-Wformat-truncation=]
>    1222 |         snprintf(addr->name->sun_path + 1, 5, "%05x", ordernum);
>         |                                                    ^
>   ../net/unix/af_unix.c:1222:9: note: ‘snprintf’ output 6 bytes into a destination of size 5
>    1222 |         snprintf(addr->name->sun_path + 1, 5, "%05x", ordernum);
>         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> snprintf() also append a trailing '\0' at the end of the sun_path.

I didn't say snprintf() would work rather we need a variant of it that
does not terminate string with \0.


> 
> Now, I think of three options. Which one do you think we should choose?
> 
> 1. Allocate an additional byte during the kzalloc phase.
> 	addr = kzalloc(sizeof(*addr) + offsetof(struct sockaddr_un, sun_path) +
> 		       UNIX_AUTOBIND_LEN + 1, GFP_KERNEL);
> 
> 2. Use temp buffer and memcpy() for handling.
> 
> 3. Keep the current code as it is.
> 
> Do you have any other suggestions?

I'd choose 3. as said in v1 thread.  We can't avoid hard-coding and
adjustment like +1 and -1 here.

  reply	other threads:[~2025-02-06  8:58 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
2025-02-06  8:19 ` Liang Jie
2025-02-06  8:58   ` Kuniyuki Iwashima [this message]
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=20250206085834.17590-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.