selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Wei Yongjun <weiyongjun1@huawei.com>
Cc: Paul Moore <paul@paul-moore.com>,
	Stephen Smalley <stephen.smalley.work@gmail.com>,
	Eric Paris <eparis@parisplace.org>,
	Ondrej Mosnacek <omosnace@redhat.com>,
	Jeff Vander Stoep <jeffv@google.com>,
	selinux@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH -next] selinux: fix error return code in policydb_read()
Date: Wed, 29 Apr 2020 06:07:38 -0700 (PDT)	[thread overview]
Message-ID: <20200429130738.GQ2014@kadam> (raw)
In-Reply-To: <20200429073053.83660-1-weiyongjun1@huawei.com>

On Wed, Apr 29, 2020 at 07:30:53AM +0000, Wei Yongjun wrote:
> Fix to return negative error code -ENOMEM from the kvcalloc() error
> handling case instead of 0, as done elsewhere in this function.
> 

Please add a Fixes tag and Cc Kent.

Fixes: acdf52d97f82 ("selinux: convert to kvmalloc")


> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> ---
>  security/selinux/ss/policydb.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
> index a0b3dc152468..a51e051df2cc 100644
> --- a/security/selinux/ss/policydb.c
> +++ b/security/selinux/ss/policydb.c
> @@ -2638,6 +2638,7 @@ int policydb_read(struct policydb *p, void *fp)
>  	if (rc)
>  		goto bad;
>  
> +	rc = -ENOMEM;
>  	p->type_attr_map_array = kvcalloc(p->p_types.nprim,
>  					  sizeof(*p->type_attr_map_array),
>  					  GFP_KERNEL);

There is another bug earlier in the function as well:

security/selinux/ss/policydb.c
  2537  
  2538          rc = next_entry(buf, fp, sizeof(u32));
  2539          if (rc)
  2540                  goto bad;
  2541          nel = le32_to_cpu(buf[0]);
  2542  
  2543          p->role_tr = hashtab_create(role_trans_hash, role_trans_cmp, nel);
  2544          if (!p->role_tr)
  2545                  goto bad;
                        ^^^^^^^^

  2546          for (i = 0; i < nel; i++) {
  2547                  rc = -ENOMEM;

This style of setting the error code seems very bug prone.

The Fixes tag for this one is:
Fixes: e67b2ec9f617 ("selinux: store role transitions in a hash table")

Just put both tags in the commit message.

regards,
dan carpenter

  reply	other threads:[~2020-04-29 13:15 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-29  7:30 [PATCH -next] selinux: fix error return code in policydb_read() Wei Yongjun
2020-04-29 13:07 ` Dan Carpenter [this message]
2020-04-29 13:32   ` Ondrej Mosnacek
2020-04-29 13:47     ` Dan Carpenter
2020-05-01 19:08     ` Paul Moore
2020-05-01 19:52       ` Ondrej Mosnacek
2020-05-01 16:46   ` Paul Moore
2020-05-04 19:17     ` Dan Carpenter
2020-05-01 19:04 ` Paul Moore
  -- strict thread matches above, loose matches on Subject: below --
2019-01-18 14:23 [PATCH -next] selinux: Fix " Wei Yongjun
2019-01-18 21:28 ` Paul Moore
2019-01-19  0:21   ` Stephen Rothwell
2019-01-20 20:04     ` Stephen Rothwell
2019-01-22 17:39       ` Paul Moore
2019-01-25 21:59         ` Paul Moore
2016-09-10  7:43 [PATCH -next] SELinux: fix " Wei Yongjun
2016-09-13 21:19 ` Paul Moore

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=20200429130738.GQ2014@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=eparis@parisplace.org \
    --cc=jeffv@google.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=omosnace@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=selinux@vger.kernel.org \
    --cc=stephen.smalley.work@gmail.com \
    --cc=weiyongjun1@huawei.com \
    /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;
as well as URLs for NNTP newsgroup(s).