@@ -168,34 +168,12 @@ static int nlmsg_perm(u16 nlmsg_type, u32 *perm, const struct nlmsg_perm *tab, s
168
168
169
169
int selinux_nlmsg_lookup (u16 sclass , u16 nlmsg_type , u32 * perm )
170
170
{
171
- int err = 0 ;
172
-
173
- if (selinux_policycap_netlink_xperm ()) {
174
- switch (sclass ) {
175
- case SECCLASS_NETLINK_ROUTE_SOCKET :
176
- * perm = NETLINK_ROUTE_SOCKET__NLMSG ;
177
- break ;
178
- case SECCLASS_NETLINK_TCPDIAG_SOCKET :
179
- * perm = NETLINK_TCPDIAG_SOCKET__NLMSG ;
180
- break ;
181
- case SECCLASS_NETLINK_XFRM_SOCKET :
182
- * perm = NETLINK_XFRM_SOCKET__NLMSG ;
183
- break ;
184
- case SECCLASS_NETLINK_AUDIT_SOCKET :
185
- * perm = NETLINK_AUDIT_SOCKET__NLMSG ;
186
- break ;
187
- /* While it is possible to add a similar permission to other
188
- * netlink classes, note that the extended permission value is
189
- * matched against the nlmsg_type field. Notably,
190
- * SECCLASS_NETLINK_GENERIC_SOCKET uses dynamic values for this
191
- * field, which means that it cannot be added as-is.
192
- */
193
- default :
194
- err = - ENOENT ;
195
- break ;
196
- }
197
- return err ;
198
- }
171
+ /* While it is possible to add a similar permission to other netlink
172
+ * classes, note that the extended permission value is matched against
173
+ * the nlmsg_type field. Notably, SECCLASS_NETLINK_GENERIC_SOCKET uses
174
+ * dynamic values for this field, which means that it cannot be added
175
+ * as-is.
176
+ */
199
177
200
178
switch (sclass ) {
201
179
case SECCLASS_NETLINK_ROUTE_SOCKET :
@@ -205,42 +183,52 @@ int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm)
205
183
* before updating the BUILD_BUG_ON() macro!
206
184
*/
207
185
BUILD_BUG_ON (RTM_MAX != (RTM_NEWTUNNEL + 3 ));
208
- err = nlmsg_perm (nlmsg_type , perm , nlmsg_route_perms ,
209
- sizeof (nlmsg_route_perms ));
210
- break ;
211
186
187
+ if (selinux_policycap_netlink_xperm ()) {
188
+ * perm = NETLINK_ROUTE_SOCKET__NLMSG ;
189
+ return 0 ;
190
+ }
191
+ return nlmsg_perm (nlmsg_type , perm , nlmsg_route_perms ,
192
+ sizeof (nlmsg_route_perms ));
193
+ break ;
212
194
case SECCLASS_NETLINK_TCPDIAG_SOCKET :
213
- err = nlmsg_perm (nlmsg_type , perm , nlmsg_tcpdiag_perms ,
214
- sizeof (nlmsg_tcpdiag_perms ));
195
+ if (selinux_policycap_netlink_xperm ()) {
196
+ * perm = NETLINK_TCPDIAG_SOCKET__NLMSG ;
197
+ return 0 ;
198
+ }
199
+ return nlmsg_perm (nlmsg_type , perm , nlmsg_tcpdiag_perms ,
200
+ sizeof (nlmsg_tcpdiag_perms ));
215
201
break ;
216
-
217
202
case SECCLASS_NETLINK_XFRM_SOCKET :
218
203
/* If the BUILD_BUG_ON() below fails you must update the
219
204
* structures at the top of this file with the new mappings
220
205
* before updating the BUILD_BUG_ON() macro!
221
206
*/
222
207
BUILD_BUG_ON (XFRM_MSG_MAX != XFRM_MSG_GETDEFAULT );
223
- err = nlmsg_perm (nlmsg_type , perm , nlmsg_xfrm_perms ,
224
- sizeof (nlmsg_xfrm_perms ));
225
- break ;
226
208
209
+ if (selinux_policycap_netlink_xperm ()) {
210
+ * perm = NETLINK_XFRM_SOCKET__NLMSG ;
211
+ return 0 ;
212
+ }
213
+ return nlmsg_perm (nlmsg_type , perm , nlmsg_xfrm_perms ,
214
+ sizeof (nlmsg_xfrm_perms ));
215
+ break ;
227
216
case SECCLASS_NETLINK_AUDIT_SOCKET :
228
- if ((nlmsg_type >= AUDIT_FIRST_USER_MSG &&
229
- nlmsg_type <= AUDIT_LAST_USER_MSG ) ||
230
- (nlmsg_type >= AUDIT_FIRST_USER_MSG2 &&
231
- nlmsg_type <= AUDIT_LAST_USER_MSG2 )) {
217
+ if (selinux_policycap_netlink_xperm ()) {
218
+ * perm = NETLINK_AUDIT_SOCKET__NLMSG ;
219
+ return 0 ;
220
+ } else if ((nlmsg_type >= AUDIT_FIRST_USER_MSG &&
221
+ nlmsg_type <= AUDIT_LAST_USER_MSG ) ||
222
+ (nlmsg_type >= AUDIT_FIRST_USER_MSG2 &&
223
+ nlmsg_type <= AUDIT_LAST_USER_MSG2 )) {
232
224
* perm = NETLINK_AUDIT_SOCKET__NLMSG_RELAY ;
233
- } else {
234
- err = nlmsg_perm (nlmsg_type , perm , nlmsg_audit_perms ,
235
- sizeof (nlmsg_audit_perms ));
225
+ return 0 ;
236
226
}
237
- break ;
238
-
239
- /* No messaging from userspace, or class unknown/unhandled */
240
- default :
241
- err = - ENOENT ;
227
+ return nlmsg_perm (nlmsg_type , perm , nlmsg_audit_perms ,
228
+ sizeof (nlmsg_audit_perms ));
242
229
break ;
243
230
}
244
231
245
- return err ;
232
+ /* No messaging from userspace, or class unknown/unhandled */
233
+ return - ENOENT ;
246
234
}
0 commit comments