From: Dan Carpenter <dan.carpenter@linaro.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-trace-kernel@vger.kernel.org
Subject: [bug report] ring-buffer: Validate boot range memory events
Date: Thu, 20 Jun 2024 11:50:43 +0300 [thread overview]
Message-ID: <e1f7e29a-0350-40c6-a28d-e9012f9a6428@moroto.mountain> (raw)
Hello Steven Rostedt (Google),
Commit 5f3b6e839f3c ("ring-buffer: Validate boot range memory
events") from Jun 12, 2024 (linux-next), leads to the following
Smatch static checker warning:
kernel/trace/ring_buffer.c:1824 rb_meta_validate_events()
error: uninitialized symbol 'head_page'.
kernel/trace/ring_buffer.c
1751 static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer)
1752 {
1753 struct ring_buffer_meta *meta = cpu_buffer->ring_meta;
1754 struct buffer_page *head_page;
1755 unsigned long entry_bytes = 0;
1756 unsigned long entries = 0;
1757 int ret;
1758 int i;
1759
1760 if (!meta || !meta->head_buffer)
1761 return;
1762
1763 /* Do the reader page first */
1764 ret = rb_validate_buffer(cpu_buffer->reader_page->page, cpu_buffer->cpu);
1765 if (ret < 0) {
1766 pr_info("Ring buffer reader page is invalid\n");
1767 goto invalid;
head_page is uninitialized
1768 }
1769 entries += ret;
1770 entry_bytes += local_read(&cpu_buffer->reader_page->page->commit);
1771 local_set(&cpu_buffer->reader_page->entries, ret);
1772
1773 head_page = cpu_buffer->head_page;
1774
1775 /* If both the head and commit are on the reader_page then we are done. */
1776 if (head_page == cpu_buffer->reader_page &&
1777 head_page == cpu_buffer->commit_page)
1778 goto done;
1779
1780 /* Iterate until finding the commit page */
1781 for (i = 0; i < meta->nr_subbufs + 1; i++, rb_inc_page(&head_page)) {
1782
1783 /* Reader page has already been done */
1784 if (head_page == cpu_buffer->reader_page)
1785 continue;
1786
1787 ret = rb_validate_buffer(head_page->page, cpu_buffer->cpu);
1788 if (ret < 0) {
1789 pr_info("Ring buffer meta [%d] invalid buffer page\n",
1790 cpu_buffer->cpu);
1791 goto invalid;
1792 }
1793 entries += ret;
1794 entry_bytes += local_read(&head_page->page->commit);
1795 local_set(&cpu_buffer->head_page->entries, ret);
1796
1797 if (head_page == cpu_buffer->commit_page)
1798 break;
1799 }
1800
1801 if (head_page != cpu_buffer->commit_page) {
1802 pr_info("Ring buffer meta [%d] commit page not found\n",
1803 cpu_buffer->cpu);
1804 goto invalid;
1805 }
1806 done:
1807 local_set(&cpu_buffer->entries, entries);
1808 local_set(&cpu_buffer->entries_bytes, entry_bytes);
1809
1810 pr_info("Ring buffer meta [%d] is from previous boot!\n", cpu_buffer->cpu);
1811 return;
1812
1813 invalid:
1814 /* The content of the buffers are invalid, reset the meta data */
1815 meta->head_buffer = 0;
1816 meta->commit_buffer = 0;
1817
1818 /* Reset the reader page */
1819 local_set(&cpu_buffer->reader_page->entries, 0);
1820 local_set(&cpu_buffer->reader_page->page->commit, 0);
1821
1822 /* Reset all the subbuffers */
1823 for (i = 0; i < meta->nr_subbufs - 1; i++, rb_inc_page(&head_page)) {
--> 1824 local_set(&head_page->entries, 0);
^^^^^^^^^
Uninitialized
1825 local_set(&head_page->page->commit, 0);
1826 }
1827 }
regards,
dan carpenter
reply other threads:[~2024-06-20 8:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=e1f7e29a-0350-40c6-a28d-e9012f9a6428@moroto.mountain \
--to=dan.carpenter@linaro.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=rostedt@goodmis.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