Bug #49680 The backup_interruption test fails on some platforms due to permission problems
Submitted: 14 Dec 2009 16:35 Modified: 3 Mar 2010 2:14
Reporter: Chuck Bell Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Backup Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: Chuck Bell CPU Architecture:Any

[14 Dec 2009 16:35] Chuck Bell
Description:
The test backup_interruption is failing on some Linux systems in pushbuild on mysql-6.0-backup due to this error:

CURRENT_TEST: backup_engines.backup_interruption
mysqltest: In included file "./suite/backup_engines/include/backup_restore_interrupt.inc": At line 102: query 'SELECT object, error_num, notes FROM mysql.backup_progress' failed: 1142: SELECT command denied to user 'root'@'localhost' for table 'backup_progress'

However, it is clear from the message we are running and connected as root who should have unrestricted access to the table cited. 

There are a number of debug synch sequences in the test which repeatedly calls the backup_restore_interrupt.inc file. The error occurs only for the following debug synch sequences. All others have been verified to work correctly without errors.

# at the very beginning		
let $sync_point= before_backup_command;
--source suite/backup_engines/include/backup_restore_interrupt.inc

# before preparations
let $sync_point= before_backup_prepare;
--source suite/backup_engines/include/backup_restore_interrupt.inc

# during preparations
  # before logger initialization
  let $sync_point= before_backup_logger_init;
  --source suite/backup_engines/include/backup_restore_interrupt.inc

An analysis shows when the backup is interrupted, the restore_global_privileges() method is called but it should not have been called since the matching save_global_privileges() method was never called because the thread was killed before the code that calls the method was executed.

Therefore, on the platforms that the test is failing, the value of the saved privileges is being used -- which could be undefined and in this case corrupts the users' global privileges. 

Note: A disconnect/connect has been confirmed to restore the privileges.

How to repeat:
./mysql-test-run.pl backup_interruption 

Suggested fix:
The Backup_restore_ctx::close() method does not properly check to see if the thread was killed before issuing the restore_global_privileges() call. However, since we do not know if the save_global_privileges() method was called first, we must either remember that we have and call the companion method or make the pair of methods call safe.

Thus, there are two options.

a) add this to the kernel.cc code

  /*
    Restore privilege information.
  */
  if (!m_thd->killed)
    m_thd->security_ctx->restore_global_privileges();

b) make the methods for save/restore call safe by initializing the variable to 0 and checking to see if it has been set (saved) before resetting (restoring) it.
[14 Dec 2009 16:44] Chuck Bell
I've decided to implement option (b) as it is the safer option.
[14 Dec 2009 16:49] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/93952

2909 Chuck Bell	2009-12-14
      BUG#49680 : The backup_interruption test fails on some platforms due 
                  to permission problems
      
      The Backup_restore_ctx::close() method does not properly check to see 
      if the thread was killed before issuing the restore_global_privileges() 
      call.
      
      This patch makes the restore_global_privileges() method call safe by
      initializing the saved variable to 0 and checking to see if the
      variable is set before restoring global privileges.
      
      This patch fixes the backup_interruption test failures on pushbuild
      hence no additional tests are necesarry as this test ensure the
      condition where restore_global_privileges() is called without calling
      save_global_privileges() first.
     @ sql/sql_class.cc
        Checks to see if variable is set before restoring privileges.
     @ sql/sql_class.h
        Initializes saved privileges variable.
[14 Dec 2009 20:40] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/93986

2909 Chuck Bell	2009-12-14
      BUG#49680 : The backup_interruption test fails on some platforms due 
                  to permission problems
      
      The Backup_restore_ctx::close() method does not properly check to see 
      if the thread was killed before issuing the restore_global_privileges() 
      call.
      
      This patch makes the restore_global_privileges() method call safe by
      using a variable to ensure the save was called before restoring global 
      privileges.
      
      This patch fixes the backup_interruption test failures on pushbuild
      hence no additional tests are necesarry as this test ensure the
      condition where restore_global_privileges() is called without calling
      save_global_privileges() first.
     @ sql/sql_class.cc
        Checks to see if variable is set before restoring privileges.
     @ sql/sql_class.h
        Initializes saved privileges variable.
[15 Dec 2009 6:50] Rafal Somla
Good to push.
[15 Dec 2009 7:56] Thava Alagu
Looks good to push.
[15 Dec 2009 19:56] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/94262

2910 Chuck Bell	2009-12-15
      BUG#49680 : The backup_interruption test fails on some platforms due 
                  to permission problems
      
      The Backup_restore_ctx::close() method does not properly check to see 
      if the thread was killed before issuing the restore_global_privileges() 
      call.
      
      This patch makes the restore_global_privileges() method call safe by
      using a variable to ensure the save was called before restoring global 
      privileges.
      
      This patch fixes the backup_interruption test failures on pushbuild
      hence no additional tests are necesarry as this test ensure the
      condition where restore_global_privileges() is called without calling
      save_global_privileges() first.
     @ sql/sql_class.cc
        Checks to see if variable is set before restoring privileges.
     @ sql/sql_class.h
        Initializes saved privileges variable.
[15 Dec 2009 20:16] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/94266

2910 Chuck Bell	2009-12-15
      BUG#49680 : The backup_interruption test fails on some platforms due 
                  to permission problems
      
      The Backup_restore_ctx::close() method does not properly check to see 
      if the thread was killed before issuing the restore_global_privileges() 
      call.
      
      This patch makes the restore_global_privileges() method call safe by
      using a variable to ensure the save was called before restoring global 
      privileges.
      
      This patch fixes the backup_interruption test failures on pushbuild
      hence no additional tests are necesarry as this test ensure the
      condition where restore_global_privileges() is called without calling
      save_global_privileges() first.
     @ sql/sql_class.cc
        Checks to see if variable is set before restoring privileges.
     @ sql/sql_class.h
        Initializes saved privileges variable.
[8 Jan 2010 21:45] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/96442

3047 Chuck Bell	2010-01-08
      BUG#49680 : The backup_interruption test fails on some platforms due 
                  to permission problems
      
      The Backup_restore_ctx::close() method does not properly check to see 
      if the thread was killed before issuing the restore_global_privileges() 
      call.
      
      original changeset: 2910 (mysql-6.0-backup)
[20 Feb 2010 9:19] Bugs System
Pushed into 6.0.14-alpha (revid:ingo.struewing@sun.com-20100218152520-s4v1ld76bif06eqn) (version source revid:ingo.struewing@sun.com-20100119103538-wtp5alpz4p2jayl5) (merge vers: 6.0.14-alpha) (pib:16)
[3 Mar 2010 2:14] Paul DuBois
Noted in 6.0.14 changelog.

MySQL Backup code could fail due to improper thread handling.