LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* re: security/loadpin: Allow to exclude specific file types
@ 2019-05-31 10:46 Colin Ian King
2019-05-31 14:44 ` Kees Cook
0 siblings, 1 reply; 6+ messages in thread
From: Colin Ian King @ 2019-05-31 10:46 UTC (permalink / raw)
To: Ke Wu, James Morris, Kees Cook, Serge E. Hallyn, linux-security-module
Cc: linux-kernel
Hi,
Static analysis with Coverity on linux-next has found a potential issue
with the following commit:
commit 1633a4f04cc171fc638deb5c95af96032d3c591b
Author: Ke Wu <mikewu@google.com>
Date: Thu May 30 12:22:08 2019 -0700
security/loadpin: Allow to exclude specific file types
209 for (j = 0; j < ARRAY_SIZE(kernel_read_file_str); j++) {
210 if (strcmp(cur, kernel_read_file_str[j]) == 0) {
211 pr_info("excluding: %s\n",
212 kernel_read_file_str[j]);
CID 81977 (#1 of 1): Out-of-bounds write
overrun-local: Overrunning array ignore_read_file_id of 8 4-byte
elements at element index 8 (byte offset 35) using index j (which
evaluates to 8).
213 ignore_read_file_id[j] = 1;
According to Coverity ignore_read_file_id is an array of 8 integers.
However, ARRAY_SIZE(kernel_read_file_str) is 9, so we have an out of
bounds write on ignore_read_file[j] when j is 8.
Colin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: security/loadpin: Allow to exclude specific file types
2019-05-31 10:46 security/loadpin: Allow to exclude specific file types Colin Ian King
@ 2019-05-31 14:44 ` Kees Cook
2019-05-31 14:49 ` Colin Ian King
0 siblings, 1 reply; 6+ messages in thread
From: Kees Cook @ 2019-05-31 14:44 UTC (permalink / raw)
To: Colin Ian King
Cc: Ke Wu, James Morris, Serge E. Hallyn, linux-security-module,
linux-kernel
On Fri, May 31, 2019 at 11:46:29AM +0100, Colin Ian King wrote:
> Hi,
>
> Static analysis with Coverity on linux-next has found a potential issue
> with the following commit:
>
> commit 1633a4f04cc171fc638deb5c95af96032d3c591b
> Author: Ke Wu <mikewu@google.com>
> Date: Thu May 30 12:22:08 2019 -0700
>
> security/loadpin: Allow to exclude specific file types
>
>
> 209 for (j = 0; j < ARRAY_SIZE(kernel_read_file_str); j++) {
> 210 if (strcmp(cur, kernel_read_file_str[j]) == 0) {
> 211 pr_info("excluding: %s\n",
> 212 kernel_read_file_str[j]);
>
> CID 81977 (#1 of 1): Out-of-bounds write
> overrun-local: Overrunning array ignore_read_file_id of 8 4-byte
> elements at element index 8 (byte offset 35) using index j (which
> evaluates to 8).
>
> 213 ignore_read_file_id[j] = 1;
>
> According to Coverity ignore_read_file_id is an array of 8 integers.
> However, ARRAY_SIZE(kernel_read_file_str) is 9, so we have an out of
> bounds write on ignore_read_file[j] when j is 8.
What am I missing? This doesn't fail the build:
+ BUILD_BUG_ON(ARRAY_SIZE(exclude_read_files) !=
+ ARRAY_SIZE(ignore_read_file_id));
They have the same number of elements.
--
Kees Cook
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: security/loadpin: Allow to exclude specific file types
2019-05-31 14:44 ` Kees Cook
@ 2019-05-31 14:49 ` Colin Ian King
2019-05-31 18:03 ` Ke Wu
0 siblings, 1 reply; 6+ messages in thread
From: Colin Ian King @ 2019-05-31 14:49 UTC (permalink / raw)
To: Kees Cook
Cc: Ke Wu, James Morris, Serge E. Hallyn, linux-security-module,
linux-kernel
On 31/05/2019 15:44, Kees Cook wrote:
> On Fri, May 31, 2019 at 11:46:29AM +0100, Colin Ian King wrote:
>> Hi,
>>
>> Static analysis with Coverity on linux-next has found a potential issue
>> with the following commit:
>>
>> commit 1633a4f04cc171fc638deb5c95af96032d3c591b
>> Author: Ke Wu <mikewu@google.com>
>> Date: Thu May 30 12:22:08 2019 -0700
>>
>> security/loadpin: Allow to exclude specific file types
>>
>>
>> 209 for (j = 0; j < ARRAY_SIZE(kernel_read_file_str); j++) {
>> 210 if (strcmp(cur, kernel_read_file_str[j]) == 0) {
>> 211 pr_info("excluding: %s\n",
>> 212 kernel_read_file_str[j]);
>>
>> CID 81977 (#1 of 1): Out-of-bounds write
>> overrun-local: Overrunning array ignore_read_file_id of 8 4-byte
>> elements at element index 8 (byte offset 35) using index j (which
>> evaluates to 8).
>>
>> 213 ignore_read_file_id[j] = 1;
>>
>> According to Coverity ignore_read_file_id is an array of 8 integers.
>> However, ARRAY_SIZE(kernel_read_file_str) is 9, so we have an out of
>> bounds write on ignore_read_file[j] when j is 8.
>
> What am I missing? This doesn't fail the build:
>
> + BUILD_BUG_ON(ARRAY_SIZE(exclude_read_files) !=
> + ARRAY_SIZE(ignore_read_file_id));
>
> They have the same number of elements.
>
Yep, that's very true. I'll discuss this with Coverity as this seems
like a weird false positive.
Apologies for the noise.
Colin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: security/loadpin: Allow to exclude specific file types
2019-05-31 14:49 ` Colin Ian King
@ 2019-05-31 18:03 ` Ke Wu
2019-05-31 20:33 ` Kees Cook
0 siblings, 1 reply; 6+ messages in thread
From: Ke Wu @ 2019-05-31 18:03 UTC (permalink / raw)
To: Colin Ian King
Cc: Kees Cook, James Morris, Serge E. Hallyn, linux-security-module,
linux-kernel
I think Coverity is correct. Note that it's the size of
kernel_read_file_str (rather than exclude_read_files) doesn't equal to
ignore_read_file_id.
This is because READING_MAX_ID is also an element in
kernel_read_file_str, which makes the size of kernel_read_file_str to
be READING_MAX_ID+1. I will send a new patch to fix the issue. Thanks
for the analysis!
On Fri, May 31, 2019 at 7:49 AM Colin Ian King <colin.king@canonical.com> wrote:
>
> On 31/05/2019 15:44, Kees Cook wrote:
> > On Fri, May 31, 2019 at 11:46:29AM +0100, Colin Ian King wrote:
> >> Hi,
> >>
> >> Static analysis with Coverity on linux-next has found a potential issue
> >> with the following commit:
> >>
> >> commit 1633a4f04cc171fc638deb5c95af96032d3c591b
> >> Author: Ke Wu <mikewu@google.com>
> >> Date: Thu May 30 12:22:08 2019 -0700
> >>
> >> security/loadpin: Allow to exclude specific file types
> >>
> >>
> >> 209 for (j = 0; j < ARRAY_SIZE(kernel_read_file_str); j++) {
> >> 210 if (strcmp(cur, kernel_read_file_str[j]) == 0) {
> >> 211 pr_info("excluding: %s\n",
> >> 212 kernel_read_file_str[j]);
> >>
> >> CID 81977 (#1 of 1): Out-of-bounds write
> >> overrun-local: Overrunning array ignore_read_file_id of 8 4-byte
> >> elements at element index 8 (byte offset 35) using index j (which
> >> evaluates to 8).
> >>
> >> 213 ignore_read_file_id[j] = 1;
> >>
> >> According to Coverity ignore_read_file_id is an array of 8 integers.
> >> However, ARRAY_SIZE(kernel_read_file_str) is 9, so we have an out of
> >> bounds write on ignore_read_file[j] when j is 8.
> >
> > What am I missing? This doesn't fail the build:
> >
> > + BUILD_BUG_ON(ARRAY_SIZE(exclude_read_files) !=
> > + ARRAY_SIZE(ignore_read_file_id));
> >
> > They have the same number of elements.
> >
>
> Yep, that's very true. I'll discuss this with Coverity as this seems
> like a weird false positive.
>
> Apologies for the noise.
>
> Colin
--
Ke Wu | Software Engineer | mikewu@google.com | Google Inc.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: security/loadpin: Allow to exclude specific file types
2019-05-31 18:03 ` Ke Wu
@ 2019-05-31 20:33 ` Kees Cook
2019-06-04 17:01 ` Ke Wu
0 siblings, 1 reply; 6+ messages in thread
From: Kees Cook @ 2019-05-31 20:33 UTC (permalink / raw)
To: Ke Wu
Cc: Colin Ian King, James Morris, Serge E. Hallyn,
linux-security-module, linux-kernel
On Fri, May 31, 2019 at 11:03:17AM -0700, Ke Wu wrote:
> I think Coverity is correct. Note that it's the size of
> kernel_read_file_str (rather than exclude_read_files) doesn't equal to
> ignore_read_file_id.
>
> This is because READING_MAX_ID is also an element in
> kernel_read_file_str, which makes the size of kernel_read_file_str to
> be READING_MAX_ID+1. I will send a new patch to fix the issue. Thanks
> for the analysis!
Ah! Yes, I see now. I was looking at the wrong things. It should be
possible to just do:
> > >> 209 for (j = 0; j < ARRAY_SIZE(kernel_read_file_str); j++) {
for (j = 0; j < ARRAY_SIZE(ignore_read_file_id); j++)
and add a
BUILD_BUG_ON(ARRAY_SIZE(kernel_read_file_str) < ARRAY_SIZE(ignore_read_file_id))
for future robustness checking.
Thanks for looking at this more closely!
-Kees
> > >> 210 if (strcmp(cur, kernel_read_file_str[j]) == 0) {
> > >> 211 pr_info("excluding: %s\n",
> > >> 212 kernel_read_file_str[j]);
> > >>
> > >> CID 81977 (#1 of 1): Out-of-bounds write
> > >> overrun-local: Overrunning array ignore_read_file_id of 8 4-byte
> > >> elements at element index 8 (byte offset 35) using index j (which
> > >> evaluates to 8).
> > >>
> > >> 213 ignore_read_file_id[j] = 1;
> > >>
> > >> According to Coverity ignore_read_file_id is an array of 8 integers.
> > >> However, ARRAY_SIZE(kernel_read_file_str) is 9, so we have an out of
> > >> bounds write on ignore_read_file[j] when j is 8.
> > >
> > > What am I missing? This doesn't fail the build:
> > >
> > > + BUILD_BUG_ON(ARRAY_SIZE(exclude_read_files) !=
> > > + ARRAY_SIZE(ignore_read_file_id));
> > >
> > > They have the same number of elements.
> > >
> >
> > Yep, that's very true. I'll discuss this with Coverity as this seems
> > like a weird false positive.
> >
> > Apologies for the noise.
> >
> > Colin
>
>
>
> --
> Ke Wu | Software Engineer | mikewu@google.com | Google Inc.
--
Kees Cook
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: security/loadpin: Allow to exclude specific file types
2019-05-31 20:33 ` Kees Cook
@ 2019-06-04 17:01 ` Ke Wu
0 siblings, 0 replies; 6+ messages in thread
From: Ke Wu @ 2019-06-04 17:01 UTC (permalink / raw)
To: Kees Cook
Cc: Colin Ian King, James Morris, Serge E. Hallyn,
linux-security-module, linux-kernel
I sent out a new patch according to your last suggestion. Please take
a look. Thanks!
On Fri, May 31, 2019 at 1:33 PM Kees Cook <keescook@chromium.org> wrote:
>
> On Fri, May 31, 2019 at 11:03:17AM -0700, Ke Wu wrote:
> > I think Coverity is correct. Note that it's the size of
> > kernel_read_file_str (rather than exclude_read_files) doesn't equal to
> > ignore_read_file_id.
> >
> > This is because READING_MAX_ID is also an element in
> > kernel_read_file_str, which makes the size of kernel_read_file_str to
> > be READING_MAX_ID+1. I will send a new patch to fix the issue. Thanks
> > for the analysis!
>
> Ah! Yes, I see now. I was looking at the wrong things. It should be
> possible to just do:
>
> > > >> 209 for (j = 0; j < ARRAY_SIZE(kernel_read_file_str); j++) {
>
> for (j = 0; j < ARRAY_SIZE(ignore_read_file_id); j++)
>
> and add a
>
> BUILD_BUG_ON(ARRAY_SIZE(kernel_read_file_str) < ARRAY_SIZE(ignore_read_file_id))
>
> for future robustness checking.
>
> Thanks for looking at this more closely!
>
> -Kees
>
> > > >> 210 if (strcmp(cur, kernel_read_file_str[j]) == 0) {
> > > >> 211 pr_info("excluding: %s\n",
> > > >> 212 kernel_read_file_str[j]);
> > > >>
> > > >> CID 81977 (#1 of 1): Out-of-bounds write
> > > >> overrun-local: Overrunning array ignore_read_file_id of 8 4-byte
> > > >> elements at element index 8 (byte offset 35) using index j (which
> > > >> evaluates to 8).
> > > >>
> > > >> 213 ignore_read_file_id[j] = 1;
> > > >>
> > > >> According to Coverity ignore_read_file_id is an array of 8 integers.
> > > >> However, ARRAY_SIZE(kernel_read_file_str) is 9, so we have an out of
> > > >> bounds write on ignore_read_file[j] when j is 8.
> > > >
> > > > What am I missing? This doesn't fail the build:
> > > >
> > > > + BUILD_BUG_ON(ARRAY_SIZE(exclude_read_files) !=
> > > > + ARRAY_SIZE(ignore_read_file_id));
> > > >
> > > > They have the same number of elements.
> > > >
> > >
> > > Yep, that's very true. I'll discuss this with Coverity as this seems
> > > like a weird false positive.
> > >
> > > Apologies for the noise.
> > >
> > > Colin
> >
> >
> >
> > --
> > Ke Wu | Software Engineer | mikewu@google.com | Google Inc.
>
> --
> Kees Cook
--
Ke Wu | Software Engineer | mikewu@google.com | Google Inc.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-06-04 17:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-31 10:46 security/loadpin: Allow to exclude specific file types Colin Ian King
2019-05-31 14:44 ` Kees Cook
2019-05-31 14:49 ` Colin Ian King
2019-05-31 18:03 ` Ke Wu
2019-05-31 20:33 ` Kees Cook
2019-06-04 17:01 ` Ke Wu
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).