Smack: check for 'struct socket' with NULL sk

There's a small problem with smack and NFS. A similar report was also
sent here: http://lkml.org/lkml/2007/10/27/85

I've also added similar checks in inode_{get/set}security(). Cheating from
SELinux post_create_socket(), it does the same.

[akpm@linux-foundation.org: remove uneeded BUG_ON()]
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
Acked-by: Casey Schaufler <casey@schuafler-ca.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Ahmed S. Darwish and committed by Linus Torvalds 2e1d146a cba44359

+5 -4
+5 -4
security/smack/smack_lsm.c
··· 701 701 return -EOPNOTSUPP; 702 702 703 703 sock = SOCKET_I(ip); 704 - if (sock == NULL) 704 + if (sock == NULL || sock->sk == NULL) 705 705 return -EOPNOTSUPP; 706 706 707 707 ssp = sock->sk->sk_security; ··· 1280 1280 */ 1281 1281 static int smack_netlabel(struct sock *sk) 1282 1282 { 1283 - struct socket_smack *ssp = sk->sk_security; 1283 + struct socket_smack *ssp; 1284 1284 struct netlbl_lsm_secattr secattr; 1285 1285 int rc = 0; 1286 1286 1287 + ssp = sk->sk_security; 1287 1288 netlbl_secattr_init(&secattr); 1288 1289 smack_to_secattr(ssp->smk_out, &secattr); 1289 1290 if (secattr.flags != NETLBL_SECATTR_NONE) ··· 1332 1331 return -EOPNOTSUPP; 1333 1332 1334 1333 sock = SOCKET_I(inode); 1335 - if (sock == NULL) 1334 + if (sock == NULL || sock->sk == NULL) 1336 1335 return -EOPNOTSUPP; 1337 1336 1338 1337 ssp = sock->sk->sk_security; ··· 1363 1362 static int smack_socket_post_create(struct socket *sock, int family, 1364 1363 int type, int protocol, int kern) 1365 1364 { 1366 - if (family != PF_INET) 1365 + if (family != PF_INET || sock->sk == NULL) 1367 1366 return 0; 1368 1367 /* 1369 1368 * Set the outbound netlbl.