flawopen.com/Teardowns/cve-2023-2640-ubuntu-overlayfs-privilege-escalation
CVE-2023-2640: Ubuntu OverlayFS में LPE
CVE-2023-2640 कुछ Ubuntu kernel builds में OverlayFS permission checks को bypass करता है। Kernel variant जाँचें और vendor fix लगाएँ।
एक इमारत की कल्पना करें जहाँ कर्मचारी जाँचता है कि कोई व्यक्ति दस्तावेज़ पर आधिकारिक मुहर लगा सकता है या नहीं। स्थानीय shortcut केवल इमारत के रखरखाव वाले लेबल के लिए जाँच छोड़ने हेतु था। बाद के बदलाव ने प्रतिबंधित सुरक्षा मुहरों समेत हर अनुरोध को उसी shortcut से भेज दिया। सुधार mounted filesystem के user namespace में सामान्य permission check वापस लाता है।
इस पेज के मुख्य शब्द
OverlayFS- OverlayFS Linux का union filesystem है जो lower layer की files दिखाता है और बदलाव upper layer में लिखता है।
Extended attribute (xattr)- Extended attribute (xattr) filesystem object से जुड़ा metadata है। Linux security modules और file capabilities कुछ xattr namespaces का उपयोग करते हैं।
ovl_do_setxattr()- OverlayFS helper जो upper-layer object पर xattr लिखता है। प्रभावित wrapper ने permission checks के बिना VFS helper का बहुत व्यापक उपयोग किया।
Copy-up- OverlayFS operation जो write के लिए lower-layer object की writable copy आवश्यक होने पर upper layer में copy बनाता है।
फ्रेमवर्क मैपिंग
- इस गाइड में बताई गई कमजोरी के लिए CWE संदर्भ: CWE-863
मूल कारण विश्लेषण (Root Cause)
Ubuntu CVE रिकॉर्ड के अनुसार vulnerable configuration में upstream commit c914c0e27eb0 और Ubuntu SAUCE patch “Skip permission checking for trusted.overlayfs.* xattrs” दोनों होने चाहिए। SAUCE patch ने OverlayFS xattr wrappers को VFS _noperm helpers पर बदला था, ताकि जाँच केवल आंतरिक trusted.overlayfs.* metadata के लिए छोड़ी जाए। Upstream wrapper बदलाव के बाद helper अन्य xattrs के लिए भी उपयोग हुआ। इसलिए स्थानीय non-privileged user mounted files पर privileged extended attributes सेट कर सकता था और उन्हें उचित जाँच के बिना upper-layer files तक पहुँचा सकता था। Canonical का fix व्यापक no-permission path को वापस लेता है और upper mount के user namespace के साथ vfs_setxattr() बुलाता है। यह Ubuntu kernel का local privilege-escalation issue है; exposure release, kernel variant तथा namespace और mount policies पर निर्भर है।
हमले का चरण-दर-चरण प्रवाह
प्रभावित Ubuntu kernel configuration
Kernel में c914c0e27eb0 और trusted.overlayfs.* xattrs की checks छोड़ने वाला Ubuntu SAUCE patch दोनों होने चाहिए। केवल upstream version से exposure साबित नहीं होता।
स्थानीय user xattr path तक पहुँचता है
Host की namespace और mount policy के अनुसार स्थानीय non-privileged user को प्रभावित OverlayFS path उपयोग करने में सक्षम होना चाहिए। Ubuntu इसे local attack बताता है।
Permission bypass अन्य xattrs तक फैला
बदला हुआ wrapper xattr updates को _noperm helpers तक भेजता था, जो OverlayFS के internal metadata के लिए थे। Upstream बदलाव के बाद अन्य xattrs भी उचित checks से बच सकते थे।
Privileged attribute upper object तक पहुँचता है
Ubuntu के अनुसार privileged extended attributes mounted files पर सेट होकर आवश्यक checks के बिना upper files में copy हो सकते थे, जिससे local privilege escalation संभव है। हर kernel या container configuration समान नहीं है।
सोर्स कोड: कमज़ोर बनाम सुरक्षित कार्यान्वयन
प्रभावित SAUCE path upstream बदलाव से दायरा बढ़ने के बाद सभी xattrs के लिए __vfs_setxattr_noperm() बुलाता था। सुधार upper mount के user namespace के साथ vfs_setxattr() का उपयोग कर सामान्य VFS checks वापस लाता है। यह Canonical patch का focused excerpt है; आसपास के debug logs छोड़े गए हैं।
सोर्स अंश: fs/overlayfs/overlayfs.h
/* SAUCE बदलाव को वापस लेने से पहले Ubuntu के canonical patch का संदर्भ। */
static inline int ovl_do_setxattr(struct ovl_fs *ofs, struct dentry *dentry,
const char *name, const void *value,
size_t size, int flags)
{
struct inode *inode = dentry->d_inode;
int err;
inode_lock(inode);
err = __vfs_setxattr_noperm(&init_user_ns, dentry, name,
value, size, flags);
inode_unlock(inode);
return err;
}
/* Ubuntu का canonical fix: permission जाँचने वाला VFS wrapper बहाल करें। */
static inline int ovl_do_setxattr(struct ovl_fs *ofs, struct dentry *dentry,
const char *name, const void *value,
size_t size, int flags)
{
int err = vfs_setxattr(ovl_upper_mnt_userns(ofs), dentry, name,
value, size, flags);
return err;
}
इंजीनियरिंग और सिस्टम सुरक्षा चेकलिस्ट
- ✓सटीक release, kernel variant और package के लिए Ubuntu CVE tracker देखें; यह Ubuntu और upstream बदलावों के खास संयोजन पर निर्भर है।
- ✓प्रभावित Ubuntu release और kernel variant का fixed package install करें, reboot करें और चल रहे kernel की पुष्टि करें।
- ✓यदि update टालना हो तो unprivileged user namespace creation सीमित करने के Ubuntu-documented अस्थायी उपाय का मूल्यांकन करें; apps और containers का प्रभाव test करें।
- ✓OverlayFS xattr wrappers में user-controlled attributes के लिए सही mount user namespace वाला permission-checking VFS API उपयोग करें; no-check helpers केवल उचित internal metadata के लिए रखें।