hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/security/selinux/netport.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Network port table
34 *
....@@ -10,21 +11,10 @@
1011 * This code is heavily based on the "netif" concept originally developed by
1112 * James Morris <jmorris@redhat.com>
1213 * (see security/selinux/netif.c for more information)
13
- *
1414 */
1515
1616 /*
1717 * (c) Copyright Hewlett-Packard Development Company, L.P., 2008
18
- *
19
- * This program is free software: you can redistribute it and/or modify
20
- * it under the terms of version 2 of the GNU General Public License as
21
- * published by the Free Software Foundation.
22
- *
23
- * This program is distributed in the hope that it will be useful,
24
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
- * GNU General Public License for more details.
27
- *
2818 */
2919
3020 #include <linux/types.h>
....@@ -140,16 +130,16 @@
140130 * @sid: port SID
141131 *
142132 * Description:
143
- * This function determines the SID of a network port by quering the security
133
+ * This function determines the SID of a network port by querying the security
144134 * policy. The result is added to the network port table to speedup future
145135 * queries. Returns zero on success, negative values on failure.
146136 *
147137 */
148138 static int sel_netport_sid_slow(u8 protocol, u16 pnum, u32 *sid)
149139 {
150
- int ret = -ENOMEM;
140
+ int ret;
151141 struct sel_netport *port;
152
- struct sel_netport *new = NULL;
142
+ struct sel_netport *new;
153143
154144 spin_lock_bh(&sel_netport_lock);
155145 port = sel_netport_find(protocol, pnum);
....@@ -158,25 +148,23 @@
158148 spin_unlock_bh(&sel_netport_lock);
159149 return 0;
160150 }
161
- new = kzalloc(sizeof(*new), GFP_ATOMIC);
162
- if (new == NULL)
163
- goto out;
151
+
164152 ret = security_port_sid(&selinux_state, protocol, pnum, sid);
165153 if (ret != 0)
166154 goto out;
167
-
168
- new->psec.port = pnum;
169
- new->psec.protocol = protocol;
170
- new->psec.sid = *sid;
171
- sel_netport_insert(new);
155
+ new = kzalloc(sizeof(*new), GFP_ATOMIC);
156
+ if (new) {
157
+ new->psec.port = pnum;
158
+ new->psec.protocol = protocol;
159
+ new->psec.sid = *sid;
160
+ sel_netport_insert(new);
161
+ }
172162
173163 out:
174164 spin_unlock_bh(&sel_netport_lock);
175
- if (unlikely(ret)) {
165
+ if (unlikely(ret))
176166 pr_warn("SELinux: failure in %s(), unable to determine network port label\n",
177167 __func__);
178
- kfree(new);
179
- }
180168 return ret;
181169 }
182170
....@@ -237,7 +225,7 @@
237225 {
238226 int iter;
239227
240
- if (!selinux_enabled)
228
+ if (!selinux_enabled_boot)
241229 return 0;
242230
243231 for (iter = 0; iter < SEL_NETPORT_HASH_SIZE; iter++) {