From: elfring@users.sourceforge.net (SF Markus Elfring)
To: linux-security-module@vger.kernel.org
Subject: [PATCH 2/4] selinux: Adjust jump targets in ebitmap_read()
Date: Sun, 13 Aug 2017 16:46:53 +0200 [thread overview]
Message-ID: <2c4582c9-efc1-4b8c-1095-84e00062c7de@users.sourceforge.net> (raw)
In-Reply-To: <e9f47cc9-fda7-dc54-bca9-cae6488914e0@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 13 Aug 2017 15:21:43 +0200
Adjust jump targets so that the function implementation becomes smaller.
* Move an error message so that it is present only once here.
* Avoid another check for the local variable "rc" at the end.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/selinux/ss/ebitmap.c | 38 ++++++++++++++++++--------------------
1 file changed, 18 insertions(+), 20 deletions(-)
diff --git a/security/selinux/ss/ebitmap.c b/security/selinux/ss/ebitmap.c
index ccf372db689c..03581d7ef817 100644
--- a/security/selinux/ss/ebitmap.c
+++ b/security/selinux/ss/ebitmap.c
@@ -350,21 +350,20 @@ int ebitmap_read(struct ebitmap *e, void *fp)
__le32 buf[3];
int rc, i;
- ebitmap_init(e);
-
rc = next_entry(buf, fp, sizeof buf);
if (rc < 0)
goto out;
- mapunit = le32_to_cpu(buf[0]);
+ ebitmap_init(e);
e->highbit = le32_to_cpu(buf[1]);
count = le32_to_cpu(buf[2]);
+ mapunit = le32_to_cpu(buf[0]);
if (mapunit != BITS_PER_U64) {
printk(KERN_ERR "SELinux: ebitmap: map size %u does not "
"match my size %zd (high bit was %d)\n",
mapunit, BITS_PER_U64, e->highbit);
- goto bad;
+ goto destroy_bitmap;
}
/* round up e->highbit */
@@ -377,27 +376,26 @@ int ebitmap_read(struct ebitmap *e, void *fp)
}
if (e->highbit && !count)
- goto bad;
+ goto destroy_bitmap;
for (i = 0; i < count; i++) {
rc = next_entry(&startbit, fp, sizeof(u32));
- if (rc < 0) {
- printk(KERN_ERR "SELinux: ebitmap: truncated map\n");
- goto bad;
- }
+ if (rc)
+ goto report_truncated_map;
+
startbit = le32_to_cpu(startbit);
if (startbit & (mapunit - 1)) {
printk(KERN_ERR "SELinux: ebitmap start bit (%d) is "
"not a multiple of the map unit size (%u)\n",
startbit, mapunit);
- goto bad;
+ goto destroy_bitmap;
}
if (startbit > e->highbit - mapunit) {
printk(KERN_ERR "SELinux: ebitmap start bit (%d) is "
"beyond the end of the bitmap (%u)\n",
startbit, (e->highbit - mapunit));
- goto bad;
+ goto destroy_bitmap;
}
if (!n || startbit >= n->startbit + EBITMAP_SIZE) {
@@ -407,7 +405,7 @@ int ebitmap_read(struct ebitmap *e, void *fp)
printk(KERN_ERR
"SELinux: ebitmap: out of memory\n");
rc = -ENOMEM;
- goto bad;
+ goto destroy_bitmap;
}
/* round down */
tmp->startbit = startbit - (startbit % EBITMAP_SIZE);
@@ -420,14 +418,13 @@ int ebitmap_read(struct ebitmap *e, void *fp)
printk(KERN_ERR "SELinux: ebitmap: start bit %d"
" comes after start bit %d\n",
startbit, n->startbit);
- goto bad;
+ goto destroy_bitmap;
}
rc = next_entry(&map, fp, sizeof(u64));
- if (rc < 0) {
- printk(KERN_ERR "SELinux: ebitmap: truncated map\n");
- goto bad;
- }
+ if (rc)
+ goto report_truncated_map;
+
map = le64_to_cpu(map);
index = (startbit - n->startbit) / EBITMAP_UNIT_SIZE;
@@ -438,9 +435,10 @@ int ebitmap_read(struct ebitmap *e, void *fp)
}
out:
return rc;
-bad:
- if (!rc)
- rc = -EINVAL;
+report_truncated_map:
+ printk(KERN_ERR "SELinux: ebitmap: truncated map\n");
+ rc = -EINVAL;
+destroy_bitmap:
ebitmap_destroy(e);
goto out;
}
--
2.14.0
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2017-08-13 14:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-13 14:43 [PATCH 0/4] SELinux: Fine-tuning for some function implementations SF Markus Elfring
2017-08-13 14:45 ` [PATCH 1/4] selinux: Delete eight unnecessary variable assignments SF Markus Elfring
2017-08-13 16:22 ` Serge E. Hallyn
2017-08-13 16:24 ` Serge E. Hallyn
2017-08-13 14:46 ` SF Markus Elfring [this message]
2017-08-13 16:24 ` [PATCH 2/4] selinux: Adjust jump targets in ebitmap_read() Serge E. Hallyn
2017-08-13 14:48 ` [PATCH 3/4] selinux: Delete an unnecessary return statement in ebitmap_destroy() SF Markus Elfring
2017-08-13 14:50 ` [PATCH 4/4] selinux: Adjust five checks for null pointers SF Markus Elfring
2017-08-13 15:41 ` Serge E. Hallyn
2017-08-14 20:59 ` [PATCH 0/4] SELinux: Fine-tuning for some function implementations 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=2c4582c9-efc1-4b8c-1095-84e00062c7de@users.sourceforge.net \
--to=elfring@users.sourceforge.net \
--cc=linux-security-module@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).