* [PATCH v2] writeback: fix -Wstringop-truncation warnings
@ 2019-07-25 14:38 Qian Cai
2019-07-25 15:04 ` David Laight
0 siblings, 1 reply; 4+ messages in thread
From: Qian Cai @ 2019-07-25 14:38 UTC (permalink / raw)
To: akpm
Cc: tobin, rostedt, mingo, tj, dchinner, fengguang.wu, jack, axboe,
linux-kernel, Qian Cai
There are many of those warnings.
In file included from ./arch/powerpc/include/asm/paca.h:15,
from ./arch/powerpc/include/asm/current.h:13,
from ./include/linux/thread_info.h:21,
from ./include/asm-generic/preempt.h:5,
from ./arch/powerpc/include/generated/asm/preempt.h:1,
from ./include/linux/preempt.h:78,
from ./include/linux/spinlock.h:51,
from fs/fs-writeback.c:19:
In function 'strncpy',
inlined from 'perf_trace_writeback_page_template' at
./include/trace/events/writeback.h:56:1:
./include/linux/string.h:260:9: warning: '__builtin_strncpy' specified
bound 32 equals destination size [-Wstringop-truncation]
return __builtin_strncpy(p, q, size);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fix it by using the new strscpy_pad() which was introduced in the
commit 458a3bf82df4 ("lib/string: Add strscpy_pad() function") and will
always be NUL-terminated instead of strncpy(). Also, changes strlcpy()
to use strscpy_pad() in this file for consistency.
Fixes: 455b2864686d ("writeback: Initial tracing support")
Fixes: 028c2dd184c0 ("writeback: Add tracing to balance_dirty_pages")
Fixes: e84d0a4f8e39 ("writeback: trace event writeback_queue_io")
Fixes: b48c104d2211 ("writeback: trace event bdi_dirty_ratelimit")
Fixes: cc1676d917f3 ("writeback: Move requeueing when I_SYNC set to writeback_sb_inodes()")
Fixes: 9fb0a7da0c52 ("writeback: add more tracepoints")
Signed-off-by: Qian Cai <cai@lca.pw>
---
v2: Use strscpy_pad() to address the possible data leaking concern from Steve [1].
Replace strlcpy() as well for consistency.
[1] https://lore.kernel.org/lkml/20190716170339.1c44719d@gandalf.local.home/
include/trace/events/writeback.h | 39 +++++++++++++++++++++------------------
1 file changed, 21 insertions(+), 18 deletions(-)
diff --git a/include/trace/events/writeback.h b/include/trace/events/writeback.h
index aa7f3aeac740..41092d63a8de 100644
--- a/include/trace/events/writeback.h
+++ b/include/trace/events/writeback.h
@@ -66,8 +66,10 @@
),
TP_fast_assign(
- strncpy(__entry->name,
- mapping ? dev_name(inode_to_bdi(mapping->host)->dev) : "(unknown)", 32);
+ strscpy_pad(__entry->name,
+ mapping ?
+ dev_name(inode_to_bdi(mapping->host)->dev) :
+ "(unknown)", 32);
__entry->ino = mapping ? mapping->host->i_ino : 0;
__entry->index = page->index;
),
@@ -110,8 +112,8 @@
struct backing_dev_info *bdi = inode_to_bdi(inode);
/* may be called for files on pseudo FSes w/ unregistered bdi */
- strncpy(__entry->name,
- bdi->dev ? dev_name(bdi->dev) : "(unknown)", 32);
+ strscpy_pad(__entry->name,
+ bdi->dev ? dev_name(bdi->dev) : "(unknown)", 32);
__entry->ino = inode->i_ino;
__entry->state = inode->i_state;
__entry->flags = flags;
@@ -190,8 +192,8 @@ static inline unsigned int __trace_wbc_assign_cgroup(struct writeback_control *w
),
TP_fast_assign(
- strncpy(__entry->name,
- dev_name(inode_to_bdi(inode)->dev), 32);
+ strscpy_pad(__entry->name,
+ dev_name(inode_to_bdi(inode)->dev), 32);
__entry->ino = inode->i_ino;
__entry->sync_mode = wbc->sync_mode;
__entry->cgroup_ino = __trace_wbc_assign_cgroup(wbc);
@@ -234,8 +236,9 @@ static inline unsigned int __trace_wbc_assign_cgroup(struct writeback_control *w
__field(unsigned int, cgroup_ino)
),
TP_fast_assign(
- strncpy(__entry->name,
- wb->bdi->dev ? dev_name(wb->bdi->dev) : "(unknown)", 32);
+ strscpy_pad(__entry->name,
+ wb->bdi->dev ? dev_name(wb->bdi->dev) :
+ "(unknown)", 32);
__entry->nr_pages = work->nr_pages;
__entry->sb_dev = work->sb ? work->sb->s_dev : 0;
__entry->sync_mode = work->sync_mode;
@@ -288,7 +291,7 @@ static inline unsigned int __trace_wbc_assign_cgroup(struct writeback_control *w
__field(unsigned int, cgroup_ino)
),
TP_fast_assign(
- strncpy(__entry->name, dev_name(wb->bdi->dev), 32);
+ strscpy_pad(__entry->name, dev_name(wb->bdi->dev), 32);
__entry->cgroup_ino = __trace_wb_assign_cgroup(wb);
),
TP_printk("bdi %s: cgroup_ino=%u",
@@ -310,7 +313,7 @@ static inline unsigned int __trace_wbc_assign_cgroup(struct writeback_control *w
__array(char, name, 32)
),
TP_fast_assign(
- strncpy(__entry->name, dev_name(bdi->dev), 32);
+ strscpy_pad(__entry->name, dev_name(bdi->dev), 32);
),
TP_printk("bdi %s",
__entry->name
@@ -335,7 +338,7 @@ static inline unsigned int __trace_wbc_assign_cgroup(struct writeback_control *w
),
TP_fast_assign(
- strncpy(__entry->name, dev_name(bdi->dev), 32);
+ strscpy_pad(__entry->name, dev_name(bdi->dev), 32);
__entry->nr_to_write = wbc->nr_to_write;
__entry->pages_skipped = wbc->pages_skipped;
__entry->sync_mode = wbc->sync_mode;
@@ -386,7 +389,7 @@ static inline unsigned int __trace_wbc_assign_cgroup(struct writeback_control *w
),
TP_fast_assign(
unsigned long *older_than_this = work->older_than_this;
- strncpy(__entry->name, dev_name(wb->bdi->dev), 32);
+ strscpy_pad(__entry->name, dev_name(wb->bdi->dev), 32);
__entry->older = older_than_this ? *older_than_this : 0;
__entry->age = older_than_this ?
(jiffies - *older_than_this) * 1000 / HZ : -1;
@@ -472,7 +475,7 @@ static inline unsigned int __trace_wbc_assign_cgroup(struct writeback_control *w
),
TP_fast_assign(
- strlcpy(__entry->bdi, dev_name(wb->bdi->dev), 32);
+ strscpy_pad(__entry->bdi, dev_name(wb->bdi->dev), 32);
__entry->write_bw = KBps(wb->write_bandwidth);
__entry->avg_write_bw = KBps(wb->avg_write_bandwidth);
__entry->dirty_rate = KBps(dirty_rate);
@@ -537,7 +540,7 @@ static inline unsigned int __trace_wbc_assign_cgroup(struct writeback_control *w
TP_fast_assign(
unsigned long freerun = (thresh + bg_thresh) / 2;
- strlcpy(__entry->bdi, dev_name(wb->bdi->dev), 32);
+ strscpy_pad(__entry->bdi, dev_name(wb->bdi->dev), 32);
__entry->limit = global_wb_domain.dirty_limit;
__entry->setpoint = (global_wb_domain.dirty_limit +
@@ -597,8 +600,8 @@ static inline unsigned int __trace_wbc_assign_cgroup(struct writeback_control *w
),
TP_fast_assign(
- strncpy(__entry->name,
- dev_name(inode_to_bdi(inode)->dev), 32);
+ strscpy_pad(__entry->name,
+ dev_name(inode_to_bdi(inode)->dev), 32);
__entry->ino = inode->i_ino;
__entry->state = inode->i_state;
__entry->dirtied_when = inode->dirtied_when;
@@ -671,8 +674,8 @@ static inline unsigned int __trace_wbc_assign_cgroup(struct writeback_control *w
),
TP_fast_assign(
- strncpy(__entry->name,
- dev_name(inode_to_bdi(inode)->dev), 32);
+ strscpy_pad(__entry->name,
+ dev_name(inode_to_bdi(inode)->dev), 32);
__entry->ino = inode->i_ino;
__entry->state = inode->i_state;
__entry->dirtied_when = inode->dirtied_when;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH v2] writeback: fix -Wstringop-truncation warnings
2019-07-25 14:38 [PATCH v2] writeback: fix -Wstringop-truncation warnings Qian Cai
@ 2019-07-25 15:04 ` David Laight
2019-07-25 15:50 ` Qian Cai
0 siblings, 1 reply; 4+ messages in thread
From: David Laight @ 2019-07-25 15:04 UTC (permalink / raw)
To: 'Qian Cai', akpm
Cc: tobin, rostedt, mingo, tj, dchinner, fengguang.wu, jack, axboe,
linux-kernel
From: Qian Cai
> Sent: 25 July 2019 15:39
>
> There are many of those warnings.
>
> In file included from ./arch/powerpc/include/asm/paca.h:15,
> from ./arch/powerpc/include/asm/current.h:13,
> from ./include/linux/thread_info.h:21,
> from ./include/asm-generic/preempt.h:5,
> from ./arch/powerpc/include/generated/asm/preempt.h:1,
> from ./include/linux/preempt.h:78,
> from ./include/linux/spinlock.h:51,
> from fs/fs-writeback.c:19:
> In function 'strncpy',
> inlined from 'perf_trace_writeback_page_template' at
> ./include/trace/events/writeback.h:56:1:
> ./include/linux/string.h:260:9: warning: '__builtin_strncpy' specified
> bound 32 equals destination size [-Wstringop-truncation]
> return __builtin_strncpy(p, q, size);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Fix it by using the new strscpy_pad() which was introduced in the
> commit 458a3bf82df4 ("lib/string: Add strscpy_pad() function") and will
> always be NUL-terminated instead of strncpy(). Also, changes strlcpy()
> to use strscpy_pad() in this file for consistency.
>
> Fixes: 455b2864686d ("writeback: Initial tracing support")
> Fixes: 028c2dd184c0 ("writeback: Add tracing to balance_dirty_pages")
> Fixes: e84d0a4f8e39 ("writeback: trace event writeback_queue_io")
> Fixes: b48c104d2211 ("writeback: trace event bdi_dirty_ratelimit")
> Fixes: cc1676d917f3 ("writeback: Move requeueing when I_SYNC set to writeback_sb_inodes()")
> Fixes: 9fb0a7da0c52 ("writeback: add more tracepoints")
> Signed-off-by: Qian Cai <cai@lca.pw>
> ---
>
> v2: Use strscpy_pad() to address the possible data leaking concern from Steve [1].
> Replace strlcpy() as well for consistency.
>
> [1] https://lore.kernel.org/lkml/20190716170339.1c44719d@gandalf.local.home/
>
> include/trace/events/writeback.h | 39 +++++++++++++++++++++------------------
> 1 file changed, 21 insertions(+), 18 deletions(-)
>
> diff --git a/include/trace/events/writeback.h b/include/trace/events/writeback.h
> index aa7f3aeac740..41092d63a8de 100644
> --- a/include/trace/events/writeback.h
> +++ b/include/trace/events/writeback.h
> @@ -66,8 +66,10 @@
> ),
>
> TP_fast_assign(
> - strncpy(__entry->name,
> - mapping ? dev_name(inode_to_bdi(mapping->host)->dev) : "(unknown)", 32);
> + strscpy_pad(__entry->name,
> + mapping ?
> + dev_name(inode_to_bdi(mapping->host)->dev) :
> + "(unknown)", 32);
Shouldn't the 32 be 'sizeof (something)' ??
Oh, and a horrid line break.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] writeback: fix -Wstringop-truncation warnings
2019-07-25 15:04 ` David Laight
@ 2019-07-25 15:50 ` Qian Cai
2019-07-25 16:41 ` Joe Perches
0 siblings, 1 reply; 4+ messages in thread
From: Qian Cai @ 2019-07-25 15:50 UTC (permalink / raw)
To: David Laight, akpm
Cc: tobin, rostedt, mingo, tj, dchinner, fengguang.wu, jack, axboe,
linux-kernel
On Thu, 2019-07-25 at 15:04 +0000, David Laight wrote:
> From: Qian Cai
> > Sent: 25 July 2019 15:39
> >
> > There are many of those warnings.
> >
> > In file included from ./arch/powerpc/include/asm/paca.h:15,
> > from ./arch/powerpc/include/asm/current.h:13,
> > from ./include/linux/thread_info.h:21,
> > from ./include/asm-generic/preempt.h:5,
> > from ./arch/powerpc/include/generated/asm/preempt.h:1,
> > from ./include/linux/preempt.h:78,
> > from ./include/linux/spinlock.h:51,
> > from fs/fs-writeback.c:19:
> > In function 'strncpy',
> > inlined from 'perf_trace_writeback_page_template' at
> > ./include/trace/events/writeback.h:56:1:
> > ./include/linux/string.h:260:9: warning: '__builtin_strncpy' specified
> > bound 32 equals destination size [-Wstringop-truncation]
> > return __builtin_strncpy(p, q, size);
> > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >
> > Fix it by using the new strscpy_pad() which was introduced in the
> > commit 458a3bf82df4 ("lib/string: Add strscpy_pad() function") and will
> > always be NUL-terminated instead of strncpy(). Also, changes strlcpy()
> > to use strscpy_pad() in this file for consistency.
> >
> > Fixes: 455b2864686d ("writeback: Initial tracing support")
> > Fixes: 028c2dd184c0 ("writeback: Add tracing to balance_dirty_pages")
> > Fixes: e84d0a4f8e39 ("writeback: trace event writeback_queue_io")
> > Fixes: b48c104d2211 ("writeback: trace event bdi_dirty_ratelimit")
> > Fixes: cc1676d917f3 ("writeback: Move requeueing when I_SYNC set to
> > writeback_sb_inodes()")
> > Fixes: 9fb0a7da0c52 ("writeback: add more tracepoints")
> > Signed-off-by: Qian Cai <cai@lca.pw>
> > ---
> >
> > v2: Use strscpy_pad() to address the possible data leaking concern from
> > Steve [1].
> > Replace strlcpy() as well for consistency.
> >
> > [1] https://lore.kernel.org/lkml/20190716170339.1c44719d@gandalf.local.home/
> >
> > include/trace/events/writeback.h | 39 +++++++++++++++++++++--------------
> > ----
> > 1 file changed, 21 insertions(+), 18 deletions(-)
> >
> > diff --git a/include/trace/events/writeback.h
> > b/include/trace/events/writeback.h
> > index aa7f3aeac740..41092d63a8de 100644
> > --- a/include/trace/events/writeback.h
> > +++ b/include/trace/events/writeback.h
> > @@ -66,8 +66,10 @@
> > ),
> >
> > TP_fast_assign(
> > - strncpy(__entry->name,
> > - mapping ? dev_name(inode_to_bdi(mapping->host)-
> > >dev) : "(unknown)", 32);
> > + strscpy_pad(__entry->name,
> > + mapping ?
> > + dev_name(inode_to_bdi(mapping->host)->dev) :
> > + "(unknown)", 32);
>
> Shouldn't the 32 be 'sizeof (something)' ??
Maybe could do a sizeof(__entry->name) as it is defined as,
TP_STRUCT__entry (
__array(char, name, 32)
__field(unsigned long, ino)
__field(pgoff_t, index)
But, that might be a follow-up patch and does not seem belong here.
>
> Oh, and a horrid line break.
That line is too long needs to break up. Open up to suggestions though.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] writeback: fix -Wstringop-truncation warnings
2019-07-25 15:50 ` Qian Cai
@ 2019-07-25 16:41 ` Joe Perches
0 siblings, 0 replies; 4+ messages in thread
From: Joe Perches @ 2019-07-25 16:41 UTC (permalink / raw)
To: Qian Cai, David Laight, akpm
Cc: tobin, rostedt, mingo, tj, dchinner, fengguang.wu, jack, axboe,
linux-kernel
On Thu, 2019-07-25 at 11:50 -0400, Qian Cai wrote:
> > > diff --git a/include/trace/events/writeback.h b/include/trace/events/writeback.h
[]
> > > @@ -66,8 +66,10 @@
> > > ),
> > >
> > > TP_fast_assign(
> > > - strncpy(__entry->name,
> > > - mapping ? dev_name(inode_to_bdi(mapping->host)-
> > > > dev) : "(unknown)", 32);
> > >
> > > + strscpy_pad(__entry->name,
> > > + mapping ?
> > > + dev_name(inode_to_bdi(mapping->host)->dev) :
> > > + "(unknown)", 32);
> >
> > Shouldn't the 32 be 'sizeof (something)' ??
>
> Maybe could do a sizeof(__entry->name) as it is defined as,
>
> TP_STRUCT__entry (
> __array(char, name, 32)
> __field(unsigned long, ino)
> __field(pgoff_t, index)
>
> But, that might be a follow-up patch and does not seem belong here.
stracpy_pad would work one day.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-07-25 16:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-25 14:38 [PATCH v2] writeback: fix -Wstringop-truncation warnings Qian Cai
2019-07-25 15:04 ` David Laight
2019-07-25 15:50 ` Qian Cai
2019-07-25 16:41 ` Joe Perches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).