Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: session_manager_service.cc

Issue 3493012: Security patches: RestartJob ignores pid, argv[0]; kill runs as child UID (Closed) Base URL: http://git.chromium.org/git/login_manager.git
Patch Set: added comments, using -1 as suid in setresuid() calls Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mock_system_utils.h ('k') | session_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "login_manager/session_manager_service.h" 5 #include "login_manager/session_manager_service.h"
6 6
7 #include <dbus/dbus-glib-lowlevel.h> 7 #include <dbus/dbus-glib-lowlevel.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <glib.h> 9 #include <glib.h>
10 #include <grp.h> 10 #include <grp.h>
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 return TRUE; 636 return TRUE;
637 } 637 }
638 638
639 gboolean SessionManagerService::RestartJob(gint pid, 639 gboolean SessionManagerService::RestartJob(gint pid,
640 gchar* arguments, 640 gchar* arguments,
641 gboolean* OUT_done, 641 gboolean* OUT_done,
642 GError** error) { 642 GError** error) {
643 int child_pid = pid; 643 int child_pid = pid;
644 std::vector<int>::iterator child_pid_it = 644 std::vector<int>::iterator child_pid_it =
645 std::find(child_pids_.begin(), child_pids_.end(), child_pid); 645 std::find(child_pids_.begin(), child_pids_.end(), child_pid);
646 if (child_pid_it == child_pids_.end()) { 646 size_t child_index = child_pid_it - child_pids_.begin();
647
648 if (child_pid_it == child_pids_.end() ||
649 child_jobs_[child_index]->GetName() != "chrome") {
650 // If we didn't find the pid, or we don't think that job was chrome...
647 *OUT_done = FALSE; 651 *OUT_done = FALSE;
648 SetGError(error, 652 SetGError(error,
649 CHROMEOS_LOGIN_ERROR_UNKNOWN_PID, 653 CHROMEOS_LOGIN_ERROR_UNKNOWN_PID,
650 "Provided pid is unknown."); 654 "Provided pid is unknown.");
651 return FALSE; 655 return FALSE;
652 } 656 }
653 657
654 // Waiting for Chrome to shutdown takes too much time. 658 // Waiting for Chrome to shutdown takes too much time.
655 // We're killing it immediately hoping that data Chrome uses before 659 // We're killing it immediately hoping that data Chrome uses before
656 // logging in is not corrupted. 660 // logging in is not corrupted.
657 // TODO(avayvod): Remove RestartJob when crosbug.com/6924 is fixed. 661 // TODO(avayvod): Remove RestartJob when crosbug.com/6924 is fixed.
658 system_->kill(-child_pid, SIGKILL); 662 uid_t to_kill_as = getuid();
663 if (child_jobs_[child_index]->IsDesiredUidSet())
664 to_kill_as = child_jobs_[child_index]->GetDesiredUid();
665 system_->kill(-child_pid, to_kill_as, SIGKILL);
659 666
660 char arguments_buffer[kMaxArgumentsSize + 1]; 667 char arguments_buffer[kMaxArgumentsSize + 1];
661 snprintf(arguments_buffer, sizeof(arguments_buffer), "%s", arguments); 668 snprintf(arguments_buffer, sizeof(arguments_buffer), "%s", arguments);
662 arguments_buffer[kMaxArgumentsSize] = '\0'; 669 arguments_buffer[kMaxArgumentsSize] = '\0';
663 string arguments_string(arguments_buffer); 670 string arguments_string(arguments_buffer);
664 671
665 size_t child_index = child_pid_it - child_pids_.begin();
666 child_jobs_[child_index]->SetArguments(arguments_string); 672 child_jobs_[child_index]->SetArguments(arguments_string);
667 child_pids_[child_index] = RunChild(child_jobs_[child_index]); 673 child_pids_[child_index] = RunChild(child_jobs_[child_index]);
668 674
669 // To set "logged-in" state for BWSI mode. 675 // To set "logged-in" state for BWSI mode.
670 return StartSession(const_cast<gchar*>(kIncognitoUser), NULL, 676 return StartSession(const_cast<gchar*>(kIncognitoUser), NULL,
671 OUT_done, error); 677 OUT_done, error);
672 } 678 }
673 679
674 /////////////////////////////////////////////////////////////////////////////// 680 ///////////////////////////////////////////////////////////////////////////////
675 // glib event handlers 681 // glib event handlers
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 // And SIGHUP, for when the terminal disappears. On shutdown, many Linux 834 // And SIGHUP, for when the terminal disappears. On shutdown, many Linux
829 // distros send SIGHUP, SIGTERM, and then SIGKILL. 835 // distros send SIGHUP, SIGTERM, and then SIGKILL.
830 action.sa_handler = SIGHUPHandler; 836 action.sa_handler = SIGHUPHandler;
831 CHECK(sigaction(SIGHUP, &action, NULL) == 0); 837 CHECK(sigaction(SIGHUP, &action, NULL) == 0);
832 } 838 }
833 839
834 void SessionManagerService::CleanupChildren(int timeout) { 840 void SessionManagerService::CleanupChildren(int timeout) {
835 for (size_t i_child = 0; i_child < child_pids_.size(); ++i_child) { 841 for (size_t i_child = 0; i_child < child_pids_.size(); ++i_child) {
836 int child_pid = child_pids_[i_child]; 842 int child_pid = child_pids_[i_child];
837 if (child_pid > 0) { 843 if (child_pid > 0) {
838 system_->kill(child_pid, (session_started_ ? SIGTERM: SIGKILL)); 844 uid_t uid = getuid();
845 if (child_jobs_[i_child]->IsDesiredUidSet())
846 uid = child_jobs_[i_child]->GetDesiredUid();
847
848 system_->kill(child_pid, uid, (session_started_ ? SIGTERM: SIGKILL));
839 if (!system_->ChildIsGone(child_pid, timeout)) 849 if (!system_->ChildIsGone(child_pid, timeout))
840 system_->kill(child_pid, SIGABRT); 850 system_->kill(child_pid, uid, SIGABRT);
841 } 851 }
842 } 852 }
843 } 853 }
844 854
845 void SessionManagerService::SetGError(GError** error, 855 void SessionManagerService::SetGError(GError** error,
846 ChromeOSLoginError code, 856 ChromeOSLoginError code,
847 const char* message) { 857 const char* message) {
848 g_set_error(error, CHROMEOS_LOGIN_ERROR, code, "Login error: %s", message); 858 g_set_error(error, CHROMEOS_LOGIN_ERROR, code, "Login error: %s", message);
849 } 859 }
850 860
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 arg_list.push_back(args[i_arg]); 895 arg_list.push_back(args[i_arg]);
886 } 896 }
887 } 897 }
888 if (arg_list.size()) { 898 if (arg_list.size()) {
889 arg_lists.push_back(arg_list); 899 arg_lists.push_back(arg_list);
890 } 900 }
891 return arg_lists; 901 return arg_lists;
892 } 902 }
893 903
894 } // namespace login_manager 904 } // namespace login_manager
OLDNEW
« no previous file with comments | « mock_system_utils.h ('k') | session_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698