xfs: logsunit rounding causes iclog corruption/crash
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 xfs: logsunit rounding causes iclog corruption/crash
When the iclog buffer size and log stripe unit are both defined and the log stripe unit is less the log buffer size then the buffer is rounded up to the log stripe unit size during the xlog_sync().
This rounding can exceed the iclog buffer length and in xlog_data_pack():
1) Cause corruption inside the iclog buffer because there will not be enough space for the headers in the front of the iclog buffer for the rounding.
2) Cause corruption in memory that follows the iclog buffer when stamping the lsn in each of the rounded blocks.
3) If CONFIG_XFS_DEBUG is defined will cause a crash in xlog_verify_iclog().
4) Cause page fault crash if the memory after the buffer is not mapped.
This has been found in XFS versions at least as far back as Linux 2.6.32.
This patch forces the iclog buffer to be a multiple of the log stripe unit when they are both defined.
Example:
# mkfs.xfs -l su=192k -f /dev/sda2
# mount -o logbsize=256k /dev/sda3 /scratch
# io such as fsstress in /scratch will immediately crash a debug xfs
kernel and most like a non-debug xfs kernel.--- fs/xfs/xfs_super.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
fs/xfs/xfs_super.c +16 -4
@@ -1357,11 +1357,23 @@ xfs_finish_flags(if (mp->m_logbsize <=0 && mp->m_sb.sb_logsunit >XLOG_BIG_RECORD_BSIZE ) { mp->m_logbsize = mp->m_sb.sb_logsunit; - }else if (mp->m_logbsize >0 && - mp->m_logbsize < mp->m_sb.sb_logsunit) { -xfs_warn (mp, + }else if (mp->m_logbsize >0 ) { +if (mp->m_logbsize > mp->m_sb.sb_logsunit) { +int logbsize; +/* round up to the next multiple of logsunit */ + logbsize =roundup (mp->m_logbsize, + mp->m_sb.sb_logsunit); +if (logbsize >XLOG_MAX_RECORD_BSIZE ) +/* buffer size too large. round down. */ + logbsize -= mp->m_sb.sb_logsunit; +xfs_warn (mp,"log bufsize rounded from %d to %d" , + mp->m_logbsize, logbsize); + mp->m_logbsize = logbsize; + }else if (mp->m_logbsize < mp->m_sb.sb_logsunit) { +xfs_warn (mp,"logbuf size must be greater than or equal to log stripe size" ); -return XFS_ERROR (EINVAL ); +return XFS_ERROR (EINVAL ); + } } }else {/* Fail a mount if the logbuf is larger than 32K */
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 13 lines · Mark Tinguely
When the iclog buffer size and log stripe unit are both defined and the log stripe unit is less the log buffer size then the buffer is rounded up to the log stripe unit size during the
xlog_sync().This rounding can exceed the iclog buffer length and in
xlog_data_pack():
1) Cause corruption inside the iclog buffer because there will not be enough space for the headers in the front of the iclog buffer for the rounding.
2) Cause corruption in memory that follows the iclog buffer when stamping the lsn in each of the rounded blocks.
3) IfCONFIG_XFS_DEBUGis defined will cause a crash inxlog_verify_iclog().
4) Cause page fault crash if the memory after the buffer is not mapped.
Quoted 8 lines
This has been found in XFS versions at least as far back as Linux 2.6.32.
This patch forces the iclog buffer to be a multiple of the log stripe unit when they are both defined.
Example:
# mkfs.xfs -l su=192k -f /dev/sda2
$ sudo mkfs.xfs -l sunit=192k /dev/vdb Specify log sunit in 512-byte blocks, no size suffix .... $
Quoted 3 lines
# mount -o logbsize=256k /dev/sda3 /scratch
# io such as fsstress in /scratch will immediately crash a debug xfs
kernel and most like a non-debug xfs kernel.It's definitely not an immediate crash. xfstests runs for several minutes (including through fsstress workloads) before it finally falls over. I'd suggest a targetted xfstest is needed for this...
Quoted 19 lines
Index:
b/fs/xfs/xfs_super.c
===================================================================fs/xfs/xfs_super.c +8
-3@@ -1357,11 +1357,23 @@ xfs_finish_flags(if (mp->m_logbsize <=0 && mp->m_sb.sb_logsunit >XLOG_BIG_RECORD_BSIZE ) { mp->m_logbsize = mp->m_sb.sb_logsunit; - }else if (mp->m_logbsize >0 && - mp->m_logbsize < mp->m_sb.sb_logsunit) { - xfs_warn(mp, + }else if (mp->m_logbsize >0 ) { +if (mp->m_logbsize > mp->m_sb.sb_logsunit) { +int logbsize; +/* round up to the next multiple of logsunit */ + logbsize =roundup (mp->m_logbsize, + mp->m_sb.sb_logsunit); +if (logbsize >XLOG_MAX_RECORD_BSIZE ) +/* buffer size too large. round down. */
fs/xfs/xfs_super.c xfs_finish_flags( · line 1376
Quoted 10 lines
fs/xfs/xfs_super.c +8
-1+ logbsize -= mp->m_sb.sb_logsunit; +xfs_warn (mp,"log bufsize rounded from %d to %d" , + mp->m_logbsize, logbsize); + mp->m_logbsize = logbsize; + }else if (mp->m_logbsize < mp->m_sb.sb_logsunit) { +xfs_warn (mp,"logbuf size must be greater than or equal to log stripe size" ); -return XFS_ERROR (EINVAL ); +return XFS_ERROR (EINVAL ); + }
If the user has specified an invalid log buffer size, then reject it with:
logbsize XXX is not an integer multiple of the log stripe unit YYY
Rounding means that the user isn't getting what they want and they may not realise it. If they make a mistake, they should be informed and forced to fix it before going any further.
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 48 lines · Dave Chinner
Quoted 13 lines · Mark Tinguely
When the iclog buffer size and log stripe unit are both defined and the log stripe unit is less the log buffer size then the buffer is rounded up to the log stripe unit size during the
xlog_sync().This rounding can exceed the iclog buffer length and in
xlog_data_pack():
1) Cause corruption inside the iclog buffer because there will not be enough space for the headers in the front of the iclog buffer for the rounding.
2) Cause corruption in memory that follows the iclog buffer when stamping the lsn in each of the rounded blocks.
3) IfCONFIG_XFS_DEBUGis defined will cause a crash inxlog_verify_iclog().
4) Cause page fault crash if the memory after the buffer is not mapped.Quoted 8 lines
This has been found in XFS versions at least as far back as Linux 2.6.32.
This patch forces the iclog buffer to be a multiple of the log stripe unit when they are both defined.
Example:
# mkfs.xfs -l su=192k -f /dev/sda2$ sudo mkfs.xfs -l sunit=192k /dev/vdb Specify log sunit in 512-byte blocks, no size suffix .... $Quoted 3 lines
# mount -o logbsize=256k /dev/sda3 /scratch # io such as fsstress in /scratch will immediately crash a debug xfs kernel and most like a non-debug xfs kernel.It's definitely not an immediate crash. xfstests runs for several minutes (including through fsstress workloads) before it finally falls over. I'd suggest a targetted xfstest is needed for this...
Quoted 12 lines
Index:
b/fs/xfs/xfs_super.c
===================================================================fs/xfs/xfs_super.c +1
-3@@ -1357,11 +1357,23 @@ xfs_finish_flags(if (mp->m_logbsize<=0 && mp->m_sb.sb_logsunit>XLOG_BIG_RECORD_BSIZE ) { mp->m_logbsize = mp->m_sb.sb_logsunit; - }else if (mp->m_logbsize>0 && - mp->m_logbsize< mp->m_sb.sb_logsunit) { - xfs_warn(mp, + }else if (mp->m_logbsize>0 ) {
Quoted 8 lines
fs/xfs/xfs_super.c xfs_finish_flags( · line 1368
Quoted 8 lines
fs/xfs/xfs_super.c +8
-0+if (mp->m_logbsize> mp->m_sb.sb_logsunit) { +int logbsize; +/* round up to the next multiple of logsunit */ + logbsize =roundup (mp->m_logbsize, + mp->m_sb.sb_logsunit); +if (logbsize>XLOG_MAX_RECORD_BSIZE ) +/* buffer size too large. round down. */ + logbsize -= mp->m_sb.sb_logsunit;
eeks:
if (logbsize != mp->m_logbsize) {Quoted 3 lines
fs/xfs/xfs_super.c xfs_finish_flags( · line 1371
Quoted 3 lines
fs/xfs/xfs_super.c +3
-0+xfs_warn (mp,"log bufsize rounded from %d to %d" , + mp->m_logbsize, logbsize); + mp->m_logbsize = logbsize;
}
Quoted 12 lines
fs/xfs/xfs_super.c xfs_finish_flags( · line 1376
Quoted 6 lines
fs/xfs/xfs_super.c +4
-1+ }else if (mp->m_logbsize< mp->m_sb.sb_logsunit) { +xfs_warn (mp,"logbuf size must be greater than or equal to log stripe size" ); -return XFS_ERROR (EINVAL ); +return XFS_ERROR (EINVAL ); + }If the user has specified an invalid log buffer size, then reject it with:
logbsize XXX is not an integer multiple of the log stripe unit YYY
Quoted 7 lines
Rounding means that the user isn't getting what they want and they may not realise it. If they make a mistake, they should be informed and forced to fix it before going any further.
Cheers,
Dave.
The code already silently changes the log blocksize if mp->m_sb.sb_logsunit > mp->m_logbsize.
IMO, it should fix it not a multiple too.
--Mark.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 14 lines · Mark Tinguely
Quoted 13 lines · Dave Chinner
Quoted 12 lines · Mark Tinguely
When the iclog buffer size and log stripe unit are both defined and the log stripe unit is less the log buffer size then the buffer is rounded up to the log stripe unit size during the
xlog_sync().This rounding can exceed the iclog buffer length and in
xlog_data_pack():
1) Cause corruption inside the iclog buffer because there will not be enough space for the headers in the front of the iclog buffer for the rounding.
2) Cause corruption in memory that follows the iclog buffer when stamping the lsn in each of the rounded blocks.
3) IfCONFIG_XFS_DEBUGis defined will cause a crash inxlog_verify_iclog().
4) Cause page fault crash if the memory after the buffer is not mapped.
...
Quoted 11 lines
Quoted 8 lines
If the user has specified an invalid log buffer size, then reject it with:
logbsize XXX is not an integer multiple of the log stripe unit YYY
Rounding means that the user isn't getting what they want and they may not realise it. If they make a mistake, they should be informed and forced to fix it before going any further.
The code already silently changes the log blocksize if
mp->m_sb.sb_logsunit>mp->m_logbsize.
Where? It only changes m_logbsize if it is <= 0, which means the user has not specified the value as a mount option and hence we are free to chose whatever value we want.
Quoted 1 line
IMO, it should fix it not a multiple too.
ENOPARSE. :/
FWIW, a further argument against the rounding approach is this: the iclogbuf size supplied to mount is constrainted to be a power of 2 size.
if (mp->m_logbsize != -1 &&
mp->m_logbsize != 0 &&
(mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
!is_power_of_2(mp->m_logbsize))) {
xfs_warn(mp,
"invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
mp->m_logbsize);
return XFS_ERROR(EINVAL);
}This constraint appears to be a feature of the original log stripe unit code that did only support power-of-2 log stripe units. However, that was removed way back in 2004:
That commit introduced the very rounding code in xlog_sync() that is causing the crash you are trying to address right now. i.e. this code:
count = XLOG_LSUNITTOB(log, XLOG_BTOLSUNIT(log, count_init));
IOWs, it makes no sense to only allow power-of-2 logbsize options if we then round it to something completely different. The above commit makes it pretty clear that the intent is that logbsize should be an exact integer multiple of the log stripe unit - which it is if no logbsize mount option is given - but our mount option parsing does not reflect this at all.
Personally, I'd prefer that logbsize be limited to power-of-2 multiples of the lsunit or XLOG_MIN_RECORD_BSIZE (if lsunit = 0) as allowing arbitrary values to be specified by users leads to a testing and bug triage nightmare.
If we are not going to change the power-of-2 logbsize mount option requirement, then I think that the correct solution is to make the log limit the iclogbuf size internally to power-of-2 multiples of the lsunit so that it is not at all externally visible (e.g. /proc/self/mounts shows exactly what came in as a mount option). This problem really has nothing to do with what mount options are specified and passed to the log - the log is separate code with it's own internal constraints and hence should be ensuring that it's setup is consistent with those constraints....
Further, if we really need to know what iclogbuf size the log is using on disk, both the physical iclogbuf size and the size of the current write gets written into every log header block....
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs