* [PATCH 0/2] fix is_pure_ops_struct()
@ 2019-07-31 18:00 Joonwon Kang
2019-07-31 18:01 ` [PATCH 1/2] randstruct: fix a bug in is_pure_ops_struct() Joonwon Kang
2019-07-31 18:01 ` [PATCH 2/2] randstruct: remove dead code " Joonwon Kang
0 siblings, 2 replies; 6+ messages in thread
From: Joonwon Kang @ 2019-07-31 18:00 UTC (permalink / raw)
To: keescook
Cc: re.emese, kernel-hardening, linux-kernel, kernel-janitors, jinb.park7
Hello,
This series fixes unreachable code bug and removes dead code in
is_pure_ops_struct().
Thanks.
Joonwon Kang (2):
randstruct: fix a bug in is_pure_ops_struct()
randstruct: remove dead code in is_pure_ops_struct()
scripts/gcc-plugins/randomize_layout_plugin.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] randstruct: fix a bug in is_pure_ops_struct()
2019-07-31 18:00 [PATCH 0/2] fix is_pure_ops_struct() Joonwon Kang
@ 2019-07-31 18:01 ` Joonwon Kang
2019-07-31 19:58 ` Kees Cook
2019-07-31 18:01 ` [PATCH 2/2] randstruct: remove dead code " Joonwon Kang
1 sibling, 1 reply; 6+ messages in thread
From: Joonwon Kang @ 2019-07-31 18:01 UTC (permalink / raw)
To: keescook
Cc: re.emese, kernel-hardening, linux-kernel, kernel-janitors, jinb.park7
Before this, there were false negatives in the case where a struct
contains other structs which contain only function pointers because
of unreachable code in is_pure_ops_struct().
Signed-off-by: Joonwon Kang <kjw1627@gmail.com>
---
scripts/gcc-plugins/randomize_layout_plugin.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/scripts/gcc-plugins/randomize_layout_plugin.c b/scripts/gcc-plugins/randomize_layout_plugin.c
index 6d5bbd31db7f..bd29e4e7a524 100644
--- a/scripts/gcc-plugins/randomize_layout_plugin.c
+++ b/scripts/gcc-plugins/randomize_layout_plugin.c
@@ -443,13 +443,13 @@ static int is_pure_ops_struct(const_tree node)
if (node == fieldtype)
continue;
- if (!is_fptr(fieldtype))
- return 0;
-
- if (code != RECORD_TYPE && code != UNION_TYPE)
+ if (code == RECORD_TYPE || code == UNION_TYPE) {
+ if (!is_pure_ops_struct(fieldtype))
+ return 0;
continue;
+ }
- if (!is_pure_ops_struct(fieldtype))
+ if (!is_fptr(fieldtype))
return 0;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] randstruct: remove dead code in is_pure_ops_struct()
2019-07-31 18:00 [PATCH 0/2] fix is_pure_ops_struct() Joonwon Kang
2019-07-31 18:01 ` [PATCH 1/2] randstruct: fix a bug in is_pure_ops_struct() Joonwon Kang
@ 2019-07-31 18:01 ` Joonwon Kang
2019-07-31 19:59 ` Kees Cook
1 sibling, 1 reply; 6+ messages in thread
From: Joonwon Kang @ 2019-07-31 18:01 UTC (permalink / raw)
To: keescook
Cc: re.emese, kernel-hardening, linux-kernel, kernel-janitors, jinb.park7
Recursive declaration for struct which has member of the same struct
type, for example,
struct foo {
struct foo f;
...
};
is not allowed. So, it is unnecessary to check if a struct has this
kind of member.
Signed-off-by: Joonwon Kang <kjw1627@gmail.com>
---
scripts/gcc-plugins/randomize_layout_plugin.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/scripts/gcc-plugins/randomize_layout_plugin.c b/scripts/gcc-plugins/randomize_layout_plugin.c
index bd29e4e7a524..e14efe23e645 100644
--- a/scripts/gcc-plugins/randomize_layout_plugin.c
+++ b/scripts/gcc-plugins/randomize_layout_plugin.c
@@ -440,9 +440,6 @@ static int is_pure_ops_struct(const_tree node)
const_tree fieldtype = get_field_type(field);
enum tree_code code = TREE_CODE(fieldtype);
- if (node == fieldtype)
- continue;
-
if (code == RECORD_TYPE || code == UNION_TYPE) {
if (!is_pure_ops_struct(fieldtype))
return 0;
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] randstruct: fix a bug in is_pure_ops_struct()
2019-07-31 18:01 ` [PATCH 1/2] randstruct: fix a bug in is_pure_ops_struct() Joonwon Kang
@ 2019-07-31 19:58 ` Kees Cook
0 siblings, 0 replies; 6+ messages in thread
From: Kees Cook @ 2019-07-31 19:58 UTC (permalink / raw)
To: Joonwon Kang
Cc: re.emese, kernel-hardening, linux-kernel, kernel-janitors, jinb.park7
On Thu, Aug 01, 2019 at 03:01:10AM +0900, Joonwon Kang wrote:
> Before this, there were false negatives in the case where a struct
> contains other structs which contain only function pointers because
> of unreachable code in is_pure_ops_struct().
>
> Signed-off-by: Joonwon Kang <kjw1627@gmail.com>
I've applied this (with some commit log tweaks) and it should be visible
in linux-next soon. I'll send this on to Linus before -rc3.
--
Kees Cook
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] randstruct: remove dead code in is_pure_ops_struct()
2019-07-31 18:01 ` [PATCH 2/2] randstruct: remove dead code " Joonwon Kang
@ 2019-07-31 19:59 ` Kees Cook
2019-08-01 13:41 ` Joonwon Kang
0 siblings, 1 reply; 6+ messages in thread
From: Kees Cook @ 2019-07-31 19:59 UTC (permalink / raw)
To: Joonwon Kang
Cc: re.emese, kernel-hardening, linux-kernel, kernel-janitors, jinb.park7
On Thu, Aug 01, 2019 at 03:01:49AM +0900, Joonwon Kang wrote:
> Recursive declaration for struct which has member of the same struct
> type, for example,
>
> struct foo {
> struct foo f;
> ...
> };
>
> is not allowed. So, it is unnecessary to check if a struct has this
> kind of member.
Is that the only case where this loop could happen? Seems also safe to
just leave it as-is...
-Kees
>
> Signed-off-by: Joonwon Kang <kjw1627@gmail.com>
> ---
> scripts/gcc-plugins/randomize_layout_plugin.c | 3 ---
> 1 file changed, 3 deletions(-)
>
> diff --git a/scripts/gcc-plugins/randomize_layout_plugin.c b/scripts/gcc-plugins/randomize_layout_plugin.c
> index bd29e4e7a524..e14efe23e645 100644
> --- a/scripts/gcc-plugins/randomize_layout_plugin.c
> +++ b/scripts/gcc-plugins/randomize_layout_plugin.c
> @@ -440,9 +440,6 @@ static int is_pure_ops_struct(const_tree node)
> const_tree fieldtype = get_field_type(field);
> enum tree_code code = TREE_CODE(fieldtype);
>
> - if (node == fieldtype)
> - continue;
> -
> if (code == RECORD_TYPE || code == UNION_TYPE) {
> if (!is_pure_ops_struct(fieldtype))
> return 0;
> --
> 2.17.1
>
--
Kees Cook
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] randstruct: remove dead code in is_pure_ops_struct()
2019-07-31 19:59 ` Kees Cook
@ 2019-08-01 13:41 ` Joonwon Kang
0 siblings, 0 replies; 6+ messages in thread
From: Joonwon Kang @ 2019-08-01 13:41 UTC (permalink / raw)
To: Kees Cook
Cc: re.emese, kernel-hardening, linux-kernel, kernel-janitors, jinb.park7
On Wed, Jul 31, 2019 at 12:59:30PM -0700, Kees Cook wrote:
> On Thu, Aug 01, 2019 at 03:01:49AM +0900, Joonwon Kang wrote:
> > Recursive declaration for struct which has member of the same struct
> > type, for example,
> >
> > struct foo {
> > struct foo f;
> > ...
> > };
> >
> > is not allowed. So, it is unnecessary to check if a struct has this
> > kind of member.
>
> Is that the only case where this loop could happen? Seems also safe to
> just leave it as-is...
>
> -Kees
I think it is pretty obvious that it is the only case. I compiled kernel
with allyesconfig and the condition never hit even once. However, it will
also be no problem to just leave it as-is as you mentioned.
>
> >
> > Signed-off-by: Joonwon Kang <kjw1627@gmail.com>
> > ---
> > scripts/gcc-plugins/randomize_layout_plugin.c | 3 ---
> > 1 file changed, 3 deletions(-)
> >
> > diff --git a/scripts/gcc-plugins/randomize_layout_plugin.c b/scripts/gcc-plugins/randomize_layout_plugin.c
> > index bd29e4e7a524..e14efe23e645 100644
> > --- a/scripts/gcc-plugins/randomize_layout_plugin.c
> > +++ b/scripts/gcc-plugins/randomize_layout_plugin.c
> > @@ -440,9 +440,6 @@ static int is_pure_ops_struct(const_tree node)
> > const_tree fieldtype = get_field_type(field);
> > enum tree_code code = TREE_CODE(fieldtype);
> >
> > - if (node == fieldtype)
> > - continue;
> > -
> > if (code == RECORD_TYPE || code == UNION_TYPE) {
> > if (!is_pure_ops_struct(fieldtype))
> > return 0;
> > --
> > 2.17.1
> >
>
> --
> Kees Cook
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-08-01 13:42 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-31 18:00 [PATCH 0/2] fix is_pure_ops_struct() Joonwon Kang
2019-07-31 18:01 ` [PATCH 1/2] randstruct: fix a bug in is_pure_ops_struct() Joonwon Kang
2019-07-31 19:58 ` Kees Cook
2019-07-31 18:01 ` [PATCH 2/2] randstruct: remove dead code " Joonwon Kang
2019-07-31 19:59 ` Kees Cook
2019-08-01 13:41 ` Joonwon Kang
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).