selinux: fix undefined return of cond_evaluate_expr
PATCH 1/1 selinux: fix undefined return of cond_evaluate_expr
From: Tom Rix <[email protected]>
clang static analysis reports an undefined return
security/selinux/ss/conditional.c:79:2: warning: Undefined or garbage value returned to caller [core.uninitialized.UndefReturn]
return s[0];
^~~~~~~~~~~static int cond_evaluate_expr( ...
{
u32 i;
int s[COND_EXPR_MAXDEPTH];
for (i = 0; i < expr->len; i++)
...
return s[0];When expr->len is 0, the loop which sets s[0] never runs.
So return -1 if the loop never runs.
--- security/selinux/ss/conditional.c | 3 +++ 1 file changed, 3 insertions(+)
security/selinux/ss/conditional.c +3 -0
@@ -27,6 +27,9 @@ static int cond_evaluate_expr(struct policydb *p, struct cond_expr *expr)int s[COND_EXPR_MAXDEPTH ];int sp =-1 ; +if (expr->len ==0 ) +return -1 ; +for (i =0 ; i < expr->len; i++) {struct cond_expr_node *node = &expr->nodes[i];
Signature · 1 line
2.18.1
Quoted 19 lines · On Wed, Jun 17, 2020 at 8:40 AM <[email protected]> wrote:
From: Tom Rix <[email protected]>
clang static analysis reports an undefined return
security/selinux/ss/conditional.c:79:2: warning: Undefined or garbage value returned to caller [core.uninitialized.UndefReturn]return s[0]; ^~~~~~~~~~~static int cond_evaluate_expr( ...
{ u32 i; int s[COND_EXPR_MAXDEPTH]; for (i = 0; i < expr->len; i++) ... return s[0];
Quoted 5 lines
When
expr->lenis 0, the loop which sets s[0] never runs.So return -1 if the loop never runs.
Signed-off-by Tom Rix <[email protected]>
clang didn't complain about the similar pattern in security/selinux/ss/services.c:constraint_expr_eval()?
Paul Moore
maintainerQuoted 22 lines · Stephen Smalley
Quoted 21 lines · On Wed, Jun 17, 2020 at 8:40 AM <[email protected]> wrote:
From: Tom Rix <[email protected]>
clang static analysis reports an undefined return
security/selinux/ss/conditional.c:79:2: warning: Undefined or garbage value returned to caller [core.uninitialized.UndefReturn]return s[0]; ^~~~~~~~~~~static int cond_evaluate_expr( ...
{ u32 i; int s[COND_EXPR_MAXDEPTH]; for (i = 0; i < expr->len; i++) ... return s[0];When
expr->lenis 0, the loop which sets s[0] never runs.
Quoted 8 lines
Quoted 3 lines
So return -1 if the loop never runs.
Signed-off-by Tom Rix <[email protected]>Acked-by Stephen Smalley <[email protected]>clang didn't complain about the similar pattern in security/selinux/ss/services.c:constraint_expr_eval()?
Related question: I appreciate the work you are doing Tom, can you share how far along you are testing the SELinux code with clang? I ask because it would be nice to roll all of these patches up into one PR for Linus instead of sending multiple updates.
Signature · 2 lines
paul moore www.paul-moore.com
Paul Moore
maintainerQuoted 30 lines · Paul Moore
Quoted 28 lines · Stephen Smalley
Quoted 19 lines · On Wed, Jun 17, 2020 at 8:40 AM <[email protected]> wrote:
From: Tom Rix <[email protected]>
clang static analysis reports an undefined return
security/selinux/ss/conditional.c:79:2: warning: Undefined or garbage value returned to caller [core.uninitialized.UndefReturn]return s[0]; ^~~~~~~~~~~static int cond_evaluate_expr( ...
{ u32 i; int s[COND_EXPR_MAXDEPTH]; for (i = 0; i < expr->len; i++) ... return s[0];Quoted 5 lines
When
expr->lenis 0, the loop which sets s[0] never runs.So return -1 if the loop never runs.
Signed-off-by Tom Rix <[email protected]>Acked-by Stephen Smalley <[email protected]>
Quoted 7 lines
Quoted 2 lines
clang didn't complain about the similar pattern in security/selinux/ss/services.c:constraint_expr_eval()?
Related question: I appreciate the work you are doing Tom, can you share how far along you are testing the SELinux code with clang? I ask because it would be nice to roll all of these patches up into one PR for Linus instead of sending multiple updates.
Regardless, this patch looks good to me too so I've merged it into the selinux/stable-5.8 branch with the others. Thank you.
It would still be nice to know if there are other clang failures you are working on fixing or if this is it for awhile.
Signature · 2 lines
paul moore www.paul-moore.com