New issue
Advanced search Search tips

Issue 616962 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: Dec 2016
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux
Pri: 3
Type: Bug



Sign in to add a comment

[remoting host] Virtual Me2Me sessions should be created from PAM (pam_open_session).

Project Member Reported by lambroslambrou@chromium.org, Jun 2 2016

Issue description

The init.d script currently uses 'sudo -i' to create the per-user session.
This creates sessions with an incorrect PAM configuration that are not properly registered as logind sessions.
Instead, we should create the sessions via pam_open_session.

The following information was provided to us:

I looked over /opt/google/chrome-remote-desktop/chrome-remote-desktop, and I think adding a flag like "--drop-privs=${USER}" or "--run-as=${USER}" is the right way to go. That binary would be run as root from the init script *without sudo* and with the flag. Then after the call to daemonize(), it would need to call something like the following run_as(username) function when the flag is set:

import pwd
import os
import PAM

def run_as(username):
  user = pwd.getpwnam(username)
  pamh = PAM.pam()
  pamh.start("chrome-remote-desktop", user.pw_name)
  pamh.open_session()
  pamh.acct_mgmt(PAM.PAM_SILENT)
  pamh.setcred(PAM.PAM_ESTABLISH_CRED | PAM.PAM_SILENT)
  pamh.open_session(PAM.PAM_SILENT) # The really important call.
  use_env = dict(v.split('=', 1) for v in pamh.getenvlist() if '=' in v)
  pid = os.fork():
  if pid == 0:
    # Child process that will continue to run as "username".
    os.setgid(user.pw_gid)
    os.initgroups(user.pw_name, user.pw_gid)
    os.setuid(user.pw_uid)
    for key, value in use_env.iteritems():
      os.putenv(key, value)
    return  # Keep running the rest of the program as the user.
  status = os.waitpid(pid, 0)
  pamh.setcred(PAM.PAM_DELETE_CRED | PAM.PAM_SILENT)
  pamh.close_session()
  if os.WIFEXITED(status):
    os._exit(os.WEXITSTATUS(status))
  else:
    ...print some warning?...
    os._exit(1)

 
Owner: rkjnsn@chromium.org
Status: Assigned (was: Untriaged)
Project Member

Comment 3 by bugdroid1@chromium.org, Nov 23 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/376920771f3df23499f30070f1ce9c2dc7c1a188

commit 376920771f3df23499f30070f1ce9c2dc7c1a188
Author: lukasza <lukasza@chromium.org>
Date: Wed Nov 23 19:15:15 2016

Revert of Add PAM session wrapper (patchset #5 id:100001 of https://codereview.chromium.org/2323153002/ )

Reason for revert:
This CL seems to have broken the build - see https://uberchromegw.corp.google.com/i/official.desktop.continuous/builders/precise64%20trunk/builds/20292/steps/compile/logs/stdio :

[4004/46998] CXX obj/remoting/host/linux/remoting_user_session/remoting_user_session.o
FAILED: obj/remoting/host/linux/remoting_user_session/remoting_user_session.o
../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/remoting/host/linux/remoting_user_session/remoting_user_session.o.d -DV8_DEPRECATION_WARNINGS -DENABLE_NOTIFICATIONS -DENABLE_PDF=1 -DUSE_UDEV -DUI_COMPOSITOR_IMAGE_TRANSPORT -DUSE_AURA=1 -DUSE_PANGO=1 -DUSE_CAIRO=1 -DUSE_GLIB=1 -DUSE_NSS_CERTS=1 -DUSE_X11=1 -DENABLE_TASK_MANAGER=1 -DENABLE_THEMES=1 -DUSE_PROPRIETARY_CODECS -DFULL_SAFE_BROWSING -DSAFE_BROWSING_CSD -DSAFE_BROWSING_DB_LOCAL -DOFFICIAL_BUILD -DGOOGLE_CHROME_BUILD -DENABLE_MEDIA_ROUTER=1 -DCR_CLANG_REVISION=287685-1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -DNO_UNWIND_TABLES -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 -DCFI_ENFORCEMENT -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -I../.. -Igen -I../../build/linux/debian_wheezy_amd64-sysroot/usr/include/glib-2.0 -I../../build/linux/debian_wheezy_amd64-sysroot/usr/lib/x86_64-linux-gnu/glib-2.0/include -fno-strict-aliasing --param=ssp-buffer-size=4 -fstack-protector -fno-unwind-tables -fno-asynchronous-unwind-tables -fPIC -pipe -B../../third_party/binutils/Linux_x64/Release/bin -fcolor-diagnostics -fdebug-prefix-map=/b/build/slave/precise64_trunk/build/src=. -flto -fwhole-program-vtables -pthread -m64 -march=x86-64 -Wall -Werror -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -Wno-c++11-narrowing -Wno-covered-switch-default -Wno-deprecated-register -Wno-unneeded-internal-declaration -Wno-inconsistent-missing-override -Wno-shift-negative-value -Wno-undefined-var-template -Wno-nonportable-include-path -Wno-address-of-packed-member -O2 -fno-ident -fdata-sections -ffunction-sections -g2 --sysroot=../../build/linux/debian_wheezy_amd64-sysroot -fsanitize=cfi-vcall -fsanitize-blacklist=../../tools/cfi/blacklist.txt -fvisibility=hidden -Xclang -load -Xclang ../../third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.so -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang check-ipc -Wheader-hygiene -Wstring-conversion -fno-threadsafe-statics -fvisibility-inlines-hidden -std=gnu++11 -fno-rtti -fno-exceptions -c ../../remoting/host/linux/remoting_user_session.cc -o obj/remoting/host/linux/remoting_user_session/remoting_user_session.o
../../remoting/host/linux/remoting_user_session.cc:320:5: error: ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
    fchown(STDOUT_FILENO, pwinfo->pw_uid, pwinfo->pw_gid);
    ^~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

Original issue's description:
> Add PAM session wrapper
>
> Adds a wrapper to launch me2me script in a proper PAM session.
>
> BUG= 616962 
>
> Committed: https://crrev.com/ac6cd2ac8ea912ee4dc0c229f79b04874aee9cc3
> Cr-Commit-Position: refs/heads/master@{#434172}

TBR=jamiewalch@chromium.org,lambroslambrou@chromium.org,sergeyu@chromium.org,rkjnsn@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG= 616962 

Review-Url: https://codereview.chromium.org/2527713002
Cr-Commit-Position: refs/heads/master@{#434218}

[modify] https://crrev.com/376920771f3df23499f30070f1ce9c2dc7c1a188/remoting/host/installer/linux/BUILD.gn
[modify] https://crrev.com/376920771f3df23499f30070f1ce9c2dc7c1a188/remoting/host/installer/linux/Makefile
[modify] https://crrev.com/376920771f3df23499f30070f1ce9c2dc7c1a188/remoting/host/installer/linux/debian/chrome-remote-desktop.init
[modify] https://crrev.com/376920771f3df23499f30070f1ce9c2dc7c1a188/remoting/host/installer/linux/debian/chrome-remote-desktop.pam
[modify] https://crrev.com/376920771f3df23499f30070f1ce9c2dc7c1a188/remoting/host/linux/BUILD.gn
[modify] https://crrev.com/376920771f3df23499f30070f1ce9c2dc7c1a188/remoting/host/linux/linux_me2me_host.py
[delete] https://crrev.com/db8a9220deabed531200e613a53d4fe6d87136d5/remoting/host/linux/remoting_user_session.cc

Comment 5 by rkjnsn@chromium.org, Dec 15 2016

Status: Fixed (was: Assigned)
Fix landed in M57.

Sign in to add a comment