ceph: fix corruption when using page_count 0 page in rbd
Subsystems (2)
PATCH 1/1 ceph: fix corruption when using page_count 0 page in rbd
It has been reported that using ZFSonLinux on rbd will result in memory corruption. The bug report can be found here:
https://github.com/zfsonlinux/spl/issues/241
http://tracker.ceph.com/issues/7790
The reason is that ZFS will send pages with page_count 0 into rbd, which in turns send them to tcp_sendpage. However, tcp_sendpage cannot deal with page_count 0, as it will do get_page and put_page, and erroneously free the page.
This type of issue has been noted before, and handled in iscsi, drbd, etc. So, rbd should also handle this. This fix address this issue by fall back to slower sendmsg when page_count 0 detected.
--- net/ceph/messenger.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
net/ceph/messenger.c +19 -1
@@ -557,7 +557,7 @@ static int ceph_tcp_sendmsg(struct socket *sock, struct kvec *iov,return r; } -static int ceph_tcp_sendpage (struct socket *sock,struct page *page, +static int __ceph_tcp_sendpage (struct socket *sock,struct page *page,int offset,size_t size,bool more) {int flags =MSG_DONTWAIT |MSG_NOSIGNAL | (more ?MSG_MORE :MSG_EOR );
@@ -570,6 +570,24 @@ static int ceph_tcp_sendpage(struct socket *sock, struct page *page,return ret; } +static int ceph_tcp_sendpage (struct socket *sock,struct page *page, +int offset,size_t size,bool more) +{ +int ret; +struct kvec iov; + +/* sendpage cannot properly handle pages with page_count == 0, +* we need to fallback to sendmsg if that's the case */ +if (page_count (page) >=1 ) +return __ceph_tcp_sendpage (sock, page, offset, size, more); + + iov.iov_base =kmap (page) + offset; + iov.iov_len = size; + ret =ceph_tcp_sendmsg (sock, &iov,1 , size, more); +kunmap (page); + +return ret; +}/* * Shutdown/close the socket for the given connection.
Signature · 1 line
1.8.5.2
Quoted 48 lines · Chunwei Chen
It has been reported that using ZFSonLinux on rbd will result in memory corruption. The bug report can be found here:
https://github.com/zfsonlinux/spl/issues/241
http://tracker.ceph.com/issues/7790The reason is that ZFS will send pages with
page_count0 into rbd, which in turns send them totcp_sendpage. However,tcp_sendpagecannot deal withpage_count0, as it will doget_pageandput_page, and erroneously free the page.This type of issue has been noted before, and handled in iscsi, drbd, etc. So, rbd should also handle this. This fix address this issue by fall back to slower sendmsg when
page_count0 detected.Cc Sage Weil <[email protected]>Cc Yehuda Sadeh <[email protected]>Signed-off-by Chunwei Chen <[email protected]>--- net/ceph/messenger.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)net/ceph/messenger.c +9
-1@@ -557,7 +557,7 @@ static int ceph_tcp_sendmsg(struct socket *sock, struct kvec *iov,return r; } -static int ceph_tcp_sendpage (struct socket *sock,struct page *page, +static int __ceph_tcp_sendpage (struct socket *sock,struct page *page,int offset,size_t size,bool more) {int flags =MSG_DONTWAIT |MSG_NOSIGNAL | (more ?MSG_MORE :MSG_EOR );@@ -570,6 +570,24 @@ static int ceph_tcp_sendpage(struct socket *sock, struct page *page,return ret; } +static int ceph_tcp_sendpage (struct socket *sock,struct page *page, +int offset,size_t size,bool more) +{ +int ret; +struct kvec iov; + +/* sendpage cannot properly handle pages with page_count == 0, +* we need to fallback to sendmsg if that's the case */
net/ceph/messenger.c static int ceph_tcp_sendpage(struct socket *sock, struct page *page, · line 590
Quoted 10 lines
net/ceph/messenger.c +10
-0+if (page_count (page) >=1 ) +return __ceph_tcp_sendpage (sock, page, offset, size, more); + + iov.iov_base =kmap (page) + offset; + iov.iov_len = size; + ret =ceph_tcp_sendmsg (sock, &iov,1 , size, more); +kunmap (page); + +return ret; +}
Looks good to me. Have you tested it with pre "Fix crash when using ZFS on Ceph rbd" ZFS?
Thanks,
Ilya
Quoted 54 lines · Ilya Dryomov
Quoted 53 lines · Chunwei Chen
It has been reported that using ZFSonLinux on rbd will result in memory corruption. The bug report can be found here:
https://github.com/zfsonlinux/spl/issues/241
http://tracker.ceph.com/issues/7790The reason is that ZFS will send pages with
page_count0 into rbd, which in turns send them totcp_sendpage. However,tcp_sendpagecannot deal withpage_count0, as it will doget_pageandput_page, and erroneously free the page.This type of issue has been noted before, and handled in iscsi, drbd, etc. So, rbd should also handle this. This fix address this issue by fall back to slower sendmsg when
page_count0 detected.Cc Sage Weil <[email protected]>Cc Yehuda Sadeh <[email protected]>Signed-off-by Chunwei Chen <[email protected]>--- net/ceph/messenger.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)net/ceph/messenger.c +14
-1@@ -557,7 +557,7 @@ static int ceph_tcp_sendmsg(struct socket *sock, struct kvec *iov,return r; } -static int ceph_tcp_sendpage (struct socket *sock,struct page *page, +static int __ceph_tcp_sendpage (struct socket *sock,struct page *page,int offset,size_t size,bool more) {int flags =MSG_DONTWAIT |MSG_NOSIGNAL | (more ?MSG_MORE :MSG_EOR );@@ -570,6 +570,24 @@ static int ceph_tcp_sendpage(struct socket *sock, struct page *page,return ret; } +static int ceph_tcp_sendpage (struct socket *sock,struct page *page, +int offset,size_t size,bool more) +{ +int ret; +struct kvec iov; + +/* sendpage cannot properly handle pages with page_count == 0, +* we need to fallback to sendmsg if that's the case */ +if (page_count (page) >=1 ) +return __ceph_tcp_sendpage (sock, page, offset, size, more); + + iov.iov_base =kmap (page) + offset; + iov.iov_len = size;
Quoted 8 lines
net/ceph/messenger.c static int ceph_tcp_sendpage(struct socket *sock, struct page *page, · line 590
Quoted 5 lines
net/ceph/messenger.c +5
-0+ ret =ceph_tcp_sendmsg (sock, &iov,1 , size, more); +kunmap (page); + +return ret; +}Looks good to me. Have you tested it with pre "Fix crash when using ZFS on Ceph rbd" ZFS?
Once this looks ready, we should perhaps stick it in for-linus so that it can go into 3.15.
sage
Quoted 64 lines · Sage Weil
Quoted 54 lines · Ilya Dryomov
Quoted 53 lines · Chunwei Chen
It has been reported that using ZFSonLinux on rbd will result in memory corruption. The bug report can be found here:
https://github.com/zfsonlinux/spl/issues/241
http://tracker.ceph.com/issues/7790The reason is that ZFS will send pages with
page_count0 into rbd, which in turns send them totcp_sendpage. However,tcp_sendpagecannot deal withpage_count0, as it will doget_pageandput_page, and erroneously free the page.This type of issue has been noted before, and handled in iscsi, drbd, etc. So, rbd should also handle this. This fix address this issue by fall back to slower sendmsg when
page_count0 detected.Cc Sage Weil <[email protected]>Cc Yehuda Sadeh <[email protected]>Signed-off-by Chunwei Chen <[email protected]>--- net/ceph/messenger.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)net/ceph/messenger.c +14
-1@@ -557,7 +557,7 @@ static int ceph_tcp_sendmsg(struct socket *sock, struct kvec *iov,return r; } -static int ceph_tcp_sendpage (struct socket *sock,struct page *page, +static int __ceph_tcp_sendpage (struct socket *sock,struct page *page,int offset,size_t size,bool more) {int flags =MSG_DONTWAIT |MSG_NOSIGNAL | (more ?MSG_MORE :MSG_EOR );@@ -570,6 +570,24 @@ static int ceph_tcp_sendpage(struct socket *sock, struct page *page,return ret; } +static int ceph_tcp_sendpage (struct socket *sock,struct page *page, +int offset,size_t size,bool more) +{ +int ret; +struct kvec iov; + +/* sendpage cannot properly handle pages with page_count == 0, +* we need to fallback to sendmsg if that's the case */ +if (page_count (page) >=1 ) +return __ceph_tcp_sendpage (sock, page, offset, size, more); + + iov.iov_base =kmap (page) + offset; + iov.iov_len = size;Quoted 8 lines
net/ceph/messenger.c static int ceph_tcp_sendpage(struct socket *sock, struct page *page, · line 590
Quoted 5 lines
net/ceph/messenger.c +5
-0+ ret =ceph_tcp_sendmsg (sock, &iov,1 , size, more); +kunmap (page); + +return ret; +}Looks good to me. Have you tested it with pre "Fix crash when using ZFS on Ceph rbd" ZFS?
Quoted 2 lines
Once this looks ready, we should perhaps stick it in for-linus so that it can go into 3.15.
That's the plan, I just wanted to confirm it's been tested, since ZFS folks went ahead and fixed it by using compound pages.
Thanks,
Ilya
Quoted 9 lines · Ilya Dryomov
Quoted 7 lines · Sage Weil
Quoted 3 lines · Ilya Dryomov
Looks good to me. Have you tested it with pre "Fix crash when using ZFS on Ceph rbd" ZFS?
Once this looks ready, we should perhaps stick it in for-linus so that it can go into 3.15.
Quoted 7 lines
That's the plan, I just wanted to confirm it's been tested, since ZFS folks went ahead and fixed it by using compound pages.
Thanks,
Ilya
Hi Ilya
Yes, I've tested before the ZFS fix and it worked for me.
Thanks,
Chunwei Chen
Quoted 15 lines · tuxoko
Quoted 12 lines · Ilya Dryomov
Quoted 7 lines · Sage Weil
Quoted 3 lines · Ilya Dryomov
Looks good to me. Have you tested it with pre "Fix crash when using ZFS on Ceph rbd" ZFS?
Once this looks ready, we should perhaps stick it in for-linus so that it can go into 3.15.
That's the plan, I just wanted to confirm it's been tested, since ZFS folks went ahead and fixed it by using compound pages.
Quoted 8 lines
Quoted 4 lines
Thanks,
Ilya
Hi Ilya
Yes, I've tested before the ZFS fix and it worked for me.
Thanks, queued.
Ilya
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html