Mac OS X Kernel Basic User Credentials

User Credentials

In order to understand security in OS X, it is important to understand that there are two security models at work. One of these is the kernel security model, which is based on users, groups, and very basic per-user and per-group rights, which are, in turn, coupled with access control lists for increased flexibility. The other is a user-level security model, which is based on keys, keychains, groups, users, password-based authentication, and a host of other details that are beyond the scope of this document.

The user-level security model (including the Keychain Manager and the Security Server) is beyond the scope of this document. The kernel security model, however, is of greater interest to kernel developers, and is much more straightforward than the user-level model. The kernel security model is based on two mechanisms: basic user credentials and ACL permissions. The first, basic user credentials, are passed around within the kernel to identify the current user and group of the calling process. The second authentication mechanism, access control lists (ACLs), provides access control at a finer level of granularity. One of the most important things to remember when working with credentials is that they are per process, not per context. This is important because a process may not be running as the console user. Two examples of this are processes started from an ssh session (since ssh runs in the startup context) and setuid programs (which run as a different user in the same login context).

It is crucial to be aware of these issues. If you are communicating with a setuid root GUI application in a user‘s login context, and if you are executing another application or are reading sensitive data, you probably want to treat it as if it had the same authority as the console user, not the authority of the effective user ID caused by running setuid. This is particularly problematic when dealing with programs that run as setuid root if the console user is not in the admin group. Failure to perform reasonable checks can lead to major security holes down the road.

However, this is not a hard and fast rule. Sometimes it is not obvious whether to use the credentials of the running process or those of the console user. In such cases, it is often reasonable to have a helper application show a dialog box on the console to require interaction from the console user. If this is not possible, a good rule of thumb is to assume the lesser of the privileges of the current and console users, as it is almost always better to have kernel code occasionally fail to provide a needed service than to provide that service unintentionally to an unauthorized user or process.

It is generally easier to determine the console user from a user space application than from kernel space code. Thus, you should generally do such checks from user space. If that is not possible, however, the variable console_user (maintained by the VFS subsystem) will give you the uid of the last owner of /dev/console (maintained by a bit of code in the chown system call). This is certainly not an ideal solution, but it does provide the most likely identity of the console user. Since this is only a "best guess," however, you should use this only if you cannot do appropriate checking in user space.

Basic User Credentials

Basic user credentials used in the kernel are stored in a variable of type struct ucred. These are mostly used in specialized parts of the kernel—generally in places where the determining factor in permissions is whether or not the caller is running as the root user.

This structure has four fields:

  • cr_ref—reference count (used internally)
  • cr_uid—user ID
  • cr_ngroups—number of groups in cr_groups
  • cr_groups[NGROUPS]—list of groups to which the user belongs

This structure has an internal reference counter to prevent unintentionally freeing the memory associated with it while it is still in use. For this reason, you should not indiscriminately copy this object but should instead either use crdup to duplicate it or use crcopy to duplicate it and (potentially) free the original. You should be sure to crfree any copies you might make. You can also create a new, empty ucred structure with crget.

The prototypes for these functions follow:

  • struct ucred *crdup(struct ucred *cr)
  • struct ucred *crcopy(struct ucred *cr)
  • struct ucred *crget(void)
  • void crfree(struct ucred *cr)

Note: Functions for working with basic user credential are not exported outside of the kernel, and thus are not generally available to kernel extensions.

Access Control Lists

Access control lists are a new feature in OS X v10.4. Access control lists are primarily used in the file system portion of the OS X kernel, and are supported through the use of the kauth API.

The kauth API is described in the header file /System/Library/Frameworks/Kernel.framework/Headers/sys/kauth.h. Because this API is still evolving, detailed documentation is not yet available.

SRC=https://developer.apple.com/library/prerelease/mac/documentation/Darwin/Conceptual/KernelProgramming/KernelProgramming.pdf

时间: 2024-10-07 20:38:34

Mac OS X Kernel Basic User Credentials的相关文章

[转]Debugging the Mac OS X kernel with VMware and GDB

Source:?http://ho.ax/posts/2012/02/debugging-the-mac-os-x-kernel-with-vmware-and-gdb/ Source:?http://ho.ax/posts/2012/02/vmware-hardware-debugging/ Edit 13 July 2013: I've made a couple of updates to this post to clarify a couple of things and resolv

Mac OS X中Android Kernel的下载方法

在上一篇日志中,我总结了大家提供的下载Android源码的方法,这里再简单总结一下内核的下载方法.参考这里的介绍:http://source.android.com/source/building-kernels.html#downloading-sources ,下载内核源码相对简单很多.我这里下载下来一共1G多一些.在终端输入: $ git clone https://android.googlesource.com/kernel/common.git 如果不指定文件夹名,就直接clone到

Install Docker on Mac OS X(转)

Install Docker on Mac OS X You can install Docker using Boot2Docker to run docker commands at your command-line. Choose this installation if you are familiar with the command-line or plan to contribute to the Docker project on GitHub. Alternatively,

A MacFUSE-Based Process File System for Mac OS X

referer: http://osxbook.com/book/bonus/chapter11/procfs/ Processes as Files The process file system ("procfs" for brevity, or simply "/proc", because that's where it is usually mounted) has become a common entity on Unix-like systems.

在 Mac OS 上使用 TypeScript 编写 ASP.NET 5 应用

在 Mac OS 上使用 TypeScript 编写 ASP.NET 5 应用? 提示 本文更新时间:2015年12月24日. 在 Mac OS 上,并没有时候编辑 ASP.NET 5 的 IDE,只有一个 Visual Studio Code 可用, 这种情况下,编写后端代码是比较费劲的(对于习惯使用IDE的人来说),所以本文从前端的角度来介绍下. 本文将引导你创建一个 d3 数据变化曲线的展现过程. 什么是 TypeScript? 写过 JavaScript 的人都知道, JavaScrip

Mac OS X:禁止崩溃报告-CrashReport

Mac OS X:禁止崩溃报告 崩溃报告就是CrashReport 至于官方的有关CrashReport的文档在Technical Note TN212 . 一般的默认情况下,当一个应用程序因为各种原因出现系统错误而退出的时候,Mac OS X会捕捉这个错误,并出现下面类似的提示窗口,提示用户该程序出错.如下图: 用户可以有三个选择, Ignore就是忽略该错误并退出该程序, Report...可以将错误的详细报告内容提交给Apple. Relaunch用户可以选择重新启动该应用程序. 有两层意

Mac OS X 背后的故事

Mac OS X 背后的故事 作者: 王越  来源: <程序员>  发布时间: 2013-01-22 10:55  阅读: 25840 次  推荐: 49   原文链接   [收藏] 作者王越,美国宾夕法尼亚大学计算机系研究生,中国著名 TeX 开发者,非著名 OpenFOAM 开发者. Mac OS X 背后的故事(一)力挽狂澜的Ellen Hancock Mac OS X 背后的故事(二)Linus Torvalds的短视 Mac OS X 背后的故事(三)Mach之父Avie Tevan

windows环境下安装win8.1+Mac OS X 10.10双系统教程

首先要感谢远景论坛里的各位大神们的帖子  没有他们的分享我也不能顺利的装上Mac OS X 10.10! 写这篇随笔主要是为了防止自己遗忘,同时给大家分享下我的经验. 本教程适用于BIOS+MBR分区的朋友们使用 首先介绍下我的电脑硬件信息 安装环境为:win8.1系统 引导方式为:变色龙r2378 一.准备工作 1.下载Mac OS X 10.10镜像(本镜像为懒人版镜像非官方镜像) 地址:http://pan.baidu.com/s/1gdEf4Gj 2.下载所需要使用到的工具,我将所有需要

mac OS.NE开发环境搭建

合肥程序员群:49313181.    合肥实名程序员群:128131462 (不愿透露姓名和信息者勿加入,申请备注填写姓名+技术+工作年限) Q  Q:408365330     E-Mail:[email protected] 一.写在前面 距离上次写技术的文章已经很久很久了,一直忙公司的事情,自己的事情..NET 相关博客也是多年前的事情了.毕竟转做andorid和IOS已经2年多了,国庆节放假也思考了下,想想再忙还是要抽时间让自己沉淀下,钱是赚不完的(虽然也赚不到钱,有赚钱的机会兄弟们要