FB_security 板


--G4iJoqBmSsgzjUCe Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jan 09, 2014 at 08:19:04PM +0400, [email protected] wrote: > Hello. >=20 > I would like to propose a patch for ping(8), which adds support for > capability mode sandbox. >=20 > The goals for this little project were: >=20 > a) to see what problems/burdens could be faced with compartmentalization > of a network utility; >=20 > b) increase security level of the day-to-day application with minimal > intrusion to the code. >=20 > To summarize on 'a)', following changes were made in original ping to > meet capsicum requirements: >=20 > 1) sendto() was replaced with connect()+send() pair, since we're not > allowed to issue sendto() with non-NULL destination; >=20 > 2) one socket 's' was replaced with two sockets 's' for sending and 's1' > for receiving. It was done for special use case, when user ping > multicast or broadcast address. As connect() man page states, socket > is allowed to receive messages only from address to which it was > connect()'ed and this is nonsense for multicast/broadcast; >=20 > 3) pr_addr() function has been slightly rewritten to support casper > daemon and its cap_gethostbyaddr() function; >=20 > 4) some setsockopts() were adjusted, since we use two sockets instead of > one. >=20 > Place for cap_enter() call was chosen to balance simplicity of the logic > for entering capability mode, code changes and protection from > potentially dangerous place (receiving/"parsing" packets from the > network). Now that you added casper to the game, I'd move gethostbyname2() until after we enter the sandbox and open system.dns service, but before we limit the service to only reverse lookups. It does process network packets after all. In practise this doesn't change much currently, as casper process responsible for doing DNS lookups is not sandboxed, but in the future it might be sandboxed using different techniques and would be nice to get this extra protection for free. > Finally, this compartmentalization logic will apply: >=20 > - If '-n' (numeric output) flag is given - enter capability mode; >=20 > - Else, if build WITH_CASPER: try to communicate with it, on fail issue > warning and proceed without capsicum, if cap_init() is successful all > other casper errors (e. g. not being able to initialize DNS services) > treated as fatal and ping aborts; >=20 > - Else, if build WITHOUT_CASPER: proceed without capsicum. >=20 > Also, please note, that ping has '-d' flag, which turn on SO_DEBUG > setsockopt() and its behavior depends on external code (which also > doesn't exist not, but could be written in future). If we enter capsicum > with this option (although, I'm sure it's not widely used) this (future) > external code may not work completely, since capsicum impose a lot of > restrictions. >=20 > I would like to ask your comments/reviews on this patch and approach. >=20 > Thanks to Gleb Smirnoff, Pawel Jakub Dawidek and Robert Watson for > helping me with some tricky capsicum things, which I tried to summarize > here. >=20 > Be well. Great! The patch overall looks very nice and complete, good work. Few minor nits inline. > --- sbin/ping/ping.c (revision 260485) > +++ sbin/ping/ping.c (working copy) [...] > +int s; /* send socket file descriptor */ > +int s1; /* receive socket file descriptor */ I'd much prefer to use some more meaningful variable names. Like 'ssend' and 'srecv' or something similar. > +#ifdef HAVE_LIBCAPSICUM > +cap_channel_t *capdns; > +#endif /* HAVE_LIBCAPSICUM */ Not sure why other globals variables aren't static, but it should be static. I don't think it is used anywhere else outside this source file. > s =3D socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); > sockerrno =3D errno; > + s1 =3D socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); > + sock1errno =3D errno; I wonder if dup(2) would be more intuitive here. Looking at the code I expect those two sockets to be different, but they aren't. dup(2) would make that 100% clear. I'll leave it to you to decide, I don't have a strong opinion on this, really. I'd still prefer to see the explanation you gave in the e-mail why do we need those two sockets in a comment. > + if (options & F_NUMERIC) > + cansandbox =3D 1; Can you make 'cansandbox' to be of type 'bool'? > + /* > + * Here we enter capapility mode (see capsicum(4)). Further down > + * creation of new file descriptors is forbidden. This is not entirely true. You can create file descriptors with dup(2), dup2(2), fcntl(F_DUP2FD), socket(2), etc. What you can't do is to address global namespaces. I'd clarify that comment. > + cap_rights_init(&rights_s1, CAP_RECV, CAP_EVENT, CAP_SETSOCKOPT); > + if (cap_rights_limit(s1, &rights_s1) < 0 && errno !=3D ENOSYS) > + err(1, "cap_rights_limit socket1"); > + > + cap_rights_init(&rights_s, CAP_SEND, CAP_SETSOCKOPT); > + if (cap_rights_limit(s, &rights_s) < 0 && errno !=3D ENOSYS) > + err(1, "cap_rights_limit socket"); [...] > + cap_rights_clear(&rights_s1, CAP_SETSOCKOPT); > + if (cap_rights_limit(s1, &rights_s1) < 0 && errno !=3D ENOSYS) > + err(1, "cap_rights_limit socket1 setsockopt"); [...] > + /* > + * We don't call setsockopt() anywhere further for 's', we don't need > + * corresponding capability, drop it. > + */ > + cap_rights_clear(&rights_s, CAP_SETSOCKOPT); > + if (cap_rights_limit(s, &rights_s) < 0 && errno !=3D ENOSYS) > + err(1, "cap_rights_limit socket setsockopt"); This made me wonder. We have two choices here: either use cap_rights_init() first and then drop capability rights we don't need anymore with cap_rights_clear() as you did or to use cap_rights_init() twice and provide list of capability rights explicitly. I think I'm more in favour of providing capability rights explicitly. If we add some additional rights in the future to the first cap_rights_init() we may forget add them to cap_rights_clear() below. That's why I'd change the code not to use cap_rights_clear(), but add a comment above second cap_rights_init() round saying which right we are removing. As a nice side-effect this would allow us to use only one 'rights' variable. I know this is nitpicking, but the Capsicum-related changes we are doing today will serve as examples tomorrow, so I'd like them to be just right. --=20 Pawel Jakub Dawidek http://www.wheelsystems.com FreeBSD committer http://www.FreeBSD.org Am I Evil? Yes, I Am! http://mobter.com --G4iJoqBmSsgzjUCe Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (FreeBSD) iEYEARECAAYFAlLPAHAACgkQForvXbEpPzQLQACgtS4uf0zBW3WH7rDJQ8f6Rik6 zksAmwR7lEwlGAqhI2Zy+HDVzIRdvu3g =heIl -----END PGP SIGNATURE----- --G4iJoqBmSsgzjUCe--







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草
伺服器連線錯誤,造成您的不便還請多多包涵!
「贊助商連結」






like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:BabyMother站內搜尋

TOP