From: Jiri Pirko <jiri@resnulli.us>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: Edward Cree <ecree.xilinx@gmail.com>,
ecree@xilinx.com, netdev@vger.kernel.org,
linux-net-drivers@amd.com, davem@davemloft.net, kuba@kernel.org,
pabeni@redhat.com, edumazet@google.com, habetsm.xilinx@gmail.com,
marcelo.leitner@gmail.com
Subject: Re: [RFC PATCH net-next 1/3] netlink: add support for formatted extack messages
Date: Thu, 13 Oct 2022 14:59:00 +0200 [thread overview]
Message-ID: <Y0gLlKo8JGJKA7nf@nanopsycho> (raw)
In-Reply-To: <ff12253b6855305cc3fa518af30e8ac21019b684.camel@sipsolutions.net>
Fri, Oct 07, 2022 at 03:49:42PM CEST, johannes@sipsolutions.net wrote:
>On Fri, 2022-10-07 at 14:46 +0100, Edward Cree wrote:
>> On 07/10/2022 14:35, Johannes Berg wrote:
>> >
>> > > +#define NL_SET_ERR_MSG_FMT(extack, fmt, args...) do { \
>> > > + struct netlink_ext_ack *__extack = (extack); \
>> > > + \
>> > > + scnprintf(__extack->_msg_buf, NETLINK_MAX_FMTMSG_LEN, \
>> > > + (fmt), ##args); \
>> >
>> > Maybe that should print some kind of warning if the string was longer
>> > than the buffer? OTOH, I guess the user would notice anyway, and until
>> > you run the code nobody can possibly notice ... too bad then?
>> >
>> > Maybe we could at least _statically_ make sure that the *format* string
>> > (fmt) is shorter than say 60 chars or something to give some wiggle room
>> > for the print expansion?
>> >
>> > /* allow 20 chars for format expansion */
>> > BUILD_BUG_ON(strlen(fmt) > NETLINK_MAX_FMTMSG_LEN - 20);
>> >
>> > might even work? Just as a sanity check.
>>
>> Hmm, I don't think we want to prohibit the case of (say) a 78-char format
>> string with one %d that's always small-valued in practice.
>> In fact if you have lots of % in the format string the output could be
>> significantly *shorter* than fmt.
>> So while I do like the idea of a sanity check, I don't see how to do it
>> without imposing unnecessary limitations.
>>
>
>Yeah, I agree. We could runtime warn but that's also pretty useless.
I think that the macro caller need to take the buffer size into account
passing the formatted msg. So if the generated message would not fit
into the buffer, it's a caller bug. WARN_ON() is suitable for such
things, as it most probaly will hit the developer testing newly added
exack message.
>
>I guess we just have to be careful - but I know from experience that
>won't work ;-)
>
>(and some things like %pM or even %p*H can expand a lot anyway)
>
>Unless maybe we printed a warning together with the full string, so the
>user could recover it? WARN_ON() isn't useful though, the string should
>be enough to understand where it came from.
>
>Anyway just thinking out loud :)
>
>johannes
next prev parent reply other threads:[~2022-10-13 12:59 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-07 13:25 [RFC PATCH net-next 0/3] netlink: formatted extacks ecree
2022-10-07 13:25 ` [RFC PATCH net-next 1/3] netlink: add support for formatted extack messages ecree
2022-10-07 13:35 ` Johannes Berg
2022-10-07 13:46 ` Edward Cree
2022-10-07 13:49 ` Johannes Berg
2022-10-07 13:58 ` Edward Cree
2022-10-13 12:59 ` Jiri Pirko [this message]
2022-10-13 13:35 ` Edward Cree
2022-10-07 18:32 ` Jakub Kicinski
2022-10-13 12:55 ` Jiri Pirko
2022-10-17 12:00 ` Edward Cree
2022-10-17 18:44 ` Jakub Kicinski
2022-10-07 13:25 ` [RFC PATCH net-next 2/3] sfc: use formatted extacks instead of efx_tc_err() ecree
2022-10-07 13:25 ` [RFC PATCH net-next 3/3] sfc: remove 'log-tc-errors' ethtool private flag ecree
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=Y0gLlKo8JGJKA7nf@nanopsycho \
--to=jiri@resnulli.us \
--cc=davem@davemloft.net \
--cc=ecree.xilinx@gmail.com \
--cc=ecree@xilinx.com \
--cc=edumazet@google.com \
--cc=habetsm.xilinx@gmail.com \
--cc=johannes@sipsolutions.net \
--cc=kuba@kernel.org \
--cc=linux-net-drivers@amd.com \
--cc=marcelo.leitner@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox