Big Ben

一个半吊子的编码爱好者

0%

什么是聚合类型

C++03定义
An aggregate is an array or a class (clause 9) with no user-declared constructors (12.1), no private or protected non-static data members (clause 11), no base classes (clause 10), and no virtual functions (10.3).

C++11定义
An aggregate is an array or a class (Clause 9) with no user-provided constructors (12.1), no brace-or-equal-initializers for non-static data members (9.2), no private or protected non-static data members (Clause 11), no base classes (Clause 10), and no virtual functions (10.3).

结合C++03和C++11标准定义,罗列一下聚合类型的特性:

  • 聚合类型可以有构造函数,但只能是编译器定义的默认构造函数,或者用=default定义的构造函数
  • 聚合类型不能有private,protected非static变量
  • 聚合类型可以有copy-assignment operator and/or destructor
  • 数组是聚合类型,即便数组成员是非聚合类型
  • 聚合类型的数组可以是非聚合类型
  • 聚合类型不能用brace-or-equal-initializers(即就地初始化)初始化非static成员。

聚合类型变量初始化

聚合类型可以采用列表初始化(其实非聚合类型,通过自定义构造函数,也可以采用列表初始化)

if(m == n)
{
    // the ith element of the array is initialized with ai
}
else if(m < n) {
    // the first m elements of the array are initialized with a1,  a2, …, am and the other n - m elements are, if possible, value-initialized (see below for the explanation of the term)
}
else if(m > n) {
    // the compiler will issue an error
}
else /*(this is the case when n isn't specified at all like int a[] = {1, 2, 3};) */
{
    // the size of the array (n) is assumed to be equal to m, so int a[] = {1, 2, 3}; is equivalent to int a[3] = {1, 2, 3};
}

聚合变量最大的特点可以做聚合初始化,除了基本的列表初始化规则,聚合初始化还体现在可以递归初始化。

struct X
{
  int i1;
  int i2;
};
struct Y
{
  char c;
  X x;
  int i[2];
  float f; 
protected:
  static double d;
private:
  void g(){}      
}; 
struct Z {
  char a;
  X x;
  Z(char a1) {};
};

Y y = {'a', {10, 20}, {20, 30}};

y.x也被初始化了。如果对Z用递归聚合初始化,例如Z z = {'a', {'b'}},编译器就会报错。因为Z不是聚合类型,编译器会去找对应的构造函数,显然Z没定义这样的构造函数。
具体介绍可以参考Aggregate initialization

什么是POD变量

POD = Plain Old Data,可见这是一种兼容型比较好的形态。甚至可以导出与其他语言共享此类变量定义。

C++03定义
A POD-struct is an aggregate class that has no non-static data members of type non-POD-struct, non-POD-union (or array of such types) or reference, and has no user-defined copy assignment operator and no user-defined destructor. Similarly, a POD-union is an aggregate union that has no non-static data members of type non-POD-struct, non-POD-union (or array of such types) or reference, and has no user-defined copy assignment operator and no user-defined destructor. A POD class is a class that is either a POD-struct or a POD-union.

C++11定义变得非常优雅
A POD struct is a non-union class that is both a trivial class and a standard-layout class, and has no non-static data members of type non-POD struct, non-POD union (or array of such types). Similarly, a POD union is a union that is both a trivial class and a standard layout class, and has no non-static data members of type non-POD struct, non-POD union (or array of such types). A POD class is a class that is either a POD struct or a POD union.

总而言之:
POD类型是一种特殊的聚合类型,一个POD类型为:

  • 标量类型。
  • 满足以下条件的自定义类型:
    • C++11之前:
      • 聚合类型。
      • 没有非POD类型的非静态成员变量。
      • 没有引用类型的非静态成员变量。
      • 没有自定义的构造函数或析构函数。
    • C++11之后:
      • 是平凡类。
      • 是标准布局类。
      • 没有非POD类型的非静态成员变量。
  • POD类型的数组。

聚合类型或是POD变量有什么好处?

聚合类最大的特点就是可以采用聚合初始化。
POD的特点更为实用一些

POD的用途
平凡类的用途:

  • 平凡类的对象可以与字节流之间安全转换,即:
    - 若要将对象转为字节流,直接取其地址即可。
    - 若要将字节流转为对象,直接将该地址cast为对象指针即可。
    - 直接通过复制字节的方式复制对象。
  • 安全的静态初始化。
    - C++11的thread_local变量可以是非平凡类型,但在某些编译器下会有比较大的性能开销。gcc扩展的__thread只能使用POD类型。

标准布局类的用途:
跨进程、跨语言使用。

名次解释

value initialization

  • 对于普通类型变量(bool, int, char, double, pointers, etc.)
    it means it is initialized with 0 for that type (false for bool, 0.0 for double, etc.).
  • 对于class类型
    • 如果有自定义构造函数,则调用自定义构造函数
    • 如果没有自定一构造函数,则调用默认构造函数
    • 如果没有对应的构造函数,则报错

举例

class A
{
public:
  A(int) {} //no default constructor
};
class B
{
public:
  B() {} //default constructor available
};
int main()
{
  A a1[3] = {A(2), A(1), A(14)}; //OK n == m
  A a2[3] = {A(2)}; //ERROR A has no default constructor. Unable to value-initialize a2[1] and a2[2]
  B b1[3] = {B()}; //OK b1[1] and b1[2] are value initialized, in this case with the default-ctor
  int Array1[1000] = {0}; //All elements are initialized with 0;
  int Array2[1000] = {1}; //Attention: only the first element is 1, the rest are 0;
  bool Array3[1000] = {}; //the braces can be empty too. All elements initialized with false
  int Array4[1000]; //no initializer. This is different from an empty {} initializer in that
  //the elements in this case are not value-initialized, but have indeterminate values 
  //(unless, of course, Array4 is a global array)
  int array[2] = {1, 2, 3, 4}; //ERROR, too many initializers
}

大括号中个数不足的,用value initialization补足。这就是A a = {1};或者A a = {}的含义。大括号中个数超过声明的个数的,则编译报错。

brace-or-equal-initializers

类成员的一种初始化方法

class B {
public:
    B(int){}
};

class A {
    int a = 123;
    int b {456};
    B c {12};
    B d = {34};
};

copy-assignment operator

拷贝赋值方法

class A {
    A A(int) {}
    A(const &) {}
    A& operator= (const A&a) {}
};
void main() {
    A a;
    A b = a; // 这里调用的是拷贝构造函数
    A c;
    c = a; // 这里才会调用拷贝复制函数
}

trial stuff

trivial copyable

参考C++ named requirements: TriviallyCopyable

The following types are collectively called trivially copyable types:

  • Scalar types
  • Trivially copyable classes, i.e. classes satisfying following requirements:
    - At least one copy constructor, move constructor, copy assignment operator, or move assignment operator is eligible
    - Every eligible copy constructor (if any) is trivial
    - Every eligible move constructor (if any) is trivial
    - Every eligible copy assignment operator (if any) is trivial
    - Every eligible move assignment operator (if any) is trivial
    - Has a trivial non-deleted destructor
  • Arrays of TriviallyCopyable objects

This implies that a trivially copyable class has no virtual functions or virtual base classes.

通过模版std::is_trivially_copyable可以检验一个类是否trivially copyable。

trivial constructor/destructor

  • 编译器定义的构造/析构函数
  • =default定义的构造析构函数

trivial class

The standard defines a trivial class as follows:

A trivially copyable class is a class that:

  • has no non-trivial copy constructors (12.8),
  • has no non-trivial move constructors (12.8),
  • has no non-trivial copy assignment operators (13.5.3, 12.8),
  • has no non-trivial move assignment operators (13.5.3, 12.8), and
  • has a trivial destructor (12.4).

A trivial class is a class that has a trivial default constructor (12.1) and is trivially copyable.

[ Note: In particular, a trivially copyable or trivial class does not have virtual functions or virtual base classes. ]
另外trivial class是递归的,即trivial class不能有非trivial class的非static成员。
用模版std::is_trivial来测试

standard layout

A standard-layout class is a class that:

  • has no non-static data members of type non-standard-layout class (or array of such types) or reference,

  • has no virtual functions (10.3) and no virtual base classes (10.1),

  • has the same access control (Clause 11) for all non-static data members,

  • has no non-standard-layout base classes,

  • either has no non-static data members in the most derived class and at most one base class with non-static data members, or has no base classes with non-static data members, (要么终点类没有非静态成员,并且只有一个基类有非静态成员;要么没有基类有非静态成员),and

  • has no base classes of the same type as the first non-static data member.

A standard-layout struct is a standard-layout class defined with the class-key struct or the class-key class.

A standard-layout union is a standard-layout class defined with the class-key union.

[ Note: Standard-layout classes are useful for communicating with code written in other programming languages. Their layout is specified in 9.2.]

标准内存分布,确保对象内存和C语言的结构体内存分布完全一致。使得POD变量具备了C兼容性。
用模版std::is_standard_layout可以测试

总结

std::is_pod来测试你的类吧。

参考文献

  1. What are Aggregates and PODs and how/why are they special?
  2. C++对象模型(三)POD
%23%20%E4%BB%80%E4%B9%88%E6%98%AF%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%0A%3E%20**C%2B%2B03%E5%AE%9A%E4%B9%89**%0A%3E%20An%20aggregate%20is%20an%20array%20or%20a%20class%20(clause%209)%20with%20no%20user-declared%20constructors%20(12.1)%2C%20no%20private%20or%20protected%20non-static%20data%20members%20(clause%2011)%2C%20no%20base%20classes%20(clause%2010)%2C%20and%20no%20virtual%20functions%20(10.3).%0A%0A%3E%20**C%2B%2B11%E5%AE%9A%E4%B9%89**%0A%3E%20An%20aggregate%20is%20an%20array%20or%20a%20class%20(Clause%209)%20with%20no%20user-provided%20constructors%20(12.1)%2C%20no%20brace-or-equal-initializers%20for%20non-static%20data%20members%20(9.2)%2C%20no%20private%20or%20protected%20non-static%20data%20members%20(Clause%2011)%2C%20no%20base%20classes%20(Clause%2010)%2C%20and%20no%20virtual%20functions%20(10.3).%0A%0A%E7%BB%93%E5%90%88C%2B%2B03%E5%92%8CC%2B%2B11%E6%A0%87%E5%87%86%E5%AE%9A%E4%B9%89%EF%BC%8C%E7%BD%97%E5%88%97%E4%B8%80%E4%B8%8B%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%E7%9A%84%E7%89%B9%E6%80%A7%EF%BC%9A%0A-%20%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%E5%8F%AF%E4%BB%A5%E6%9C%89%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%EF%BC%8C%E4%BD%86%E5%8F%AA%E8%83%BD%E6%98%AF%E7%BC%96%E8%AF%91%E5%99%A8%E5%AE%9A%E4%B9%89%E7%9A%84%E9%BB%98%E8%AE%A4%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%EF%BC%8C%E6%88%96%E8%80%85%E7%94%A8%60%3Ddefault%60%E5%AE%9A%E4%B9%89%E7%9A%84%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%0A-%20%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%E4%B8%8D%E8%83%BD%E6%9C%89private%EF%BC%8Cprotected%E9%9D%9Estatic%E5%8F%98%E9%87%8F%0A-%20%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%E5%8F%AF%E4%BB%A5%E6%9C%89copy-assignment%20operator%20and%2For%20destructor%0A-%20%E6%95%B0%E7%BB%84%E6%98%AF%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%EF%BC%8C%E5%8D%B3%E4%BE%BF%E6%95%B0%E7%BB%84%E6%88%90%E5%91%98%E6%98%AF%E9%9D%9E%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%0A-%20%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%E7%9A%84%E6%95%B0%E7%BB%84%E5%8F%AF%E4%BB%A5%E6%98%AF%E9%9D%9E%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%0A-%20%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%E4%B8%8D%E8%83%BD%E7%94%A8brace-or-equal-initializers%EF%BC%88%E5%8D%B3%E5%B0%B1%E5%9C%B0%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%89%E5%88%9D%E5%A7%8B%E5%8C%96%E9%9D%9Estatic%E6%88%90%E5%91%98%E3%80%82%0A%0A%23%23%20%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%E5%8F%98%E9%87%8F%E5%88%9D%E5%A7%8B%E5%8C%96%0A%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%E5%8F%AF%E4%BB%A5%E9%87%87%E7%94%A8%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%88%E5%85%B6%E5%AE%9E%E9%9D%9E%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%EF%BC%8C%E9%80%9A%E8%BF%87%E8%87%AA%E5%AE%9A%E4%B9%89%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%EF%BC%8C%E4%B9%9F%E5%8F%AF%E4%BB%A5%E9%87%87%E7%94%A8%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%89%0A%60%60%60%20c%0Aif(m%20%3D%3D%20n)%0A%7B%0A%20%20%20%20%2F%2F%20the%20ith%20element%20of%20the%20array%20is%20initialized%20with%20ai%0A%7D%0Aelse%20if(m%20%3C%20n)%20%7B%0A%20%20%20%20%2F%2F%20the%20first%20m%20elements%20of%20the%20array%20are%20initialized%20with%20a1%2C%20%20a2%2C%20%E2%80%A6%2C%20am%20and%20the%20other%20n%20-%20m%20elements%20are%2C%20if%20possible%2C%20value-initialized%20(see%20below%20for%20the%20explanation%20of%20the%20term)%0A%7D%0Aelse%20if(m%20%3E%20n)%20%7B%0A%20%20%20%20%2F%2F%20the%20compiler%20will%20issue%20an%20error%0A%7D%0Aelse%20%2F*(this%20is%20the%20case%20when%20n%20isn't%20specified%20at%20all%20like%20int%20a%5B%5D%20%3D%20%7B1%2C%202%2C%203%7D%3B)%20*%2F%0A%7B%0A%20%20%20%20%2F%2F%20the%20size%20of%20the%20array%20(n)%20is%20assumed%20to%20be%20equal%20to%20m%2C%20so%20int%20a%5B%5D%20%3D%20%7B1%2C%202%2C%203%7D%3B%20is%20equivalent%20to%20int%20a%5B3%5D%20%3D%20%7B1%2C%202%2C%203%7D%3B%0A%7D%0A%60%60%60%0A%E8%81%9A%E5%90%88%E5%8F%98%E9%87%8F%E6%9C%80%E5%A4%A7%E7%9A%84%E7%89%B9%E7%82%B9%E5%8F%AF%E4%BB%A5%E5%81%9A**%E8%81%9A%E5%90%88%E5%88%9D%E5%A7%8B%E5%8C%96**%EF%BC%8C%E9%99%A4%E4%BA%86%E5%9F%BA%E6%9C%AC%E7%9A%84%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E8%A7%84%E5%88%99%EF%BC%8C%E8%81%9A%E5%90%88%E5%88%9D%E5%A7%8B%E5%8C%96%E8%BF%98%E4%BD%93%E7%8E%B0%E5%9C%A8%E5%8F%AF%E4%BB%A5%E9%80%92%E5%BD%92%E5%88%9D%E5%A7%8B%E5%8C%96%E3%80%82%0A%60%60%60c%2B%2B%0Astruct%20X%0A%7B%0A%20%20int%20i1%3B%0A%20%20int%20i2%3B%0A%7D%3B%0Astruct%20Y%0A%7B%0A%20%20char%20c%3B%0A%20%20X%20x%3B%0A%20%20int%20i%5B2%5D%3B%0A%20%20float%20f%3B%20%0Aprotected%3A%0A%20%20static%20double%20d%3B%0Aprivate%3A%0A%20%20void%20g()%7B%7D%20%20%20%20%20%20%0A%7D%3B%20%0Astruct%20Z%20%7B%0A%20%20char%20a%3B%0A%20%20X%20x%3B%0A%20%20Z(char%20a1)%20%7B%7D%3B%0A%7D%3B%0A%0AY%20y%20%3D%20%7B'a'%2C%20%7B10%2C%2020%7D%2C%20%7B20%2C%2030%7D%7D%3B%0A%60%60%60%0A%60y.x%60%E4%B9%9F%E8%A2%AB%E5%88%9D%E5%A7%8B%E5%8C%96%E4%BA%86%E3%80%82%E5%A6%82%E6%9E%9C%E5%AF%B9Z%E7%94%A8%E9%80%92%E5%BD%92%E8%81%9A%E5%90%88%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%8C%E4%BE%8B%E5%A6%82%60Z%20z%20%3D%20%7B'a'%2C%20%7B'b'%7D%7D%60%EF%BC%8C%E7%BC%96%E8%AF%91%E5%99%A8%E5%B0%B1%E4%BC%9A%E6%8A%A5%E9%94%99%E3%80%82%E5%9B%A0%E4%B8%BAZ%E4%B8%8D%E6%98%AF%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%EF%BC%8C%E7%BC%96%E8%AF%91%E5%99%A8%E4%BC%9A%E5%8E%BB%E6%89%BE%E5%AF%B9%E5%BA%94%E7%9A%84%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%EF%BC%8C%E6%98%BE%E7%84%B6Z%E6%B2%A1%E5%AE%9A%E4%B9%89%E8%BF%99%E6%A0%B7%E7%9A%84%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E3%80%82%0A%E5%85%B7%E4%BD%93%E4%BB%8B%E7%BB%8D%E5%8F%AF%E4%BB%A5%E5%8F%82%E8%80%83%5BAggregate%20initialization%5D(https%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Flanguage%2Faggregate_initialization)%E3%80%82%0A%23%20%E4%BB%80%E4%B9%88%E6%98%AFPOD%E5%8F%98%E9%87%8F%0APOD%20%3D%20Plain%20Old%20Data%EF%BC%8C%E5%8F%AF%E8%A7%81%E8%BF%99%E6%98%AF%E4%B8%80%E7%A7%8D%E5%85%BC%E5%AE%B9%E5%9E%8B%E6%AF%94%E8%BE%83%E5%A5%BD%E7%9A%84%E5%BD%A2%E6%80%81%E3%80%82%E7%94%9A%E8%87%B3%E5%8F%AF%E4%BB%A5%E5%AF%BC%E5%87%BA%E4%B8%8E%E5%85%B6%E4%BB%96%E8%AF%AD%E8%A8%80%E5%85%B1%E4%BA%AB%E6%AD%A4%E7%B1%BB%E5%8F%98%E9%87%8F%E5%AE%9A%E4%B9%89%E3%80%82%0A%3E%20**C%2B%2B03%E5%AE%9A%E4%B9%89**%0A%3E%20A%20POD-struct%20is%20an%20aggregate%20class%20that%20has%20no%20non-static%20data%20members%20of%20type%20non-POD-struct%2C%20non-POD-union%20(or%20array%20of%20such%20types)%20or%20reference%2C%20and%20has%20no%20user-defined%20copy%20assignment%20operator%20and%20no%20user-defined%20destructor.%20Similarly%2C%20a%20POD-union%20is%20an%20aggregate%20union%20that%20has%20no%20non-static%20data%20members%20of%20type%20non-POD-struct%2C%20non-POD-union%20(or%20array%20of%20such%20types)%20or%20reference%2C%20and%20has%20no%20user-defined%20copy%20assignment%20operator%20and%20no%20user-defined%20destructor.%20A%20POD%20class%20is%20a%20class%20that%20is%20either%20a%20POD-struct%20or%20a%20POD-union.%0A%0A%3E%20C%2B%2B11%E5%AE%9A%E4%B9%89%E5%8F%98%E5%BE%97%E9%9D%9E%E5%B8%B8%E4%BC%98%E9%9B%85%0A%3E%20**A%20POD%20struct%20is%20a%20non-union%20class%20that%20is%20both%20a%20trivial%20class%20and%20a%20standard-layout%20class**%2C%20and%20has%20no%20non-static%20data%20members%20of%20type%20non-POD%20struct%2C%20non-POD%20union%20(or%20array%20of%20such%20types).%20Similarly%2C%20a%20POD%20union%20is%20a%20union%20that%20is%20both%20a%20trivial%20class%20and%20a%20standard%20layout%20class%2C%20and%20has%20no%20non-static%20data%20members%20of%20type%20non-POD%20struct%2C%20non-POD%20union%20(or%20array%20of%20such%20types).%20A%20POD%20class%20is%20a%20class%20that%20is%20either%20a%20POD%20struct%20or%20a%20POD%20union.%0A%0A%E6%80%BB%E8%80%8C%E8%A8%80%E4%B9%8B%EF%BC%9A%0APOD%E7%B1%BB%E5%9E%8B%E6%98%AF%E4%B8%80%E7%A7%8D%E7%89%B9%E6%AE%8A%E7%9A%84%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%EF%BC%8C%E4%B8%80%E4%B8%AAPOD%E7%B1%BB%E5%9E%8B%E4%B8%BA%EF%BC%9A%0A-%20%E6%A0%87%E9%87%8F%E7%B1%BB%E5%9E%8B%E3%80%82%0A-%20%E6%BB%A1%E8%B6%B3%E4%BB%A5%E4%B8%8B%E6%9D%A1%E4%BB%B6%E7%9A%84%E8%87%AA%E5%AE%9A%E4%B9%89%E7%B1%BB%E5%9E%8B%EF%BC%9A%0A%20%20%20%20-%20C%2B%2B11%E4%B9%8B%E5%89%8D%EF%BC%9A%0A%20%20%20%20%20%20%20%20-%20%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%E3%80%82%0A%20%20%20%20%20%20%20%20-%20%E6%B2%A1%E6%9C%89%E9%9D%9EPOD%E7%B1%BB%E5%9E%8B%E7%9A%84%E9%9D%9E%E9%9D%99%E6%80%81%E6%88%90%E5%91%98%E5%8F%98%E9%87%8F%E3%80%82%0A%20%20%20%20%20%20%20%20-%20%E6%B2%A1%E6%9C%89%E5%BC%95%E7%94%A8%E7%B1%BB%E5%9E%8B%E7%9A%84%E9%9D%9E%E9%9D%99%E6%80%81%E6%88%90%E5%91%98%E5%8F%98%E9%87%8F%E3%80%82%0A%20%20%20%20%20%20%20%20-%20%E6%B2%A1%E6%9C%89%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9A%84%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E6%88%96%E6%9E%90%E6%9E%84%E5%87%BD%E6%95%B0%E3%80%82%0A%20%20%20%20-%20C%2B%2B11%E4%B9%8B%E5%90%8E%EF%BC%9A%0A%20%20%20%20%20%20%20%20-%20%E6%98%AF%E5%B9%B3%E5%87%A1%E7%B1%BB%E3%80%82%0A%20%20%20%20%20%20%20%20-%20%E6%98%AF%E6%A0%87%E5%87%86%E5%B8%83%E5%B1%80%E7%B1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5%9D%80%E5%8D%B3%E5%8F%AF%E3%80%82%0A%20%20%20%20-%20%E8%8B%A5%E8%A6%81%E5%B0%86%E5%AD%97%E8%8A%82%E6%B5%81%E8%BD%AC%E4%B8%BA%E5%AF%B9%E8%B1%A1%EF%BC%8C%E7%9B%B4%E6%8E%A5%E5%B0%86%E8%AF%A5%E5%9C%B0%E5%9D%80cast%E4%B8%BA%E5%AF%B9%E8%B1%A1%E6%8C%87%E9%92%88%E5%8D%B3%E5%8F%AF%E3%80%82%0A%20%20%20%20-%20%E7%9B%B4%E6%8E%A5%E9%80%9A%E8%BF%87%E5%A4%8D%E5%88%B6%E5%AD%97%E8%8A%82%E7%9A%84%E6%96%B9%E5%BC%8F%E5%A4%8D%E5%88%B6%E5%AF%B9%E8%B1%A1%E3%80%82%0A%3E-%20%E5%AE%89%E5%85%A8%E7%9A%84%E9%9D%99%E6%80%81%E5%88%9D%E5%A7%8B%E5%8C%96%E3%80%82%0A%20%20%20%20-%20C%2B%2B11%E7%9A%84thread_local%E5%8F%98%E9%87%8F%E5%8F%AF%E4%BB%A5%E6%98%AF%E9%9D%9E%E5%B9%B3%E5%87%A1%E7%B1%BB%E5%9E%8B%EF%BC%8C%E4%BD%86%E5%9C%A8%E6%9F%90%E4%BA%9B%E7%BC%96%E8%AF%91%E5%99%A8%E4%B8%8B%E4%BC%9A%E6%9C%89%E6%AF%94%E8%BE%83%E5%A4%A7%E7%9A%84%E6%80%A7%E8%83%BD%E5%BC%80%E9%94%80%E3%80%82gcc%E6%89%A9%E5%B1%95%E7%9A%84__thread%E5%8F%AA%E8%83%BD%E4%BD%BF%E7%94%A8POD%E7%B1%BB%E5%9E%8B%E3%80%82%0A%3E%0A%3E**%E6%A0%87%E5%87%86%E5%B8%83%E5%B1%80%E7%B1%BB%E7%9A%84%E7%94%A8%E9%80%94%EF%BC%9A**%0A%E8%B7%A8%E8%BF%9B%E7%A8%8B%E3%80%81%E8%B7%A8%E8%AF%AD%E8%A8%80%E4%BD%BF%E7%94%A8%E3%80%82%0A%23%20%E5%90%8D%E6%AC%A1%E8%A7%A3%E9%87%8A%0A%23%23%20value%20initialization%0A-%20%E5%AF%B9%E4%BA%8E%E6%99%AE%E9%80%9A%E7%B1%BB%E5%9E%8B%E5%8F%98%E9%87%8F(bool%2C%20int%2C%20char%2C%20double%2C%20pointers%2C%20etc.)%20%0Ait%20means%20it%20is%20initialized%20with%200%20for%20that%20type%20(false%20for%20bool%2C%200.0%20for%20double%2C%20etc.).%20%0A-%20%E5%AF%B9%E4%BA%8Eclass%E7%B1%BB%E5%9E%8B%0A%20%20%20%20-%20%E5%A6%82%E6%9E%9C%E6%9C%89%E8%87%AA%E5%AE%9A%E4%B9%89%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%EF%BC%8C%E5%88%99%E8%B0%83%E7%94%A8%E8%87%AA%E5%AE%9A%E4%B9%89%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%0A%20%20%20%20-%20%E5%A6%82%E6%9E%9C%E6%B2%A1%E6%9C%89%E8%87%AA%E5%AE%9A%E4%B8%80%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%EF%BC%8C%E5%88%99%E8%B0%83%E7%94%A8%E9%BB%98%E8%AE%A4%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%0A%20%20%20%20-%20%E5%A6%82%E6%9E%9C%E6%B2%A1%E6%9C%89%E5%AF%B9%E5%BA%94%E7%9A%84%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%EF%BC%8C%E5%88%99%E6%8A%A5%E9%94%99%0A%20%20%20%20%0A%E4%B8%BE%E4%BE%8B%0A%60%60%60c%2B%2B%0Aclass%20A%0A%7B%0Apublic%3A%0A%20%20A(int)%20%7B%7D%20%2F%2Fno%20default%20constructor%0A%7D%3B%0Aclass%20B%0A%7B%0Apublic%3A%0A%20%20B()%20%7B%7D%20%2F%2Fdefault%20constructor%20available%0A%7D%3B%0Aint%20main()%0A%7B%0A%20%20A%20a1%5B3%5D%20%3D%20%7BA(2)%2C%20A(1)%2C%20A(14)%7D%3B%20%2F%2FOK%20n%20%3D%3D%20m%0A%20%20A%20a2%5B3%5D%20%3D%20%7BA(2)%7D%3B%20%2F%2FERROR%20A%20has%20no%20default%20constructor.%20Unable%20to%20value-initialize%20a2%5B1%5D%20and%20a2%5B2%5D%0A%20%20B%20b1%5B3%5D%20%3D%20%7BB()%7D%3B%20%2F%2FOK%20b1%5B1%5D%20and%20b1%5B2%5D%20are%20value%20initialized%2C%20in%20this%20case%20with%20the%20default-ctor%0A%20%20int%20Array1%5B1000%5D%20%3D%20%7B0%7D%3B%20%2F%2FAll%20elements%20are%20initialized%20with%200%3B%0A%20%20int%20Array2%5B1000%5D%20%3D%20%7B1%7D%3B%20%2F%2FAttention%3A%20only%20the%20first%20element%20is%201%2C%20the%20rest%20are%200%3B%0A%20%20bool%20Array3%5B1000%5D%20%3D%20%7B%7D%3B%20%2F%2Fthe%20braces%20can%20be%20empty%20too.%20All%20elements%20initialized%20with%20false%0A%20%20int%20Array4%5B1000%5D%3B%20%2F%2Fno%20initializer.%20This%20is%20different%20from%20an%20empty%20%7B%7D%20initializer%20in%20that%0A%20%20%2F%2Fthe%20elements%20in%20this%20case%20are%20not%20value-initialized%2C%20but%20have%20indeterminate%20values%20%0A%20%20%2F%2F(unless%2C%20of%20course%2C%20Array4%20is%20a%20global%20array)%0A%20%20int%20array%5B2%5D%20%3D%20%7B1%2C%202%2C%203%2C%204%7D%3B%20%2F%2FERROR%2C%20too%20many%20initializers%0A%7D%0A%60%60%60%0A%E5%A4%A7%E6%8B%AC%E5%8F%B7%E4%B8%AD%E4%B8%AA%E6%95%B0%E4%B8%8D%E8%B6%B3%E7%9A%84%EF%BC%8C%E7%94%A8value%20initialization%E8%A1%A5%E8%B6%B3%E3%80%82%E8%BF%99%E5%B0%B1%E6%98%AF%60A%20a%20%3D%20%7B1%7D%3B%60%E6%88%96%E8%80%85%60A%20a%20%3D%20%7B%7D%60%E7%9A%84%E5%90%AB%E4%B9%89%E3%80%82%E5%A4%A7%E6%8B%AC%E5%8F%B7%E4%B8%AD%E4%B8%AA%E6%95%B0%E8%B6%85%E8%BF%87%E5%A3%B0%E6%98%8E%E7%9A%84%E4%B8%AA%E6%95%B0%E7%9A%84%EF%BC%8C%E5%88%99%E7%BC%96%E8%AF%91%E6%8A%A5%E9%94%99%E3%80%82%0A%0A%23%23%20brace-or-equal-initializers%0A%E7%B1%BB%E6%88%90%E5%91%98%E7%9A%84%E4%B8%80%E7%A7%8D%E5%88%9D%E5%A7%8B%E5%8C%96%E6%96%B9%E6%B3%95%0A%60%60%60c%2B%2B%0Aclass%20B%20%7B%0Apublic%3A%0A%20%20%20%20B(int)%7B%7D%0A%7D%3B%0A%0Aclass%20A%20%7B%0A%20%20%20%20int%20a%20%3D%20123%3B%0A%20%20%20%20int%20b%20%7B456%7D%3B%0A%20%20%20%20B%20c%20%7B12%7D%3B%0A%20%20%20%20B%20d%20%3D%20%7B34%7D%3B%0A%7D%3B%0A%60%60%60%0A%23%23%20copy-assignment%20operator%0A%E6%8B%B7%E8%B4%9D%E8%B5%8B%E5%80%BC%E6%96%B9%E6%B3%95%0A%60%60%60c%2B%2B%0Aclass%20A%20%7B%0A%20%20%20%20A%20A(int)%20%7B%7D%0A%20%20%20%20A(const%20%26)%20%7B%7D%0A%20%20%20%20A%26%20operator%3D%20(const%20A%26a)%20%7B%7D%0A%7D%3B%0Avoid%20main()%20%7B%0A%20%20%20%20A%20a%3B%0A%20%20%20%20A%20b%20%3D%20a%3B%20%2F%2F%20%E8%BF%99%E9%87%8C%E8%B0%83%E7%94%A8%E7%9A%84%E6%98%AF%E6%8B%B7%E8%B4%9D%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%0A%20%20%20%20A%20c%3B%0A%20%20%20%20c%20%3D%20a%3B%20%2F%2F%20%E8%BF%99%E9%87%8C%E6%89%8D%E4%BC%9A%E8%B0%83%E7%94%A8%E6%8B%B7%E8%B4%9D%E5%A4%8D%E5%88%B6%E5%87%BD%E6%95%B0%0A%7D%0A%60%60%60%0A%23%23%20trial%20stuff%0A%23%23%23%20trivial%20copyable%0A%E5%8F%82%E8%80%83%5BC%2B%2B%20named%20requirements%3A%20TriviallyCopyable%5D(https%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Fnamed_req%2FTriviallyCopyable)%0A%3E%20The%20following%20types%20are%20collectively%20called%20trivially%20copyable%20types%3A%0A%3E%20-%20Scalar%20types%0A%3E%20-%20Trivially%20copyable%20classes%2C%20i.e.%20classes%20satisfying%20following%20requirements%3A%0A%20%20%20%20-%20At%20least%20one%20copy%20constructor%2C%20move%20constructor%2C%20copy%20assignment%20operator%2C%20or%20move%20assignment%20operator%20is%20eligible%0A%20%20%20%20-%20Every%20eligible%20copy%20constructor%20(if%20any)%20is%20trivial%0A%20%20%20%20-%20Every%20eligible%20move%20constructor%20(if%20any)%20is%20trivial%0A%20%20%20%20-%20Every%20eligible%20copy%20assignment%20operator%20(if%20any)%20is%20trivial%0A%20%20%20%20-%20Every%20eligible%20move%20assignment%20operator%20(if%20any)%20is%20trivial%0A%20%20%20%20-%20Has%20a%20trivial%20non-deleted%20destructor%0A%3E%20-%20Arrays%20of%20TriviallyCopyable%20objects%0A%3E%0A%3E%20This%20implies%20that%20a%20trivially%20copyable%20class%20has%20no%20virtual%20functions%20or%20virtual%20base%20classes.%0A%0A%E9%80%9A%E8%BF%87%E6%A8%A1%E7%89%88%5Bstd%3A%3Ais_trivially_copyable%5D(https%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Ftypes%2Fis_trivially_copyable)%E5%8F%AF%E4%BB%A5%E6%A3%80%E9%AA%8C%E4%B8%80%E4%B8%AA%E7%B1%BB%E6%98%AF%E5%90%A6trivially%20copyable%E3%80%82%0A%23%23%23%20trivial%20constructor%2Fdestructor%0A-%20%E7%BC%96%E8%AF%91%E5%99%A8%E5%AE%9A%E4%B9%89%E7%9A%84%E6%9E%84%E9%80%A0%2F%E6%9E%90%E6%9E%84%E5%87%BD%E6%95%B0%0A-%20%E7%94%A8%60%3Ddefault%60%E5%AE%9A%E4%B9%89%E7%9A%84%E6%9E%84%E9%80%A0%E6%9E%90%E6%9E%84%E5%87%BD%E6%95%B0%0A%23%23%23%20trivial%20class%0AThe%20standard%20defines%20a%20trivial%20class%20as%20follows%3A%0A%0AA%20trivially%20copyable%20class%20is%20a%20class%20that%3A%0A%0A-%20has%20no%20non-trivial%20copy%20constructors%20(12.8)%2C%0A-%20has%20no%20non-trivial%20move%20constructors%20(12.8)%2C%0A-%20has%20no%20non-trivial%20copy%20assignment%20operators%20(13.5.3%2C%2012.8)%2C%0A-%20has%20no%20non-trivial%20move%20assignment%20operators%20(13.5.3%2C%2012.8)%2C%20and%0A-%20has%20a%20trivial%20destructor%20(12.4).%0A%0AA%20trivial%20class%20is%20a%20class%20that%20has%20a%20trivial%20default%20constructor%20(12.1)%20and%20is%20trivially%20copyable.%0A%0A%5B%20Note%3A%20In%20particular%2C%20a%20trivially%20copyable%20or%20trivial%20class%20does%20not%20have%20virtual%20functions%20or%20virtual%20base%20classes.%20%5D%0A%E5%8F%A6%E5%A4%96trivial%20class%E6%98%AF%E9%80%92%E5%BD%92%E7%9A%84%EF%BC%8C%E5%8D%B3trivial%20class%E4%B8%8D%E8%83%BD%E6%9C%89%E9%9D%9Etrivial%20class%E7%9A%84%E9%9D%9Estatic%E6%88%90%E5%91%98%E3%80%82%0A%E7%94%A8%E6%A8%A1%E7%89%88%5Bstd%3A%3Ais_trivial%5D(https%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Ftypes%2Fis_trivial)%E6%9D%A5%E6%B5%8B%E8%AF%95%0A%23%23%20standard%20layout%0AA%20standard-layout%20class%20is%20a%20class%20that%3A%0A%0A-%20has%20no%20non-static%20data%20members%20of%20type%20non-standard-layout%20class%20(or%20array%20of%20such%20types)%20or%20reference%2C%0A%0A-%20has%20no%20virtual%20functions%20(10.3)%20and%20no%20virtual%20base%20classes%20(10.1)%2C%0A%0A-%20has%20the%20same%20access%20control%20(Clause%2011)%20for%20all%20non-static%20data%20members%2C%0A%0A-%20has%20no%20non-standard-layout%20base%20classes%2C%0A%0A-%20either%20has%20no%20non-static%20data%20members%20in%20the%20most%20derived%20class%20and%20at%20most%20one%20base%20class%20with%20non-static%20data%20members%2C%20or%20has%20no%20base%20classes%20with%20non-static%20data%20members%2C%20(%E8%A6%81%E4%B9%88%E7%BB%88%E7%82%B9%E7%B1%BB%E6%B2%A1%E6%9C%89%E9%9D%9E%E9%9D%99%E6%80%81%E6%88%90%E5%91%98%EF%BC%8C%E5%B9%B6%E4%B8%94%E5%8F%AA%E6%9C%89%E4%B8%80%E4%B8%AA%E5%9F%BA%E7%B1%BB%E6%9C%89%E9%9D%9E%E9%9D%99%E6%80%81%E6%88%90%E5%91%98%EF%BC%9B%E8%A6%81%E4%B9%88%E6%B2%A1%E6%9C%89%E5%9F%BA%E7%B1%BB%E6%9C%89%E9%9D%9E%E9%9D%99%E6%80%81%E6%88%90%E5%91%98)%EF%BC%8Cand%0A%0A-%20has%20no%20base%20classes%20of%20the%20same%20type%20as%20the%20first%20non-static%20data%20member.%0A%0AA%20standard-layout%20struct%20is%20a%20standard-layout%20class%20defined%20with%20the%20class-key%20struct%20or%20the%20class-key%20class.%0A%0AA%20standard-layout%20union%20is%20a%20standard-layout%20class%20defined%20with%20the%20class-key%20union.%0A%0A%5B%20Note%3A%20Standard-layout%20classes%20are%20useful%20for%20communicating%20with%20code%20written%20in%20other%20programming%20languages.%20Their%20layout%20is%20specified%20in%209.2.%5D%0A%0A%E6%A0%87%E5%87%86%E5%86%85%E5%AD%98%E5%88%86%E5%B8%83%EF%BC%8C%E7%A1%AE%E4%BF%9D%E5%AF%B9%E8%B1%A1%E5%86%85%E5%AD%98%E5%92%8CC%E8%AF%AD%E8%A8%80%E7%9A%84%E7%BB%93%E6%9E%84%E4%BD%93%E5%86%85%E5%AD%98%E5%88%86%E5%B8%83%E5%AE%8C%E5%85%A8%E4%B8%80%E8%87%B4%E3%80%82%E4%BD%BF%E5%BE%97POD%E5%8F%98%E9%87%8F%E5%85%B7%E5%A4%87%E4%BA%86C%E5%85%BC%E5%AE%B9%E6%80%A7%E3%80%82%0A%E7%94%A8%E6%A8%A1%E7%89%88%5Bstd%3A%3Ais_standard_layout%5D(https%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Ftypes%2Fis_standard_layout)%E5%8F%AF%E4%BB%A5%E6%B5%8B%E8%AF%95%0A%0A%23%20%E6%80%BB%E7%BB%93%0A%E7%94%A8%5Bstd%3A%3Ais_pod%5D(https%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Ftypes%2Fis_pod)%E6%9D%A5%E6%B5%8B%E8%AF%95%E4%BD%A0%E7%9A%84%E7%B1%BB%E5%90%A7%E3%80%82%0A%23%20%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE%0A1.%20%5BWhat%20are%20Aggregates%20and%20PODs%20and%20how%2Fwhy%20are%20they%20special%3F%5D(https%3A%2F%2Fstackoverflow.com%2Fquestions%2F4178175%2Fwhat-are-aggregates-and-pods-and-how-why-are-they-special)%0A2.%20%5BC%2B%2B%E5%AF%B9%E8%B1%A1%E6%A8%A1%E5%9E%8B%EF%BC%88%E4%B8%89%EF%BC%89POD%5D(https%3A%2F%2Ffuzhe1989.github.io%2F2018%2F03%2F15%2Fcpp-object-model-pod%2F)

C++11的列表初始化

在C语言和C++98/03中,大括号可以用来初始化数组,例如:

int a[] = {1, 2, 3};
int b[4] = {1, 2, 3, 4}; // 如果个数不足的,用0初始化

C++11将这类大括号初始化,扩展到自定义类型,但需要满足一定的条件,否则会编译报错。

参考C++11新特性之列表初始化、POD、聚合类

  1. C++98/03标准中对于普通数组和POD类型可以直接使用列表初始化;
  2. C++11标准中对于普通数组和聚合类型可以直接使用列表初始化;
  3. C++11标准中对于非聚合类型可以通过自定义构造函数的方式使用列表初始化。

C++11新特性之列表初始化提到非聚合类型不能使用列表初始化是不对的。实验证明,不论是不是聚合类型,均可以采用列表初始化。

class A {
	public:
		A(int a1) {}
		A(std::initializer_list<int> l) {}
	private:
		int a {12};
};
int main()
{
	A a = {123};
    ...
}

首先声明A a={123}或者A a{123}这两种构造方法是一致的。
其次,对于这种构造方法,编译器会先尝试用A(std::initializer_list<int> l)去匹配,如果不成功,则会尝试A(int),如果这两种构造函数都未定义,就会编译报错。
另外,成员变量也可以采用就地初始化, 虽然这会导致类成为非聚合类,但并不妨碍其采用列表初始化方法。使用虚函数,有基类的效果都是一样的,不影响列表初始化方法的使用。

C++11中的几种初始化方法

  1. 就地初始化
class A {
	private:
		int a1 {12};
        double a2 = {12.0};
        float a3 = 12.0
        B b{123}
        C c = {123};
};
  1. 构造函数初始化列表
class A {
    public:
        A() : a(123), b(456) {}
	private:
        int a;
        int b;
};
  1. 列表初始化
class A {
    public:
        A(int, int) {}
        A(std::initializer_list<int, int>) {}
	private:
        int a;
        int b;
};
void main ()
{
    // 优先匹配A(std::initializer_list<int, int>)
    // 再匹配A(int, int)
    // 否则报错
    A a {123, 456};
}
  • 就地初始化会最先得到执行,构造函数初始化列表会覆盖就地初始化的值
  • 如果采用初始化列表,即a{...}初始化,std::initializer_list<T>的构造函数会优先得到执行
  • 如果采用原生构造函数,即a(int)初始化,A(init)优先得到执行

什么是initializer-list

摘录C++11新特性之列表初始化-初始化列表

  1. 它是一个轻量级的容器类型,内部定义了迭代器iterator等容器必须的一些概念。
  2. initialzer-list<T>来说,它可以接受任意长度的初始化列表,但是元素必须是要相同的或者可以转换为T类型的。
  3. 三个成员接口,begin(),end(),size(),其中size()返回initialzer-list的长度。
  4. 能被整体的初始化和赋值,遍历只能通过begin和end迭代器来,遍历取得的数据是可读的,是不能对单个进行修改的。

注意一:
initialzer-list<T>保存的是T类型的引用,并不对T类型的数据进行拷贝,因此需要注意变量的生存期

std::initializer_list<int> func(void)
{
    return{ 2, 3 };
}
void main()
{
    auto c = func();
    for (auto it = c.begin(); it != c.end(); it++)
		std::cout << it - c.begin() << ":" << (*it) << std::endl;
}

此处打印是乱的。因为func返回的是右值引用,在退出函数后失效。

注意二:
列表初始化防止类型收窄

int a = 1.1; //OK
int b{ 1.1 }; //error
 
float f1 = 1e40; //OK, 科学计数法10^40
float f2{ 1e40 }; //error
 
const int x = 1024, y = 1;
char c = x; //OK
char d{ x };//error
char e = y;//error
char f{ y };//error

参考文献

initializer_list - cppreference.com

C++11新特性之列表初始化

C++11新特性之列表初始化、POD、聚合类

%23%20C%2B%2B11%E7%9A%84%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%0A%E5%9C%A8C%E8%AF%AD%E8%A8%80%E5%92%8CC%2B%2B98%2F03%E4%B8%AD%EF%BC%8C%E5%A4%A7%E6%8B%AC%E5%8F%B7%E5%8F%AF%E4%BB%A5%E7%94%A8%E6%9D%A5%E5%88%9D%E5%A7%8B%E5%8C%96%E6%95%B0%E7%BB%84%EF%BC%8C%E4%BE%8B%E5%A6%82%EF%BC%9A%0A%60%60%60c%0Aint%20a%5B%5D%20%3D%20%7B1%2C%202%2C%203%7D%3B%0Aint%20b%5B4%5D%20%3D%20%7B1%2C%202%2C%203%2C%204%7D%3B%20%2F%2F%20%E5%A6%82%E6%9E%9C%E4%B8%AA%E6%95%B0%E4%B8%8D%E8%B6%B3%E7%9A%84%EF%BC%8C%E7%94%A80%E5%88%9D%E5%A7%8B%E5%8C%96%0A%60%60%60%0A%0AC%2B%2B11%E5%B0%86%E8%BF%99%E7%B1%BB%E5%A4%A7%E6%8B%AC%E5%8F%B7%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%8C%E6%89%A9%E5%B1%95%E5%88%B0%E8%87%AA%E5%AE%9A%E4%B9%89%E7%B1%BB%E5%9E%8B%EF%BC%8C%E4%BD%86%E9%9C%80%E8%A6%81%E6%BB%A1%E8%B6%B3%E4%B8%80%E5%AE%9A%E7%9A%84%E6%9D%A1%E4%BB%B6%EF%BC%8C%E5%90%A6%E5%88%99%E4%BC%9A%E7%BC%96%E8%AF%91%E6%8A%A5%E9%94%99%E3%80%82%0A%3E%E5%8F%82%E8%80%83%5BC%2B%2B11%E6%96%B0%E7%89%B9%E6%80%A7%E4%B9%8B%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E3%80%81POD%E3%80%81%E8%81%9A%E5%90%88%E7%B1%BB%5D(https%3A%2F%2Fblog.csdn.net%2FJinhuCheng%2Farticle%2Fdetails%2F107330983)%0A%3E%201.%20C%2B%2B98%2F03%E6%A0%87%E5%87%86%E4%B8%AD%E5%AF%B9%E4%BA%8E%E6%99%AE%E9%80%9A%E6%95%B0%E7%BB%84%E5%92%8CPOD%E7%B1%BB%E5%9E%8B%E5%8F%AF%E4%BB%A5%E7%9B%B4%E6%8E%A5%E4%BD%BF%E7%94%A8%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%9B%0A%3E%202.%20C%2B%2B11%E6%A0%87%E5%87%86%E4%B8%AD%E5%AF%B9%E4%BA%8E%E6%99%AE%E9%80%9A%E6%95%B0%E7%BB%84%E5%92%8C%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%E5%8F%AF%E4%BB%A5%E7%9B%B4%E6%8E%A5%E4%BD%BF%E7%94%A8%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%9B%0A%3E%203.%20C%2B%2B11%E6%A0%87%E5%87%86%E4%B8%AD%E5%AF%B9%E4%BA%8E%E9%9D%9E%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%E8%87%AA%E5%AE%9A%E4%B9%89%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E7%9A%84%E6%96%B9%E5%BC%8F%E4%BD%BF%E7%94%A8%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E3%80%82%0A%5BC%2B%2B11%E6%96%B0%E7%89%B9%E6%80%A7%E4%B9%8B%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%5D(https%3A%2F%2Fblog.csdn.net%2Fhailong0715%2Farticle%2Fdetails%2F54018002)%E6%8F%90%E5%88%B0%E9%9D%9E%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%E4%B8%8D%E8%83%BD%E4%BD%BF%E7%94%A8%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E6%98%AF%E4%B8%8D%E5%AF%B9%E7%9A%84%E3%80%82%E5%AE%9E%E9%AA%8C%E8%AF%81%E6%98%8E%EF%BC%8C%E4%B8%8D%E8%AE%BA%E6%98%AF%E4%B8%8D%E6%98%AF%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%EF%BC%8C%E5%9D%87%E5%8F%AF%E4%BB%A5%E9%87%87%E7%94%A8%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E3%80%82%0A%60%60%60c%2B%2B%0Aclass%20A%20%7B%0A%09public%3A%0A%09%09A(int%20a1)%20%7B%7D%0A%09%09A(std%3A%3Ainitializer_list%3Cint%3E%20l)%20%7B%7D%0A%09private%3A%0A%09%09int%20a%20%7B12%7D%3B%0A%7D%3B%0Aint%20main()%0A%7B%0A%09A%20a%20%3D%20%7B123%7D%3B%0A%20%20%20%20...%0A%7D%0A%60%60%60%0A%E9%A6%96%E5%85%88%E5%A3%B0%E6%98%8E%60A%20a%3D%7B123%7D%60%E6%88%96%E8%80%85%60A%20a%7B123%7D%60%E8%BF%99%E4%B8%A4%E7%A7%8D%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%E6%98%AF%E4%B8%80%E8%87%B4%E7%9A%84%E3%80%82%0A%E5%85%B6%E6%AC%A1%EF%BC%8C%E5%AF%B9%E4%BA%8E%E8%BF%99%E7%A7%8D%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%EF%BC%8C%E7%BC%96%E8%AF%91%E5%99%A8%E4%BC%9A%E5%85%88%E5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80%82%0A%23%23%20C%2B%2B11%E4%B8%AD%E7%9A%84%E5%87%A0%E7%A7%8D%E5%88%9D%E5%A7%8B%E5%8C%96%E6%96%B9%E6%B3%95%0A1.%20%E5%B0%B1%E5%9C%B0%E5%88%9D%E5%A7%8B%E5%8C%96%0A%60%60%60c%2B%2B%0Aclass%20A%20%7B%0A%09private%3A%0A%09%09int%20a1%20%7B12%7D%3B%0A%20%20%20%20%20%20%20%20double%20a2%20%3D%20%7B12.0%7D%3B%0A%20%20%20%20%20%20%20%20float%20a3%20%3D%2012.0%0A%20%20%20%20%20%20%20%20B%20b%7B123%7D%0A%20%20%20%20%20%20%20%20C%20c%20%3D%20%7B123%7D%3B%0A%7D%3B%0A%60%60%60%0A2.%20%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E5%88%9D%E5%A7%8B%E5%8C%96%E5%88%97%E8%A1%A8%0A%60%60%60c%2B%2B%0Aclass%20A%20%7B%0A%20%20%20%20public%3A%0A%20%20%20%20%20%20%20%20A()%20%3A%20a(123)%2C%20b(456)%20%7B%7D%0A%09private%3A%0A%20%20%20%20%20%20%20%20int%20a%3B%0A%20%20%20%20%20%20%20%20int%20b%3B%0A%7D%3B%0A%60%60%60%0A3.%20%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%0A%60%60%60c%2B%2B%0Aclass%20A%20%7B%0A%20%20%20%20public%3A%0A%20%20%20%20%20%20%20%20A(int%2C%20int)%20%7B%7D%0A%20%20%20%20%20%20%20%20A(std%3A%3Ainitializer_list%3Cint%2C%20int%3E)%20%7B%7D%0A%09private%3A%0A%20%20%20%20%20%20%20%20int%20a%3B%0A%20%20%20%20%20%20%20%20int%20b%3B%0A%7D%3B%0Avoid%20main%20()%0A%7B%0A%20%20%20%20%2F%2F%20%E4%BC%98%E5%85%88%E5%8C%B9%E9%85%8DA(std%3A%3Ainitializer_list%3Cint%2C%20int%3E)%0A%20%20%20%20%2F%2F%20%E5%86%8D%E5%8C%B9%E9%85%8DA(int%2C%20int)%0A%20%20%20%20%2F%2F%20%E5%90%A6%E5%88%99%E6%8A%A5%E9%94%99%0A%20%20%20%20A%20a%20%7B123%2C%20456%7D%3B%0A%7D%0A%60%60%60%0A-%20%E5%B0%B1%E5%9C%B0%E5%88%9D%E5%A7%8B%E5%8C%96%E4%BC%9A%E6%9C%80%E5%85%88%E5%BE%97%E5%88%B0%E6%89%A7%E8%A1%8C%EF%BC%8C%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E5%88%9D%E5%A7%8B%E5%8C%96%E5%88%97%E8%A1%A8%E4%BC%9A%E8%A6%86%E7%9B%96%E5%B0%B1%E5%9C%B0%E5%88%9D%E5%A7%8B%E5%8C%96%E7%9A%84%E5%80%BC%0A-%20%E5%A6%82%E6%9E%9C%E9%87%87%E7%94%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E5%88%97%E8%A1%A8%EF%BC%8C%E5%8D%B3%60a%7B...%7D%60%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%8C%60std%3A%3Ainitializer_list%3CT%3E%60%E7%9A%84%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E4%BC%9A%E4%BC%98%E5%85%88%E5%BE%97%E5%88%B0%E6%89%A7%E8%A1%8C%0A-%20%E5%A6%82%E6%9E%9C%E9%87%87%E7%94%A8%E5%8E%9F%E7%94%9F%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%EF%BC%8C%E5%8D%B3%60a(int)%60%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%8C%60A(init)%60%E4%BC%98%E5%85%88%E5%BE%97%E5%88%B0%E6%89%A7%E8%A1%8C%0A%23%20%E4%BB%80%E4%B9%88%E6%98%AFinitializer-list%0A%3E**%E6%91%98%E5%BD%95%5BC%2B%2B11%E6%96%B0%E7%89%B9%E6%80%A7%E4%B9%8B%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%5D(https%3A%2F%2Fblog.csdn.net%2Fhailong0715%2Farticle%2Fdetails%2F54018002)**-%E5%88%9D%E5%A7%8B%E5%8C%96%E5%88%97%E8%A1%A8%0A%3E1.%20%E5%AE%83%E6%98%AF%E4%B8%80%E4%B8%AA%E8%BD%BB%E9%87%8F%E7%BA%A7%E7%9A%84%E5%AE%B9%E5%99%A8%E7%B1%BB%E5%9E%8B%EF%BC%8C%E5%86%85%E9%83%A8%E5%AE%9A%E4%B9%89%E4%BA%86%E8%BF%AD%E4%BB%A3%E5%99%A8iterator%E7%AD%89%E5%AE%B9%E5%99%A8%E5%BF%85%E9%A1%BB%E7%9A%84%E4%B8%80%E4%BA%9B%E6%A6%82%E5%BF%B5%E3%80%82%20%0A%3E2.%20initialzer-list%3CT%3E%E6%9D%A5%E8%AF%B4%EF%BC%8C%E5%AE%83%E5%8F%AF%E4%BB%A5%E6%8E%A5%E5%8F%97%E4%BB%BB%E6%84%8F%E9%95%BF%E5%BA%A6%E7%9A%84%E5%88%9D%E5%A7%8B%E5%8C%96%E5%88%97%E8%A1%A8%EF%BC%8C%E4%BD%86%E6%98%AF%E5%85%83%E7%B4%A0%E5%BF%85%E9%A1%BB%E6%98%AF%E8%A6%81%E7%9B%B8%E5%90%8C%E7%9A%84%E6%88%96%E8%80%85%E5%8F%AF%E4%BB%A5%E8%BD%AC%E6%8D%A2%E4%B8%BAT%E7%B1%BB%E5%9E%8B%E7%9A%84%E3%80%82%20%20%0A%3E3.%20%E4%B8%89%E4%B8%AA%E6%88%90%E5%91%98%E6%8E%A5%E5%8F%A3%EF%BC%8Cbegin()%2Cend()%2Csize()%2C%E5%85%B6%E4%B8%ADsize()%E8%BF%94%E5%9B%9Einitialzer-list%E7%9A%84%E9%95%BF%E5%BA%A6%E3%80%82%20%20%0A%3E4.%20%E8%83%BD%E8%A2%AB%E6%95%B4%E4%BD%93%E7%9A%84%E5%88%9D%E5%A7%8B%E5%8C%96%E5%92%8C%E8%B5%8B%E5%80%BC%EF%BC%8C%E9%81%8D%E5%8E%86%E5%8F%AA%E8%83%BD%E9%80%9A%E8%BF%87begin%E5%92%8Cend%E8%BF%AD%E4%BB%A3%E5%99%A8%E6%9D%A5%EF%BC%8C%E9%81%8D%E5%8E%86%E5%8F%96%E5%BE%97%E7%9A%84%E6%95%B0%E6%8D%AE%E6%98%AF%E5%8F%AF%E8%AF%BB%E7%9A%84%EF%BC%8C%E6%98%AF%E4%B8%8D%E8%83%BD%E5%AF%B9%E5%8D%95%E4%B8%AA%E8%BF%9B%E8%A1%8C%E4%BF%AE%E6%94%B9%E7%9A%84%E3%80%82%20%20%0A%0A%E6%B3%A8%E6%84%8F%E4%B8%80%EF%BC%9A%0Ainitialzer-list%3CT%3E%E4%BF%9D%E5%AD%98%E7%9A%84%E6%98%AFT%E7%B1%BB%E5%9E%8B%E7%9A%84%E5%BC%95%E7%94%A8%EF%BC%8C%E5%B9%B6%E4%B8%8D%E5%AF%B9T%E7%B1%BB%E5%9E%8B%E7%9A%84%E6%95%B0%E6%8D%AE%E8%BF%9B%E8%A1%8C%E6%8B%B7%E8%B4%9D%EF%BC%8C%E5%9B%A0%E6%AD%A4%E9%9C%80%E8%A6%81%E6%B3%A8%E6%84%8F%E5%8F%98%E9%87%8F%E7%9A%84%E7%94%9F%E5%AD%98%E6%9C%9F%0A%60%60%60c%2B%2B%0Astd%3A%3Ainitializer_list%3Cint%3E%20func(void)%0A%7B%0A%20%20%20%20return%7B%202%2C%203%20%7D%3B%0A%7D%0Avoid%20main()%0A%7B%0A%20%20%20%20auto%20c%20%3D%20func()%3B%0A%20%20%20%20for%20(auto%20it%20%3D%20c.begin()%3B%20it%20!%3D%20c.end()%3B%20it%2B%2B)%0A%09%09std%3A%3Acout%20%3C%3C%20it%20-%20c.begin()%20%3C%3C%20%22%3A%22%20%3C%3C%20(*it)%20%3C%3C%20std%3A%3Aendl%3B%0A%7D%0A%60%60%60%0A%E6%AD%A4%E5%A4%84%E6%89%93%E5%8D%B0%E6%98%AF%E4%B9%B1%E7%9A%84%E3%80%82%E5%9B%A0%E4%B8%BAfunc%E8%BF%94%E5%9B%9E%E7%9A%84%E6%98%AF%E5%8F%B3%E5%80%BC%E5%BC%95%E7%94%A8%EF%BC%8C%E5%9C%A8%E9%80%80%E5%87%BA%E5%87%BD%E6%95%B0%E5%90%8E%E5%A4%B1%E6%95%88%E3%80%82%0A%0A%E6%B3%A8%E6%84%8F%E4%BA%8C%EF%BC%9A%0A%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E9%98%B2%E6%AD%A2%E7%B1%BB%E5%9E%8B%E6%94%B6%E7%AA%84%0A%60%60%60c%2B%2B%0Aint%20a%20%3D%201.1%3B%20%2F%2FOK%0Aint%20b%7B%201.1%20%7D%3B%20%2F%2Ferror%0A%20%0Afloat%20f1%20%3D%201e40%3B%20%2F%2FOK%2C%20%E7%A7%91%E5%AD%A6%E8%AE%A1%E6%95%B0%E6%B3%9510%5E40%0Afloat%20f2%7B%201e40%20%7D%3B%20%2F%2Ferror%0A%20%0Aconst%20int%20x%20%3D%201024%2C%20y%20%3D%201%3B%0Achar%20c%20%3D%20x%3B%20%2F%2FOK%0Achar%20d%7B%20x%20%7D%3B%2F%2Ferror%0Achar%20e%20%3D%20y%3B%2F%2Ferror%0Achar%20f%7B%20y%20%7D%3B%2F%2Ferror%0A%60%60%60%0A%0A%0A%23%20%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE%0A%5Binitializer_list%20-%20cppreference.com%5D(https%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Futility%2Finitializer_list)%0A%5BC%2B%2B11%E6%96%B0%E7%89%B9%E6%80%A7%E4%B9%8B%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%5D(https%3A%2F%2Fblog.csdn.net%2Fhailong0715%2Farticle%2Fdetails%2F54018002)%0A%5BC%2B%2B11%E6%96%B0%E7%89%B9%E6%80%A7%E4%B9%8B%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E3%80%81POD%E3%80%81%E8%81%9A%E5%90%88%E7%B1%BB%5D(https%3A%2F%2Fblog.csdn.net%2FJinhuCheng%2Farticle%2Fdetails%2F107330983)

在Linux中,一个进程拉起另一个进程的流程大致如下:

PHN2ZyBpZD0iZHQ4bnhmMW9lbTQiIHdpZHRoPSIxMDAlIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHN0eWxlPSJtYXgtd2lkdGg6IDYxMC43OTY4NzVweDsiIHZpZXdCb3g9IjAgMCA2MTAuNzk2ODc1IDEzOC41NjI1Ij48c3R5bGU+CgoKI2R0OG54ZjFvZW00IC5sYWJlbCB7CiAgZm9udC1mYW1pbHk6ICd0cmVidWNoZXQgbXMnLCB2ZXJkYW5hLCBhcmlhbDsKICBjb2xvcjogIzMzMzsgfQoKI2R0OG54ZjFvZW00IC5ub2RlIHJlY3QsCiNkdDhueGYxb2VtNCAubm9kZSBjaXJjbGUsCiNkdDhueGYxb2VtNCAubm9kZSBlbGxpcHNlLAojZHQ4bnhmMW9lbTQgLm5vZGUgcG9seWdvbiB7CiAgZmlsbDogI0VDRUNGRjsKICBzdHJva2U6ICM5MzcwREI7CiAgc3Ryb2tlLXdpZHRoOiAxcHg7IH0KCiNkdDhueGYxb2VtNCAubm9kZS5jbGlja2FibGUgewogIGN1cnNvcjogcG9pbnRlcjsgfQoKI2R0OG54ZjFvZW00IC5hcnJvd2hlYWRQYXRoIHsKICBmaWxsOiAjMzMzMzMzOyB9CgojZHQ4bnhmMW9lbTQgLmVkZ2VQYXRoIC5wYXRoIHsKICBzdHJva2U6ICMzMzMzMzM7CiAgc3Ryb2tlLXdpZHRoOiAxLjVweDsgfQoKI2R0OG54ZjFvZW00IC5lZGdlTGFiZWwgewogIGJhY2tncm91bmQtY29sb3I6ICNlOGU4ZTg7IH0KCiNkdDhueGYxb2VtNCAuY2x1c3RlciByZWN0IHsKICBmaWxsOiAjZmZmZmRlICFpbXBvcnRhbnQ7CiAgc3Ryb2tlOiAjYWFhYT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Q8L3RzcGFuPjwvdGV4dD48L2c+PC9nPjwvZz48L2c+PC9nPjwvZz48L3N2Zz4=

最常见的就是通过shell终端执行命令。此场景下,/bin/bash就是这个parent process,而要执行的那个命令就是new process。
Linux有一些特性,可以使得创建出的进程比拉起的进程权限高。例如可执行文件配置了set-user-ID位,则拉起的进程就是root权限,而其父进程有可能是普通用户权限。如果可执行文件配置了file capability,则创建出的进程就具备了某些capability,如果父进程没有这些capability,则这也是一种权限放大的场景。
当发生这种权限放大的场景时,Linux的安全特性要求,此时子进程中的某些敏感环境变量会被清空,例如:LD_PRELOAD,LD_LIBRARY_PATH。由于这些环境变量都是从父进程继承过来的,如果不清空,则表明会使用高权限级别执行这些环境变量指定的可执行代码。

LD_LIBRARY_PATH

参考文献[1],ld.so搜索动态库的顺序如下:

  1. DT_PATH指定的库文件(deprecated)
  2. LD_LIBRARY_PATH指定的库文件
  3. DT_RUNPATH指定的库文件
  4. /etc/ld.so.cache这个二进制文件指定的库文件,该文件通过ldconfig命令生成
  5. In the default path /lib, and then /usr/lib. (On some 64-bit architectures, the default paths for 64-bit shared objects are /lib64, and then /usr/lib64.) If the binary was linked with the -z nodeflib linker option, this step is skipped.

所以针对LD_LIBRARY_PATH,除了第二条的方法失效,其他的都可以用。

LD_PRELOAD

那针对LD_PRELOAD,是不是就没法用呢?其实也不是。
在没有setcap以及set-user-ID的情况下,如果ld.so需要预加载一个库文件,指定方法在文献[1]中同样有描述:

  1. The LD_PRELOAD environment variable.
  2. The --preload command-line option when invoking the dynamic linker directly.
  3. The /etc/ld.so.preload file.

在secure-execution模式下,方法2和方法3均不受影响。方法1也仍然可以使用。但是需要一些特殊的设置,在[1]中也有描述。

In secure-execution mode, preload pathnames containing slashes are ignored. Furthermore, shared objects are preloaded only from the standard search directories and only if they have set-user-ID mode bit enabled (which is not typical).

综上,需要3点配置:

  • LD_PRELOAD环境变量指定的库文件不能包含斜线'/'
  • 库文件只会从标准路径下加载。这里标准路径可以参考LD_LIBRARY_PATH中的描述。注意,此时ld.so只会搜索标准路径,不会搜索通过其他手段配置的路径(如上一节描述的)。
  • 库文件必须使能了set-user-id位

示例代码

代码目录树:

[ben@localhost test]$ tree .
.
├── lib.c
├── libtest.so
├── main
├── main.c
├── test
└── test.c

main.c生成main可执行程序,test.c生成test可执行程序,lib.c生成libtest.so。

// main.c

#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

int main()
{
        pid_t pid = fork();
        if (pid == 0) {
                char *envp[] = {
                        "LD_PRELOAD=libtest.so",
                        // "LD_PRELOAD=./libtest.so",
                        NULL
                };
                char *argv[] = {
                        "test",
                        NULL
                };
                int err = execve("./test", argv, envp);
        }
        else {
                int status;
                wait(&status);
        }
        return 0;
}

// test.c
#include <stdio.h>
#include <stdlib.h>

int main ()
{
        const char *preload = getenv("LD_PRELOAD");
        printf("LD_PRELOAD = %s\n", preload);
        return 0;
}

// lib.c
#include <stdio.h>

static void func(void) __attribute__((constructor));
void func(void)
{
        printf("I'm libtest.so loaded\n");
}

在test可执行程序是普通的二进制时,输出为

[ben@localhost test]$ ./main
I'm libtest.so loaded
LD_PRELOAD = ./libtest.so

当test配置了capability以后:

[ben@localhost test]$ sudo setcap cap_net_admin,cap_net_raw=eip ./test
[ben@localhost test]$ ./main
LD_PRELOAD = (null)

可见LD_PRELOAD指定libtest.so未被加载,且LD_PRELOAD环境变量被清空了。

LD_PRELOAD不含斜线

[ben@localhost test]$ ./main
ERROR: ld.so: object 'libtest.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
LD_PRELOAD = (null)

LD_PRELOAD仍然被清空了,但ld.so似乎尝试去加载libtest.so了,但是没找着。

将libtest.so放入标准路径

如果没有配置set-user-id位:

[ben@localhost test]$ ./main
ERROR: ld.so: object 'libtest.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
LD_PRELOAD = (null)

仍然提示找不到。如果设置了set-user-id位:

[ben@localhost test]$ sudo chmod a+s /usr/lib64/libtest.so 
[ben@localhost test]$ ./main
I'm libtest.so loaded
LD_PRELOAD = (null)

在满足上一节提到的3个条件时,libteso.so就可以正常加载了。
看看如果放到/usr/lib下面会怎么样?

[ben@localhost test]$ ls /usr/lib/libtest.so -l
-rwsr-sr-x. 1 root root 8208 1月  24 19:48 /usr/lib/libtest.so
[ben@localhost test]$ ./main
ERROR: ld.so: object 'libtest.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
LD_PRELOAD = (null)

看看还是一样找不到。可见在x64平台上,/usr/lib并非标准路径,而/usr/lib64以及/lib64才是

参考文献

[1] ld.so(8) — Linux manual page

[2] Stackoverflow - Does using linux capabilities disables LD_PRELOAD

%E5%9C%A8Linux%E4%B8%AD%EF%BC%8C%E4%B8%80%E4%B8%AA%E8%BF%9B%E7%A8%8B%E6%8B%89%E8%B5%B7%E5%8F%A6%E4%B8%80%E4%B8%AA%E8%BF%9B%E7%A8%8B%E7%9A%84%E6%B5%81%E7%A8%8B%E5%A4%A7%E8%87%B4%E5%A6%82%E4%B8%8B%EF%BC%9A%0A%60%60%60mermaid%0Agraph%20LR%0AF%5Bparent%20process%5D%20--%3E%20A%5Bstart%5D%0AA%20--fork--%3E%20B%5Bchild%5D%0AA%20--%3E%20C%5Bwait%5D%0AB%20--exec--%3E%20D%5Bnew%20process%5D%0AD%20--%3E%20E%5Bend%5D%0AC%20--%3E%20E%0A%60%60%60%0A%E6%9C%80%E5%B8%B8%E8%A7%81%E7%9A%84%E5%B0%B1%E6%98%AF%E9%80%9A%E8%BF%87shell%E7%BB%88%E7%AB%AF%E6%89%A7%E8%A1%8C%E5%91%BD%E4%BB%A4%E3%80%82%E6%AD%A4%E5%9C%BA%E6%99%AF%E4%B8%8B%EF%BC%8C%2Fbin%2Fbash%E5%B0%B1%E6%98%AF%E8%BF%99%E4%B8%AAparent%20process%EF%BC%8C%E8%80%8C%E8%A6%81%E6%89%A7%E8%A1%8C%E7%9A%84%E9%82%A3%E4%B8%AA%E5%91%BD%E4%BB%A4%E5%B0%B1%E6%98%AFnew%20process%E3%80%82%0ALinux%E6%9C%89%E4%B8%80%E4%BA%9B%E7%89%B9%E6%80%A7%EF%BC%8C%E5%8F%AF%E4%BB%A5%E4%BD%BF%E5%BE%97%E5%88%9B%E5%BB%BA%E5%87%BA%E7%9A%84%E8%BF%9B%E7%A8%8B%E6%AF%94%E6%8B%89%E8%B5%B7%E7%9A%84%E8%BF%9B%E7%A8%8B%E6%9D%83%E9%99%90%E9%AB%98%E3%80%82%E4%BE%8B%E5%A6%82%E5%8F%AF%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6%E9%85%8D%E7%BD%AE%E4%BA%86set-user-ID%E4%BD%8D%EF%BC%8C%E5%88%99%E6%8B%89%E8%B5%B7%E7%9A%84%E8%BF%9B%E7%A8%8B%E5%B0%B1%E6%98%AFroot%E6%9D%83%E9%99%90%EF%BC%8C%E8%80%8C%E5%85%B6%E7%88%B6%E8%BF%9B%E7%A8%8B%E6%9C%89%E5%8F%AF%E8%83%BD%E6%98%AF%E6%99%AE%E9%80%9A%E7%94%A8%E6%88%B7%E6%9D%83%E9%99%90%E3%80%82%E5%A6%82%E6%9E%9C%E5%8F%AF%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6%E9%85%8D%E7%BD%AE%E4%BA%86file%20capability%EF%BC%8C%E5%88%99%E5%88%9B%E5%BB%BA%E5%87%BA%E7%9A%84%E8%BF%9B%E7%A8%8B%E5%B0%B1%E5%85%B7%E5%A4%87%E4%BA%86%E6%9F%90%E4%BA%9Bcapability%EF%BC%8C%E5%A6%82%E6%9E%9C%E7%88%B6%E8%BF%9B%E7%A8%8B%E6%B2%A1%E6%9C%89%E8%BF%99%E4%BA%9Bcapability%EF%BC%8C%E5%88%99%E8%BF%99%E4%B9%9F%E6%98%AF%E4%B8%80%E7%A7%8D%E6%9D%83%E9%99%90%E6%94%BE%E5%A4%A7%E7%9A%84%E5%9C%BA%E6%99%AF%E3%80%82%0A%E5%BD%93%E5%8F%91%E7%94%9F%E8%BF%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%E5%AE%9A%E7%9A%84%E5%BA%93%E6%96%87%E4%BB%B6%EF%BC%88deprecated%EF%BC%89%0A2.%20LD_LIBRARY_PATH%E6%8C%87%E5%AE%9A%E7%9A%84%E5%BA%93%E6%96%87%E4%BB%B6%0A3.%20DT_RUNPATH%E6%8C%87%E5%AE%9A%E7%9A%84%E5%BA%93%E6%96%87%E4%BB%B6%0A4.%20%2Fetc%2Fld.so.cache%E8%BF%99%E4%B8%AA%E4%BA%8C%E8%BF%9B%E5%88%B6%E6%96%87%E4%BB%B6%E6%8C%87%E5%AE%9A%E7%9A%84%E5%BA%93%E6%96%87%E4%BB%B6%EF%BC%8C%E8%AF%A5%E6%96%87%E4%BB%B6%E9%80%9A%E8%BF%87ldconfig%E5%91%BD%E4%BB%A4%E7%94%9F%E6%88%90%0A5.%20In%20the%20default%20path%20%2Flib%2C%20and%20then%20%2Fusr%2Flib.%20%20(On%20some%2064-bit%20architectures%2C%20the%20default%20paths%20for%2064-bit%20shared%20objects%20are%20%2Flib64%2C%20and%20then%20%2Fusr%2Flib64.)%20%20If%20the%20binary%20was%20linked%20with%20the%20-z%20nodeflib%20linker%20option%2C%20this%20step%20is%20skipped.%0A%0A%E6%89%80%E4%BB%A5%E9%92%88%E5%AF%B9LD_LIBRARY_PATH%EF%BC%8C%E9%99%A4%E4%BA%86%E7%AC%AC%E4%BA%8C%E6%9D%A1%E7%9A%84%E6%96%B9%E6%B3%95%E5%A4%B1%E6%95%88%EF%BC%8C%E5%85%B6%E4%BB%96%E7%9A%84%E9%83%BD%E5%8F%AF%E4%BB%A5%E7%94%A8%E3%80%82%0A%0A%23%20LD_PRELOAD%0A%E9%82%A3%E9%92%88%E5%AF%B9LD_PRELOAD%EF%BC%8C%E6%98%AF%E4%B8%8D%E6%98%AF%E5%B0%B1%E6%B2%A1%E6%B3%95%E7%94%A8%E5%91%A2%EF%BC%9F%E5%85%B6%E5%AE%9E%E4%B9%9F%E4%B8%8D%E6%98%AF%E3%80%82%0A%E5%9C%A8%E6%B2%A1%E6%9C%89setcap%E4%BB%A5%E5%8F%8Aset-user-ID%E7%9A%84%E6%83%85%E5%86%B5%E4%B8%8B%EF%BC%8C%E5%A6%82%E6%9E%9Cld.so%E9%9C%80%E8%A6%81%E9%A2%84%E5%8A%A0%E8%BD%BD%E4%B8%80%E4%B8%AA%E5%BA%93%E6%96%87%E4%BB%B6%EF%BC%8C%E6%8C%87%E5%AE%9A%E6%96%B9%E6%B3%95%E5%9C%A8%E6%96%87%E7%8C%AE%5B1%5D%E4%B8%AD%E5%90%8C%E6%A0%B7%E6%9C%89%E6%8F%8F%E8%BF%B0%EF%BC%9A%0A1.%20The%20%60LD_PRELOAD%60%20environment%20variable.%0A2.%20The%20%60--preload%60%20command-line%20option%20when%20invoking%20the%20dynamic%20linker%20directly.%0A3.%20The%20%60%2Fetc%2Fld.so.preload%60%20file.%0A%0A%E5%9C%A8secure-execution%E6%A8%A1%E5%BC%8F%E4%B8%8B%EF%BC%8C%E6%96%B9%E6%B3%952%E5%92%8C%E6%96%B9%E6%B3%953%E5%9D%87%E4%B8%8D%E5%8F%97%E5%BD%B1%E5%93%8D%E3%80%82%E6%96%B9%E6%B3%951%E4%B9%9F%E4%BB%8D%E7%84%B6%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8%E3%80%82%E4%BD%86%E6%98%AF%E9%9C%80%E8%A6%81%E4%B8%80%E4%BA%9B%E7%89%B9%E6%AE%8A%E7%9A%84%E8%AE%BE%E7%BD%AE%EF%BC%8C%E5%9C%A8%5B1%5D%E4%B8%AD%E4%B9%9F%E6%9C%89%E6%8F%8F%E8%BF%B0%E3%80%82%0A%3E%20In%20secure-execution%20mode%2C%20**preload%20pathnames%20containing%20slashes%20are%20ignored**.%20%20Furthermore%2C%20shared%20objects%20are%20preloaded%20**only%20from%20the%20standard%20search%20directories**%20and%20only%20if%20**they%20have%20set-user-ID%20mode%20bit%20enabled**%20(which%20is%20not%20typical).%0A%0A%E7%BB%BC%E4%B8%8A%EF%BC%8C%E9%9C%80%E8%A6%813%E7%82%B9%E9%85%8D%E7%BD%AE%EF%BC%9A%0A-%20LD_PRELOAD%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E6%8C%87%E5%AE%9A%E7%9A%84%E5%BA%93%E6%96%87%E4%BB%B6%E4%B8%8D%E8%83%BD%E5%8C%85%E5%90%AB%E6%96%9C%E7%BA%BF'%2F'%0A-%20%E5%BA%93%E6%96%87%E4%BB%B6%E5%8F%AA%E4%BC%9A%E4%BB%8E%E6%A0%87%E5%87%86%E8%B7%AF%E5%BE%84%E4%B8%8B%E5%8A%A0%E8%BD%BD%E3%80%82%E8%BF%99%E9%87%8C%E6%A0%87%E5%87%86%E8%B7%AF%E5%BE%84%E5%8F%AF%E4%BB%A5%E5%8F%82%E8%80%83LD_LIBRARY_PATH%E4%B8%AD%E7%9A%84%E6%8F%8F%E8%BF%B0%E3%80%82%E6%B3%A8%E6%84%8F%EF%BC%8C%E6%AD%A4%E6%97%B6ld.so%E5%8F%AA%E4%BC%9A%E6%90%9C%E7%B4%A2%E6%A0%87%E5%87%86%E8%B7%AF%E5%BE%84%EF%BC%8C%E4%B8%8D%E4%BC%9A%E6%90%9C%E7%B4%A2%E9%80%9A%E8%BF%87%E5%85%B6%E4%BB%96%E6%89%8B%E6%AE%B5%E9%85%8D%E7%BD%AE%E7%9A%84%E8%B7%AF%E5%BE%84%EF%BC%88%E5%A6%82%E4%B8%8A%E4%B8%80%E8%8A%82%E6%8F%8F%E8%BF%B0%E7%9A%84%EF%BC%89%E3%80%82%0A-%20%E5%BA%93%E6%96%87%E4%BB%B6%E5%BF%85%E9%A1%BB%E4%BD%BF%E8%83%BD%E4%BA%86set-user-id%E4%BD%8D%0A%0A%23%20%E7%A4%BA%E4%BE%8B%E4%BB%A3%E7%A0%81%0A%E4%BB%A3%E7%A0%81%E7%9B%AE%E5%BD%95%E6%A0%91%EF%BC%9A%0A%60%60%60%0A%5Bben%40localhost%20test%5D%24%20tree%20.%0A.%0A%E2%94%9C%E2%94%80%E2%94%80%20lib.c%0A%E2%94%9C%E2%94%80%E2%94%80%20libtest.so%0A%E2%94%9C%E2%94%80%E2%94%80%20main%0A%E2%94%9C%E2%94%80%E2%94%80%20main.c%0A%E2%94%9C%E2%94%80%E2%94%80%20test%0A%E2%94%94%E2%94%80%E2%94%80%20test.c%0A%60%60%60%0Amain.c%E7%94%9F%E6%88%90main%E5%8F%AF%E6%89%A7%E8%A1%8C%E7%A8%8B%E5%BA%8F%EF%BC%8Ctest.c%E7%94%9F%E6%88%90test%E5%8F%AF%E6%89%A7%E8%A1%8C%E7%A8%8B%E5%BA%8F%EF%BC%8Clib.c%E7%94%9F%E6%88%90libtest.so%E3%80%82%0A%60%60%60c%0A%2F%2F%20main.c%0A%0A%23include%20%3Cstdio.h%3E%0A%23include%20%3Cunistd.h%3E%0A%23include%20%3Csys%2Fwait.h%3E%0A%0Aint%20main()%0A%7B%0A%20%20%20%20%20%20%20%20pid_t%20pid%20%3D%20fork()%3B%0A%20%20%20%20%20%20%20%20if%20(pid%20%3D%3D%200)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20char%20*envp%5B%5D%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22LD_PRELOAD%3Dlibtest.so%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20%22LD_PRELOAD%3D.%2Flibtest.so%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20NULL%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20char%20*argv%5B%5D%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22test%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20NULL%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20int%20err%20%3D%20execve(%22.%2Ftest%22%2C%20argv%2C%20envp)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20else%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20int%20status%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wait(%26status)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20return%200%3B%0A%7D%0A%0A%2F%2F%20test.c%0A%23include%20%3Cstdio.h%3E%0A%23include%20%3Cstdlib.h%3E%0A%0Aint%20main%20()%0A%7B%0A%20%20%20%20%20%20%20%20const%20char%20*preload%20%3D%20getenv(%22LD_PRELOAD%22)%3B%0A%20%20%20%20%20%20%20%20printf(%22LD_PRELOAD%20%3D%20%25s%5Cn%22%2C%20preload)%3B%0A%20%20%20%20%20%20%20%20return%200%3B%0A%7D%0A%0A%2F%2F%20lib.c%0A%23include%20%3Cstdio.h%3E%0A%0Astatic%20void%20func(void)%20__attribute__((constructor))%3B%0Avoid%20func(void)%0A%7B%0A%20%20%20%20%20%20%20%20printf(%22I'm%20libtest.so%20loaded%5Cn%22)%3B%0A%7D%0A%60%60%60%0A%E5%9C%A8test%E5%8F%AF%E6%89%A7%E8%A1%8C%E7%A8%8B%E5%BA%8F%E6%98%AF%E6%99%AE%E9%80%9A%E7%9A%84%E4%BA%8C%E8%BF%9B%E5%88%B6%E6%97%B6%EF%BC%8C%E8%BE%93%E5%87%BA%E4%B8%BA%0A%60%60%60shell%0A%5Bben%40localhost%20test%5D%24%20.%2Fmain%0AI'm%20libtest.so%20loaded%0ALD_PRELOAD%20%3D%20.%2Flibtest.so%0A%60%60%60%0A%E5%BD%93test%E9%85%8D%E7%BD%AE%E4%BA%86capability%E4%BB%A5%E5%90%8E%EF%BC%9A%0A%60%60%60shell%0A%5Bben%40localhost%20test%5D%24%20sudo%20setcap%20cap_net_admin%2Ccap_net_raw%3Deip%20.%2Ftest%0A%5Bben%40localhost%20test%5D%24%20.%2Fmain%0ALD_PRELOAD%20%3D%20(null)%0A%60%60%60%0A%E5%8F%AF%E8%A7%81LD_PRELOAD%E6%8C%87%E5%AE%9Alibtest.so%E6%9C%AA%E8%A2%AB%E5%8A%A0%E8%BD%BD%EF%BC%8C%E4%B8%94LD_PRELOAD%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%A2%AB%E6%B8%85%E7%A9%BA%E4%BA%86%E3%80%82%0A%23%23%20LD_PRELOAD%E4%B8%8D%E5%90%AB%E6%96%9C%E7%BA%BF%0A%60%60%60shell%0A%5Bben%40localhost%20test%5D%24%20.%2Fmain%0AERROR%3A%20ld.so%3A%20object%20'libtest.so'%20from%20LD_PRELOAD%20cannot%20be%20preloaded%20(cannot%20open%20shared%20object%20file)%3A%20ignored.%0ALD_PRELOAD%20%3D%20(null)%0A%60%60%60%0ALD_PRELOAD%E4%BB%8D%E7%84%B6%E8%A2%AB%E6%B8%85%E7%A9%BA%E4%BA%86%EF%BC%8C%E4%BD%86ld.so%E4%BC%BC%E4%B9%8E%E5%B0%9D%E8%AF%95%E5%8E%BB%E5%8A%A0%E8%BD%BDlibtest.so%E4%BA%86%EF%BC%8C%E4%BD%86%E6%98%AF%E6%B2%A1%E6%89%BE%E7%9D%80%E3%80%82%0A%0A%23%23%20%E5%B0%86libtest.so%E6%94%BE%E5%85%A5%E6%A0%87%E5%87%86%E8%B7%AF%E5%BE%84%0A%E5%A6%82%E6%9E%9C%E6%B2%A1%E6%9C%89%E9%85%8D%E7%BD%AEset-user-id%E4%BD%8D%EF%BC%9A%0A%60%60%60shell%0A%5Bben%40localhost%20test%5D%24%20.%2Fmain%0AERROR%3A%20ld.so%3A%20object%20'libtest.so'%20from%20LD_PRELOAD%20cannot%20be%20preloaded%20(cannot%20open%20shared%20object%20file)%3A%20ignored.%0ALD_PRELOAD%20%3D%20(null)%0A%60%60%60%0A%E4%BB%8D%E7%84%B6%E6%8F%90%E7%A4%BA%E6%89%BE%E4%B8%8D%E5%88%B0%E3%80%82%E5%A6%82%E6%9E%9C%E8%AE%BE%E7%BD%AE%E4%BA%86set-user-id%E4%BD%8D%EF%BC%9A%0A%60%60%60shell%0A%5Bben%40localhost%20test%5D%24%20sudo%20chmod%20a%2Bs%20%2Fusr%2Flib64%2Flibtest.so%20%0A%5Bben%40localhost%20test%5D%24%20.%2Fmain%0AI'm%20libtest.so%20loaded%0ALD_PRELOAD%20%3D%20(null)%0A%60%60%60%0A%E5%9C%A8%E6%BB%A1%E8%B6%B3%E4%B8%8A%E4%B8%80%E8%8A%82%E6%8F%90%E5%88%B0%E7%9A%843%E4%B8%AA%E6%9D%A1%E4%BB%B6%E6%97%B6%EF%BC%8Clibteso.so%E5%B0%B1%E5%8F%AF%E4%BB%A5%E6%AD%A3%E5%B8%B8%E5%8A%A0%E8%BD%BD%E4%BA%86%E3%80%82%0A%E7%9C%8B%E7%9C%8B%E5%A6%82%E6%9E%9C%E6%94%BE%E5%88%B0%2Fusr%2Flib%E4%B8%8B%E9%9D%A2%E4%BC%9A%E6%80%8E%E4%B9%88%E6%A0%B7%EF%BC%9F%0A%60%60%60shell%0A%5Bben%40localhost%20test%5D%24%20ls%20%2Fusr%2Flib%2Flibtest.so%20-l%0A-rwsr-sr-x.%201%20root%20root%208208%201%E6%9C%88%20%2024%2019%3A48%20%2Fusr%2Flib%2Flibtest.so%0A%5Bben%40localhost%20test%5D%24%20.%2Fmain%0AERROR%3A%20ld.so%3A%20object%20'libtest.so'%20from%20LD_PRELOAD%20cannot%20be%20preloaded%20(cannot%20open%20shared%20object%20file)%3A%20ignored.%0ALD_PRELOAD%20%3D%20(null)%0A%60%60%60%0A%E7%9C%8B%E7%9C%8B%E8%BF%98%E6%98%AF%E4%B8%80%E6%A0%B7%E6%89%BE%E4%B8%8D%E5%88%B0%E3%80%82%E5%8F%AF%E8%A7%81%E5%9C%A8x64%E5%B9%B3%E5%8F%B0%E4%B8%8A%EF%BC%8C%2Fusr%2Flib%E5%B9%B6%E9%9D%9E%E6%A0%87%E5%87%86%E8%B7%AF%E5%BE%84%EF%BC%8C%E8%80%8C%2Fusr%2Flib64%E4%BB%A5%E5%8F%8A%2Flib64%E6%89%8D%E6%98%AF%E3%80%82%0A%0A%23%20%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE%0A%5B1%5D%20%5Bld.so(8)%20%E2%80%94%20Linux%20manual%20page%5D(https%3A%2F%2Fman7.org%2Flinux%2Fman-pages%2Fman8%2Fld.so.8.html)%0A%5B2%5D%20%5BStackoverflow%20-%20Does%20using%20linux%20capabilities%20disables%20LD_PRELOAD%5D(https%3A%2F%2Fstackoverflow.com%2Fquestions%2F18058426%2Fdoes-using-linux-capabilities-disables-ld-preload)

{"id":"1","name":"SELinux","children":[{"name":"MAC","id":"a6343230-d947-4dbe-85fa-2fa427ce03b7","parent":"1","isFolded":false,"children":[{"name":"MAC vs. DAC","id":"01c579c3-e514-4b43-916b-19bc7c3dfa46","parent":"a6343230-d947-4dbe-85fa-2fa427ce03b7","isFolded":false},{"name":"TEAC","id":"decc9d20-e0bb-46bd-bea4-41c9f89b776c","parent":"a6343230-d947-4dbe-85fa-2fa427ce03b7","isFolded":false,"children":[{"name":"allow","id":"d177ddc5-7f24-4ad4-aa98-2d4982aa7198","parent":"decc9d20-e0bb-46bd-bea4-41c9f89b776c","isFolded":false},{"name":"file context","id":"fb8144fe-ffed-4ca0-b159-103635a05559","parent":"decc9d20-e0bb-46bd-bea4-41c9f89b776c","isFolded":false,"children":[{"name":"Type transtion","id":"01a0bcc8-f38e-42f3-b283-ad29b667e4b6","parent":"fb8144fe-ffed-4ca0-b159-103635a05559","isFolded":false},{"name":"ls -Z","id":"5c581ccd-ae5a-4339-a3fd-5b0c9185b44d","parent":"fb8144fe-ffed-4ca0-b159-103635a05559","isFolded":false}]},{"name":"domain","id":"f1df4671-b15b-4965-8ef1-412e1ac78527","parent":"decc9d20-e0bb-46bd-bea4-41c9f89b776c","isFolded":false,"children":[{"name":"Domain transition","id":"16d4c234-7773-401c-bc6d-670f6c7b71af","parent":"f1df4671-b15b-4965-8ef1-412e1ac78527","isFolded":false},{"name":"ps -Z","id":"71b3b003-fe49-4b61-87a1-146517bfa1bc","parent":"f1df4671-b15b-4965-8ef1-412e1ac78527","isFolded":false}]}]},{"name":"RBAC","id":"ed74db92-0f2c-4e48-8709-0b8879798938","parent":"a6343230-d947-4dbe-85fa-2fa427ce03b7","isFolded":false,"children":[{"name":"user","id":"43d5143f-7798-4f4b-a234-a33b4aa6064b","parent":"ed74db92-0f2c-4e48-8709-0b8879798938","isFolded":false},{"name":"role","id":"d8e13a49-ec67-4586-9785-a2acf1e0187f","parent":"ed74db92-0f2c-4e48-8709-0b8879798938","isFolded":false},{"name":"Role transition","id":"4550c835-67bf-4451-9f32-5fc823fae512","parent":"ed74db92-0f2c-4e48-8709-0b8879798938","isFolded":false}]},{"name":"Conditional policy","id":"39f3d356-e7e1-4f33-84e6-66897471ae25","parent":"a6343230-d947-4dbe-85fa-2fa427ce03b7","isFolded":false}]},{"name":"compile","id":"05424ac0-8918-476f-bc21-c989b626e981","parent":"1","isFolded":false,"children":[{"name":"check_policy","id":"d2a67d13-eca5-4996-8311-65c2d5586c08","parent":"05424ac0-8918-476f-bc21-c989b626e981","isFolded":false},{"name":"Sepolicy","id":"11881193-e26e-4fe8-93e2-fbb1376a8b1d","parent":"05424ac0-8918-476f-bc21-c989b626e981","isFolded":false},{"name":"Semodule","id":"eb26fd93-a1c3-45fa-94ab-414ab44e9733","parent":"05424ac0-8918-476f-bc21-c989b626e981","isFolded":false}]},{"name":"初始化","id":"43459d78-7b4c-4642-a8ba-15b310c17e3b","parent":"1","isFolded":false,"children":[{"name":"LSM","id":"962beb64-afa5-4e60-b53f-ca1e57bde223","parent":"43459d78-7b4c-4642-a8ba-15b310c17e3b","isFolded":false,"children":[{"name":"selinuxfs","id":"82a19f24-bd61-4921-8050-6051ba657f9c","parent":"962beb64-afa5-4e60-b53f-ca1e57bde223","isFolded":false,"children":[{"name":"init_sel_fs","id":"25291af6-36ab-4698-a8c2-05cacdcc4f5f","parent":"82a19f24-bd61-4921-8050-6051ba657f9c","isFolded":false}]},{"name":"selinux_init","id":"54fc5d2c-0c98-4ca2-a1c5-e1a5e8564e00","parent":"962beb64-afa5-4e60-b53f-ca1e57bde223","isFolded":false,"children":[]},{"name":"security_load_policy","id":"9ba0e47f-a160-4e24-a461-7349dd54ac20","parent":"962beb64-afa5-4e60-b53f-ca1e57bde223","isFolded":false}]},{"name":"init进程","id":"7166fca1-1669-4f90-819d-23944b96ca92","parent":"43459d78-7b4c-4642-a8ba-15b310c17e3b","isFolded":false,"children":[{"name":"busybox init","id":"8bea8dc5-8ac1-4a29-b555-40fc76c1f358","parent":"7166fca1-1669-4f90-819d-23944b96ca92","isFolded":false,"children":[{"name":"Libselinux","id":"41e1bc29-8326-4ec7-a61b-0d7565bb16f6","parent":"8bea8dc5-8ac1-4a29-b555-40fc76c1f358","isFolded":false}]},{"name":"systemd","id":"962beb64-afa5-4e60-b53f-ca1e57bde223","parent":"7166fca1-1669-4f90-819d-23944b96ca92","isFolded":false}]},{"name":"配置文件","id":"ff71360c-fe09-4c78-b10c-5bc05054b558","parent":"43459d78-7b4c-4642-a8ba-15b310c17e3b","isFolded":false,"children":[{"name":"/etc/selinux/confg","id":"f74b66d4-447d-4d02-be46-aa2f67fdeec8","parent":"ff71360c-fe09-4c78-b10c-5bc05054b558","isFolded":false},{"name":"/sys/fs/selinux/","id":"ab82d41b-6f86-4141-aa83-11ed5ff3c100","parent":"ff71360c-fe09-4c78-b10c-5bc05054b558","isFolded":false}]}]},{"name":"工具集","id":"8eea1060-f967-4062-a98e-8bca8bfb3b21","parent":"1","isFolded":false,"children":[{"name":"semanage","id":"9d6f3c2c-91f5-447e-bd62-1ea1b65bfb59","parent":"8eea1060-f967-4062-a98e-8bca8bfb3b21","isFolded":false},{"name":"sesearch","id":"ea0a832a-05cb-471e-8b35-26d313f2fd2a","parent":"8eea1060-f967-4062-a98e-8bca8bfb3b21","isFolded":false}]},{"name":"策略语法","id":"187a78ed-a525-4979-b208-ff59c8d191bb","parent":"1","isFolded":false,"children":[{"name":"标准","id":"f54d80ee-e847-4297-9ec0-ca708514e6c7","parent":"187a78ed-a525-4979-b208-ff59c8d191bb","isFolded":false,"children":[{"name":"allow","id":"49cdfee5-00a3-468a-8fac-b21423098aeb","parent":"f54d80ee-e847-4297-9ec0-ca708514e6c7","isFolded":false},{"name":"Role","id":"74040fcc-f6c6-407d-b5e3-b385f1424165","parent":"f54d80ee-e847-4297-9ec0-ca708514e6c7","isFolded":false},{"name":"安全上下文","id":"a5c214c1-71f9-4548-b223-831068872412","parent":"f54d80ee-e847-4297-9ec0-ca708514e6c7","isFolded":false,"children":[{"name":"fc文件","id":"c63de22c-e260-43a7-971f-141a59871ae4","parent":"a5c214c1-71f9-4548-b223-831068872412","isFolded":false,"children":[]},{"name":"netifcon","id":"253e5ea4-00ed-44e8-a5c8-d90bcd0bd917","parent":"a5c214c1-71f9-4548-b223-831068872412","isFolded":false},{"name":"portcon","id":"11fd971b-bc11-4c4d-8f67-259f088f770f","parent":"a5c214c1-71f9-4548-b223-831068872412","isFolded":false},{"name":"nodecon","id":"9314dca8-2640-4bf3-9d44-bf36a30675f0","parent":"a5c214c1-71f9-4548-b223-831068872412","isFolded":false}]}]},{"name":"CIL","id":"95bb02f4-0e0c-4121-bbfa-89fe0babb4a5","parent":"187a78ed-a525-4979-b208-ff59c8d191bb","isFolded":false}]},{"name":"iptable","id":"178111ad-f47b-49e4-ac90-479499ab5e43","parent":"1","isFolded":false,"children":[{"name":"security table","id":"f5711cf1-3863-43dc-b8e6-1fd69ccb71e9","parent":"178111ad-f47b-49e4-ac90-479499ab5e43","isFolded":false},{"name":"SECMARK","id":"ab33314e-b3ca-42e4-bcdb-e249cd6b87a7","parent":"178111ad-f47b-49e4-ac90-479499ab5e43","isFolded":false},{"name":"NetFilter","id":"765137cd-9c01-4650-bb98-bdb985ae3862","parent":"178111ad-f47b-49e4-ac90-479499ab5e43","isFolded":false}]}],"isFolded":false,"_children":null}

RBAC, Role Based Access Control, 是SELinux的另一个重要的特性。但他并不是一种独立的控制方式,而是对TEAC的一种补充。其主要的作用是,构建SELinux提供的进程级的MAC机制与Linux的用户系统的映射关系。

RBAC工作原理

RBAC并不提供强制访问控制,而是通过user,role,type之间的对应关系,来控制type_transition策略能否成功。

role vs. type

role based最基本的就是定义role到type到对应关系。使用role语句可以实现:role role_name [types type_set];。例如:

role user_r types user_t;
role user_r types { staff_t, admin_t };
  • role定义是累积的,即后面的对应关系不会覆盖前面语句定义的对应关系,而只会追加这种关系
  • role语句通常定义在type声明附近,以确保该对应关系被及时定义

定义子role (period)
A period is used to indicate restrictions on the set of types that may be assigned to a role. For example, the set of types for a role called apache.cgi must be a subset of the type set of a role called apache.

role语句定义的基本逻辑就是,定义了role=>{ types }集合的映射关系。当发生type transition时,如果转换后的{role,type}组合未定义,则视为权限错误。从这个层面看,role对应的是主体type,即domain type,而非object type。

特殊的role: object_r

object_r是内核SELinux模块预定义的一个role,无需在policy中声明。而这个object_r被专门用来定义客体的安全上下文。

user vs. role

user是对role的再一次扩充,通过user将role与Linux user的映射关系建立起来。SELinux的用户系统独立于Linux用户系统。通过seusers文件或者semanage user命令可以定义他们之间的映射关系。但实际可定义的自由度并没有那么高。

The design decision for SELinux to have a distinct user identifier (rather than share that of Linux) is motivated by the desire to create an immutable SELinux user identifier.

定义一个user与role的映射关系,可以使用user语句:user user_name roles { role_set };
user语句所体现的逻辑和role语句类似,即定义了user=>{ roles }集合的映射关系。当应用启动时发生role transition时,如果转换后的{user, role}未定义,则视为权限错误。

当SELinux通过RBAC,建立起user=>role=>type的映射关系以后,还获得了一个好处。Linux系统的用户数可能很多,而用户的类型很少。用户并不是为了定义权限的,不同的用户之间的使用数据需要隔离。但往往一类用户的权限是相同的。例如超级用户,管理员用户,普通用户等等。系统的权限集最小粒度由domain定义。可能每个进程的权限不同,也可能一组进程的权限相同。但往往domain的数量也很庞大。如果没有RBAC,我们需要定义user到domain到映射。这样也不是不能做,但却不太优雅。每次新增用户时,需要为新增用户绑定一堆domain。定义了role之后,role相当于较稳定的一层抽象,role到types的映射关系是在定义type时候就定义了的。增加新user的时候,只要定义user到role的映射即可。这就是引入RBAC的原因。

PHN2ZyBpZD0iZGpkaWlmNXVnZ3UiIHdpZHRoPSIxMDAlIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHN0eWxlPSJtYXgtd2lkdGg6IDI2OS43NjU2MjVweDsiIHZpZXdCb3g9IjAgMCAyNjkuNzY1NjI1IDIyNC44NDM3NSI+PHN0eWxlPgoKCiNkamRpaWY1dWdndSAubGFiZWwgewogIGZvbnQtZmFtaWx5OiAndHJlYnVjaGV0IG1zJywgdmVyZGFuYSwgYXJpYWw7CiAgY29sb3I6ICMzMzM7IH0KCiNkamRpaWY1dWdndSAubm9kZSByZWN0LAojZGpkaWlmNXVnZ3UgLm5vZGUgY2lyY2xlLAojZGpkaWlmNXVnZ3UgLm5vZGUgZWxsaXBzZSwKI2RqZGlpZjV1Z2d1IC5ub2RlIHBvbHlnb24gewogIGZpbGw6ICNFQ0VDRkY7CiAgc3Ryb2tlOiAjOTM3MERCOwogIHN0cm9rZS13aWR0aDogMXB4OyB9CgojZGpkaWlmNXVnZ3UgLm5vZGUuY2xpY2thYmxlIHsKICBjdXJzb3I6IHBvaW50ZXI7IH0KCiNkamRpaWY1dWdndSAuYXJyb3doZWFkUGF0aCB7CiAgZmlsbDogIzMzMzMzMzsgfQoKI2RqZGlpZjV1Z2d1IC5lZGdlUGF0aCAucGF0aCB7CiAgc3Ryb2tlOiAjMzMzMzMzOwogIHN0cm9rZS13aWR0aDogMS41cHg7IH0KCiNkamRpaWY1dWdndSAuZWRnZUxhYmVsIHsKICBiYWNrZ3JvdW5k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xOC4xNDA2MjUiIHdpZHRoPSI2NC40Mzc1IiBoZWlnaHQ9IjM2LjI4MTI1Ij48L3JlY3Q+PGcgY2xhc3M9ImxhYmVsIiB0cmFuc2Zvcm09InRyYW5zbGF0ZSgwLDApIj48ZyB0cmFuc2Zvcm09InRyYW5zbGF0ZSgtMjIuMjE4NzUsLTguMTQwNjI1KSI+PHRleHQ+PHRzcGFuIHhtbDpzcGFjZT0icHJlc2VydmUiIGR5PSIxZW0iIHg9IjEiPmRvbWFpbjwvdHNwYW4+PC90ZXh0PjwvZz48L2c+PC9nPjwvZz48L2c+PC9nPjwvc3ZnPg==

Linux用户 vs. SELinux user

               标记中        MLS/       MLS/                          
SELinux 用户      前缀         MCS 级别     MCS 范围                         SELinux 角色

guest_u         user       s0         s0                             guest_r
root            user       s0         s0-s0:c0.c1023                 staff_r sysadm_r system_r unconfined_r
staff_u         user       s0         s0-s0:c0.c1023                 staff_r sysadm_r unconfined_r
sysadm_u        user       s0         s0-s0:c0.c1023                 sysadm_r
system_u        user       s0         s0-s0:c0.c1023                 system_r unconfined_r
unconfined_u    user       s0         s0-s0:c0.c1023                 system_r unconfined_r
user_u          user       s0         s0                             user_r
xguest_u        user       s0         s0                             xguest_r
  • 查看两者的映射关系可以通过命令semanage login -l.
登录名                  SELinux 用户           MLS/MCS 范围           服务

__default__          unconfined_u         s0-s0:c0.c1023       *
john                 user_u               s0                   *
root                 unconfined_u         s0-s0:c0.c1023       *

Linux用户和SELinux用户的初始映射关系由seusers文件指定。这个文件不属于策略二进制的一部分,而可以直接修改生效。当然更优雅的办法是通过semanage命令来修改。
另外,在修改了context以后,或者新建了用户以后,必须要使用注销登录的方法,才能使新的context生效,而只使用su命令切换用户,并不会切换context。推测注销登录使用的是PAM登录程序,而su命令中,并没有重新加载user context的功能。
Linux用户登录后,获取shell安全上下文的步骤,可以参考文献【2】。简述如下:

  1. 根据seusers文件,映射SELinux用户,如果没有seusers文件,系统就无法启动了。如果seusers文件没有对应的用户描述,则统一映射为__default__用户。如果__default__用户描述不存在,则无法登录。
  2. 根据SELinux的搜索优先级,找到对应SELinux用户的安全上下文。

勘误
在[1]中,对Linux用户和SELinux的映射关系有如下描述:
On login, if there is an SELinux user identifier that is exactly the same as the Linux user identifier, the matching SELinux user identifier becomes the user identifier in the security context for the initial shell process. In this way, if a Linux user identifier also exists as a user identifier in the SELinux policy, all login processes will set the initial shell process security context user identifier to that matching Linux identity.
经实验证明,并非如此:

  • 定义了一个guest_u用户,登录后,其shell的安全上下文仍为:
  • 但事实证明,明明就有guest_u这个用户

总结

现在可以引用[1]中的一幅图来总结一下RBAC的工作原理了。

  • Linux系统有一个用户较joe
  • SELinuxcelue中规定joe和user_r绑定,user_r和user_t绑定
  • 当joe登录时,系统根据seusers(此处与图不同,参见上一章勘误),找到对应的SELinux user,找不到就是__default__, __default__没有就不能登录了
  • 根据以下context文件顺序,决定其shell的安全上下文,即joe:user_r:user_t
    • /etc/selinux/specified-policy/contexts/users
    • /etc/selinux/specified-policy/contexts/default_contexts
    • /etc/selinux/specified-policy/contexts/failsafe_context
    • sid kernel的安全上下文
  • joe执行了一个应用,开始进行domain_transition, 要从user_t切换到passwd_t
    • 如果定义了role user_r types passwd_trole user_r types user_t,则这次domain transition可以成功
    • 否则任意一个未定义,domain transition都会失败

高阶用法

role_transition

role transition和domain transition非常类似,也是在某个domain进程在执行某个可执行文件时,即exec系统调用时,切换进程主体的安全上下文。domain transition切换的时domain,role transtion切换的是role。实现方式通过以下两条语句:

allow staff_r sysadm_r; # 允许从staff_r切换到sysadm_r
role_transition sysadm_r http_exec_t system_r; # sysadm_r进程执行http_exec_t类型文件时,role切换为system_r

role_dominance

可以利用role来定义其他role,即role dominance。

dominance { role super_r {role sysadm_r; role secadm_r; }

上面例子中的super_r称为dominant role,它可以从它关联的role中即成types。但它只能继承该条语句之前关联的types。我们之前说role语句是可以累积的。那么在role_dominance语句之后定义的types,并不能动态的添加到dominant role上。

相关工具

跟role相关的主要是semnage的一些用法,另外[1]还介绍了一个apol的可视化工具,可以检索user和role的数据。我理解semanage通过命令行也都可以实现。

  1. 前文介绍过的semanage user -lsemanage login -l, 前者用来查看所有SELinux的用户,后者用来查看Linux用户和SELinux用户两者的映射关系.
  2. Modify the default user on the system to the guest_u user
  • semanage login -m -s guest_u __default__
  1. 修改user和role的对应关系
  • semanage user -m -R "message_filter_r unconfined_r" user_u
  1. 添加一个用户并指定SELinux用户
  • useradd joe -Z user_u

参考文献

[1] SELinux by Example_ Using Security Enhanced Linux

[2] SELinux初始化登录用户安全上下文的方法

RBAC%2C%20Role%20Based%20Access%20Control%2C%20%E6%98%AFSELinux%E7%9A%84%E5%8F%A6%E4%B8%80%E4%B8%AA%E9%87%8D%E8%A6%81%E7%9A%84%E7%89%B9%E6%80%A7%E3%80%82%E4%BD%86%E4%BB%96%E5%B9%B6%E4%B8%8D%E6%98%AF%E4%B8%80%E7%A7%8D%E7%8B%AC%E7%AB%8B%E7%9A%84%E6%8E%A7%E5%88%B6%E6%96%B9%E5%BC%8F%EF%BC%8C%E8%80%8C%E6%98%AF%E5%AF%B9TEAC%E7%9A%84%E4%B8%80%E7%A7%8D%E8%A1%A5%E5%85%85%E3%80%82%E5%85%B6%E4%B8%BB%E8%A6%81%E7%9A%84%E4%BD%9C%E7%94%A8%E6%98%AF%EF%BC%8C%E6%9E%84%E5%BB%BASELinux%E6%8F%90%E4%BE%9B%E7%9A%84%E8%BF%9B%E7%A8%8B%E7%BA%A7%E7%9A%84MAC%E6%9C%BA%E5%88%B6%E4%B8%8ELinux%E7%9A%84%E7%94%A8%E6%88%B7%E7%B3%BB%E7%BB%9F%E7%9A%84%E6%98%A0%E5%B0%84%E5%85%B3%E7%B3%BB%E3%80%82%0A%0A%23%20RBAC%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86%0ARBAC%E5%B9%B6%E4%B8%8D%E6%8F%90%E4%BE%9B%E5%BC%BA%E5%88%B6%E8%AE%BF%E9%97%AE%E6%8E%A7%E5%88%B6%EF%BC%8C%E8%80%8C%E6%98%AF%E9%80%9A%E8%BF%87user%EF%BC%8Crole%EF%BC%8Ctype%E4%B9%8B%E9%97%B4%E7%9A%84%E5%AF%B9%E5%BA%94%E5%85%B3%E7%B3%BB%EF%BC%8C%E6%9D%A5%E6%8E%A7%E5%88%B6type_transition%E7%AD%96%E7%95%A5%E8%83%BD%E5%90%A6%E6%88%90%E5%8A%9F%E3%80%82%0A%23%23%20role%20vs.%20type%0Arole%20based%E6%9C%80%E5%9F%BA%E6%9C%AC%E7%9A%84%E5%B0%B1%E6%98%AF%E5%AE%9A%E4%B9%89role%E5%88%B0type%E5%88%B0%E5%AF%B9%E5%BA%94%E5%85%B3%E7%B3%BB%E3%80%82%E4%BD%BF%E7%94%A8role%E8%AF%AD%E5%8F%A5%E5%8F%AF%E4%BB%A5%E5%AE%9E%E7%8E%B0%EF%BC%9A%60role%20role_name%20%5Btypes%20type_set%5D%3B%60%E3%80%82%E4%BE%8B%E5%A6%82%EF%BC%9A%0A%60%60%60%0Arole%20user_r%20types%20user_t%3B%0Arole%20user_r%20types%20%7B%20staff_t%2C%20admin_t%20%7D%3B%0A%60%60%60%0A-%20role%E5%AE%9A%E4%B9%89%E6%98%AF%E7%B4%AF%E7%A7%AF%E7%9A%84%EF%BC%8C%E5%8D%B3%E5%90%8E%E9%9D%A2%E7%9A%84%E5%AF%B9%E5%BA%94%E5%85%B3%E7%B3%BB%E4%B8%8D%E4%BC%9A%E8%A6%86%E7%9B%96%E5%89%8D%E9%9D%A2%E8%AF%AD%E5%8F%A5%E5%AE%9A%E4%B9%89%E7%9A%84%E5%AF%B9%E5%BA%94%E5%85%B3%E7%B3%BB%EF%BC%8C%E8%80%8C%E5%8F%AA%E4%BC%9A%E8%BF%BD%E5%8A%A0%E8%BF%99%E7%A7%8D%E5%85%B3%E7%B3%BB%0A-%20role%E8%AF%AD%E5%8F%A5%E9%80%9A%E5%B8%B8%E5%AE%9A%E4%B9%89%E5%9C%A8type%E5%A3%B0%E6%98%8E%E9%99%84%E8%BF%91%EF%BC%8C%E4%BB%A5%E7%A1%AE%E4%BF%9D%E8%AF%A5%E5%AF%B9%E5%BA%94%E5%85%B3%E7%B3%BB%E8%A2%AB%E5%8F%8A%E6%97%B6%E5%AE%9A%E4%B9%89%0A%0A%3E%20**%E5%AE%9A%E4%B9%89%E5%AD%90role%20(period)**%0A%3E%20A%20period%20is%20used%20to%20indicate%20restrictions%20on%20the%20set%20of%20types%20that%20may%20be%20assigned%20to%20a%20role.%20For%20example%2C%20the%20set%20of%20types%20for%20a%20role%20called%20***apache.cgi***%20must%20be%20a%20***subset***%20of%20the%20type%20set%20of%20a%20role%20called%20***apache***.%0A%0Arole%E8%AF%AD%E5%8F%A5%E5%AE%9A%E4%B9%89%E7%9A%84%E5%9F%BA%E6%9C%AC%E9%80%BB%E8%BE%91%E5%B0%B1%E6%98%AF%EF%BC%8C%E5%AE%9A%E4%B9%89%E4%BA%86role%3D%3E%7B%20types%20%7D%E9%9B%86%E5%90%88%E7%9A%84%E6%98%A0%E5%B0%84%E5%85%B3%E7%B3%BB%E3%80%82%E5%BD%93%E5%8F%91%E7%94%9Ftype%20transition%E6%97%B6%EF%BC%8C%E5%A6%82%E6%9E%9C%E8%BD%AC%E6%8D%A2%E5%90%8E%E7%9A%84%7Brole%EF%BC%8Ctype%7D%E7%BB%84%E5%90%88%E6%9C%AA%E5%AE%9A%E4%B9%89%EF%BC%8C%E5%88%99%E8%A7%86%E4%B8%BA%E6%9D%83%E9%99%90%E9%94%99%E8%AF%AF%E3%80%82%E4%BB%8E%E8%BF%99%E4%B8%AA%E5%B1%82%E9%9D%A2%E7%9C%8B%EF%BC%8Crole%E5%AF%B9%E5%BA%94%E7%9A%84%E6%98%AF%E4%B8%BB%E4%BD%93type%EF%BC%8C%E5%8D%B3domain%20type%EF%BC%8C%E8%80%8C%E9%9D%9Eobject%20type%E3%80%82%0A%0A%0A%23%23%23%20%E7%89%B9%E6%AE%8A%E7%9A%84role%3A%20object_r%0Aobject_r%E6%98%AF%E5%86%85%E6%A0%B8SELinux%E6%A8%A1%E5%9D%97%E9%A2%84%E5%AE%9A%E4%B9%89%E7%9A%84%E4%B8%80%E4%B8%AArole%EF%BC%8C%E6%97%A0%E9%9C%80%E5%9C%A8policy%E4%B8%AD%E5%A3%B0%E6%98%8E%E3%80%82%E8%80%8C%E8%BF%99%E4%B8%AAobject_r%E8%A2%AB%E4%B8%93%E9%97%A8%E7%94%A8%E6%9D%A5%E5%AE%9A%E4%B9%89%E5%AE%A2%E4%BD%93%E7%9A%84%E5%AE%89%E5%85%A8%E4%B8%8A%E4%B8%8B%E6%96%87%E3%80%82%0A%23%23%20user%20vs.%20role%0Auser%E6%98%AF%E5%AF%B9role%E7%9A%84%E5%86%8D%E4%B8%80%E6%AC%A1%E6%89%A9%E5%85%85%EF%BC%8C%E9%80%9A%E8%BF%87user%E5%B0%86role%E4%B8%8ELinux%20user%E7%9A%84%E6%98%A0%E5%B0%84%E5%85%B3%E7%B3%BB%E5%BB%BA%E7%AB%8B%E8%B5%B7%E6%9D%A5%E3%80%82SELinux%E7%9A%84%E7%94%A8%E6%88%B7%E7%B3%BB%E7%BB%9F%E7%8B%AC%E7%AB%8B%E4%BA%8ELinux%E7%94%A8%E6%88%B7%E7%B3%BB%E7%BB%9F%E3%80%82%E9%80%9A%E8%BF%87seusers%E6%96%87%E4%BB%B6%E6%88%96%E8%80%85%60semanage%20user%60%E5%91%BD%E4%BB%A4%E5%8F%AF%E4%BB%A5%E5%AE%9A%E4%B9%89%E4%BB%96%E4%BB%AC%E4%B9%8B%E9%97%B4%E7%9A%84%E6%98%A0%E5%B0%84%E5%85%B3%E7%B3%BB%E3%80%82%E4%BD%86%E5%AE%9E%E9%99%85%E5%8F%AF%E5%AE%9A%E4%B9%89%E7%9A%84%E8%87%AA%E7%94%B1%E5%BA%A6%E5%B9%B6%E6%B2%A1%E6%9C%89%E9%82%A3%E4%B9%88%E9%AB%98%E3%80%82%0A%3E%20The%20design%20decision%20for%20SELinux%20to%20have%20a%20distinct%20user%20identifier%20(rather%20than%20share%20that%20of%20Linux)%20is%20motivated%20by%20the%20desire%20to%20create%20an%20immutable%20SELinux%20user%20identifier.%0A%0A%E5%AE%9A%E4%B9%89%E4%B8%80%E4%B8%AAuser%E4%B8%8Erole%E7%9A%84%E6%98%A0%E5%B0%84%E5%85%B3%E7%B3%BB%EF%BC%8C%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8user%E8%AF%AD%E5%8F%A5%EF%BC%9A%60user%20user_name%20roles%20%7B%20role_set%20%7D%3B%60%0Auser%E8%AF%AD%E5%8F%A5%E6%89%80%E4%BD%93%E7%8E%B0%E7%9A%84%E9%80%BB%E8%BE%91%E5%92%8Crole%E8%AF%AD%E5%8F%A5%E7%B1%BB%E4%BC%BC%EF%BC%8C%E5%8D%B3%E5%AE%9A%E4%B9%89%E4%BA%86user%3D%3E%7B%20roles%20%7D%E9%9B%86%E5%90%88%E7%9A%84%E6%98%A0%E5%B0%84%E5%85%B3%E7%B3%BB%E3%80%82%E5%BD%93%E5%BA%94%E7%94%A8%E5%90%AF%E5%8A%A8%E6%97%B6%E5%8F%91%E7%94%9Frole%20transition%E6%97%B6%EF%BC%8C%E5%A6%82%E6%9E%9C%E8%BD%AC%E6%8D%A2%E5%90%8E%E7%9A%84%7Buser%2C%20role%7D%E6%9C%AA%E5%AE%9A%E4%B9%89%EF%BC%8C%E5%88%99%E8%A7%86%E4%B8%BA%E6%9D%83%E9%99%90%E9%94%99%E8%AF%AF%E3%80%82%0A%0A%E5%BD%93SELinux%E9%80%9A%E8%BF%87RBAC%EF%BC%8C%E5%BB%BA%E7%AB%8B%E8%B5%B7user%3D%3Erole%3D%3Etype%E7%9A%84%E6%98%A0%E5%B0%84%E5%85%B3%E7%B3%BB%E4%BB%A5%E5%90%8E%EF%BC%8C%E8%BF%98%E8%8E%B7%E5%BE%97%E4%BA%86%E4%B8%80%E4%B8%AA%E5%A5%BD%E5%A4%84%E3%80%82Linux%E7%B3%B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5%BE%80%E5%BE%80domain%E7%9A%84%E6%95%B0%E9%87%8F%E4%B9%9F%E5%BE%88%E5%BA%9E%E5%A4%A7%E3%80%82%E5%A6%82%E6%9E%9C%E6%B2%A1%E6%9C%89RBAC%EF%BC%8C%E6%88%91%E4%BB%AC%E9%9C%80%E8%A6%81%E5%AE%9A%E4%B9%89user%E5%88%B0domain%E5%88%B0%E6%98%A0%E5%B0%84%E3%80%82%E8%BF%99%E6%A0%B7%E4%B9%9F%E4%B8%8D%E6%98%AF%E4%B8%8D%E8%83%BD%E5%81%9A%EF%BC%8C%E4%BD%86%E5%8D%B4%E4%B8%8D%E5%A4%AA%E4%BC%98%E9%9B%85%E3%80%82%E6%AF%8F%E6%AC%A1%E6%96%B0%E5%A2%9E%E7%94%A8%E6%88%B7%E6%97%B6%EF%BC%8C%E9%9C%80%E8%A6%81%E4%B8%BA%E6%96%B0%E5%A2%9E%E7%94%A8%E6%88%B7%E7%BB%91%E5%AE%9A%E4%B8%80%E5%A0%86domain%E3%80%82%E5%AE%9A%E4%B9%89%E4%BA%86role%E4%B9%8B%E5%90%8E%EF%BC%8Crole%E7%9B%B8%E5%BD%93%E4%BA%8E%E8%BE%83%E7%A8%B3%E5%AE%9A%E7%9A%84%E4%B8%80%E5%B1%82%E6%8A%BD%E8%B1%A1%EF%BC%8Crole%E5%88%B0types%E7%9A%84%E6%98%A0%E5%B0%84%E5%85%B3%E7%B3%BB%E6%98%AF%E5%9C%A8%E5%AE%9A%E4%B9%89type%E6%97%B6%E5%80%99%E5%B0%B1%E5%AE%9A%E4%B9%89%E4%BA%86%E7%9A%84%E3%80%82%E5%A2%9E%E5%8A%A0%E6%96%B0user%E7%9A%84%E6%97%B6%E5%80%99%EF%BC%8C%E5%8F%AA%E8%A6%81%E5%AE%9A%E4%B9%89user%E5%88%B0role%E7%9A%84%E6%98%A0%E5%B0%84%E5%8D%B3%E5%8F%AF%E3%80%82%E8%BF%99%E5%B0%B1%E6%98%AF%E5%BC%95%E5%85%A5RBAC%E7%9A%84%E5%8E%9F%E5%9B%A0%E3%80%82%0A%0A%60%60%60mermaid%0Agraph%20LR%0AA%5Buser%5D%20--%3E%20B%5Brole%5D%0AA%20--%3E%20C%5Brole%5D%0AA%20--%3E%20D%5Brole%5D%0AC%20--%3E%20E%5Bdomain%5D%0AC%20--%3E%20F%5Bdomain%5D%0AC%20--%3E%20G%5Bdomain%5D%0A%60%60%60%0A%0A%23%23%23%20Linux%E7%94%A8%E6%88%B7%20vs.%20SELinux%20user%0A-%20%E5%BD%93%E5%89%8D%E7%B3%BB%E7%BB%9F%E7%9A%84%E7%94%A8%E6%88%B7%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%E6%9F%A5%E7%9C%8B%2Fetc%2Fpasswd%E6%96%87%E4%BB%B6%E8%8E%B7%E5%8F%96%EF%BC%8C%E4%B9%9F%E5%8F%AF%E4%BB%A5%E5%8F%82%E8%80%83%5B%E5%88%97%E5%87%BA%20Linux%20%E7%B3%BB%E7%BB%9F%E4%B8%8A%E6%89%80%E6%9C%89%E7%94%A8%E6%88%B7%E7%9A%84%203%20%E7%A7%8D%E6%96%B9%E6%B3%95%5D(https%3A%2F%2Fzhuanlan.zhihu.com%2Fp%2F41161408).%0A-%20%E6%9F%A5%E7%9C%8BSELinux%E7%9A%84%E7%94%A8%E6%88%B7%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%E5%91%BD%E4%BB%A4%60semanage%20user%20-l%60.%0A%60%60%60shell%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%E6%A0%87%E8%AE%B0%E4%B8%AD%20%20%20%20%20%20%20%20MLS%2F%20%20%20%20%20%20%20MLS%2F%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0ASELinux%20%E7%94%A8%E6%88%B7%20%20%20%20%20%20%E5%89%8D%E7%BC%80%20%20%20%20%20%20%20%20%20MCS%20%E7%BA%A7%E5%88%AB%20%20%20%20%20MCS%20%E8%8C%83%E5%9B%B4%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20SELinux%20%E8%A7%92%E8%89%B2%0A%0Aguest_u%20%20%20%20%20%20%20%20%20user%20%20%20%20%20%20%20s0%20%20%20%20%20%20%20%20%20s0%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20guest_r%0Aroot%20%20%20%20%20%20%20%20%20%20%20%20user%20%20%20%20%20%20%20s0%20%20%20%20%20%20%20%20%20s0-s0%3Ac0.c1023%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20staff_r%20sysadm_r%20system_r%20unconfined_r%0Astaff_u%20%20%20%20%20%20%20%20%20user%20%20%20%20%20%20%20s0%20%20%20%20%20%20%20%20%20s0-s0%3Ac0.c1023%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20staff_r%20sysadm_r%20unconfined_r%0Asysadm_u%20%20%20%20%20%20%20%20user%20%20%20%20%20%20%20s0%20%20%20%20%20%20%20%20%20s0-s0%3Ac0.c1023%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20sysadm_r%0Asystem_u%20%20%20%20%20%20%20%20user%20%20%20%20%20%20%20s0%20%20%20%20%20%20%20%20%20s0-s0%3Ac0.c1023%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20system_r%20unconfined_r%0Aunconfined_u%20%20%20%20user%20%20%20%20%20%20%20s0%20%20%20%20%20%20%20%20%20s0-s0%3Ac0.c1023%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20system_r%20unconfined_r%0Auser_u%20%20%20%20%20%20%20%20%20%20user%20%20%20%20%20%20%20s0%20%20%20%20%20%20%20%20%20s0%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20user_r%0Axguest_u%20%20%20%20%20%20%20%20user%20%20%20%20%20%20%20s0%20%20%20%20%20%20%20%20%20s0%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20xguest_r%0A%60%60%60%0A-%20%E6%9F%A5%E7%9C%8B%E4%B8%A4%E8%80%85%E7%9A%84%E6%98%A0%E5%B0%84%E5%85%B3%E7%B3%BB%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%E5%91%BD%E4%BB%A4%60semanage%20login%20-l%60.%0A%60%60%60shell%0A%E7%99%BB%E5%BD%95%E5%90%8D%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20SELinux%20%E7%94%A8%E6%88%B7%20%20%20%20%20%20%20%20%20%20%20MLS%2FMCS%20%E8%8C%83%E5%9B%B4%20%20%20%20%20%20%20%20%20%20%20%E6%9C%8D%E5%8A%A1%0A%0A__default__%20%20%20%20%20%20%20%20%20%20unconfined_u%20%20%20%20%20%20%20%20%20s0-s0%3Ac0.c1023%20%20%20%20%20%20%20*%0Ajohn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20user_u%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20s0%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20*%0Aroot%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20unconfined_u%20%20%20%20%20%20%20%20%20s0-s0%3Ac0.c1023%20%20%20%20%20%20%20*%0A%60%60%60%0A%0ALinux%E7%94%A8%E6%88%B7%E5%92%8CSELinux%E7%94%A8%E6%88%B7%E7%9A%84%E5%88%9D%E5%A7%8B%E6%98%A0%E5%B0%84%E5%85%B3%E7%B3%BB%E7%94%B1seusers%E6%96%87%E4%BB%B6%E6%8C%87%E5%AE%9A%E3%80%82%E8%BF%99%E4%B8%AA%E6%96%87%E4%BB%B6%E4%B8%8D%E5%B1%9E%E4%BA%8E%E7%AD%96%E7%95%A5%E4%BA%8C%E8%BF%9B%E5%88%B6%E7%9A%84%E4%B8%80%E9%83%A8%E5%88%86%EF%BC%8C%E8%80%8C%E5%8F%AF%E4%BB%A5%E7%9B%B4%E6%8E%A5%E4%BF%AE%E6%94%B9%E7%94%9F%E6%95%88%E3%80%82%E5%BD%93%E7%84%B6%E6%9B%B4%E4%BC%98%E9%9B%85%E7%9A%84%E5%8A%9E%E6%B3%95%E6%98%AF%E9%80%9A%E8%BF%87semanage%E5%91%BD%E4%BB%A4%E6%9D%A5%E4%BF%AE%E6%94%B9%E3%80%82%0A%E5%8F%A6%E5%A4%96%EF%BC%8C%E5%9C%A8%E4%BF%AE%E6%94%B9%E4%BA%86context%E4%BB%A5%E5%90%8E%EF%BC%8C%E6%88%96%E8%80%85%E6%96%B0%E5%BB%BA%E4%BA%86%E7%94%A8%E6%88%B7%E4%BB%A5%E5%90%8E%EF%BC%8C%E5%BF%85%E9%A1%BB%E8%A6%81%E4%BD%BF%E7%94%A8%E6%B3%A8%E9%94%80%E7%99%BB%E5%BD%95%E7%9A%84%E6%96%B9%E6%B3%95%EF%BC%8C%E6%89%8D%E8%83%BD%E4%BD%BF%E6%96%B0%E7%9A%84context%E7%94%9F%E6%95%88%EF%BC%8C%E8%80%8C%E5%8F%AA%E4%BD%BF%E7%94%A8su%E5%91%BD%E4%BB%A4%E5%88%87%E6%8D%A2%E7%94%A8%E6%88%B7%EF%BC%8C%E5%B9%B6%E4%B8%8D%E4%BC%9A%E5%88%87%E6%8D%A2context%E3%80%82%E6%8E%A8%E6%B5%8B%E6%B3%A8%E9%94%80%E7%99%BB%E5%BD%95%E4%BD%BF%E7%94%A8%E7%9A%84%E6%98%AFPAM%E7%99%BB%E5%BD%95%E7%A8%8B%E5%BA%8F%EF%BC%8C%E8%80%8Csu%E5%91%BD%E4%BB%A4%E4%B8%AD%EF%BC%8C%E5%B9%B6%E6%B2%A1%E6%9C%89%E9%87%8D%E6%96%B0%E5%8A%A0%E8%BD%BDuser%20context%E7%9A%84%E5%8A%9F%E8%83%BD%E3%80%82%0ALinux%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95%E5%90%8E%EF%BC%8C%E8%8E%B7%E5%8F%96shell%E5%AE%89%E5%85%A8%E4%B8%8A%E4%B8%8B%E6%96%87%E7%9A%84%E6%AD%A5%E9%AA%A4%EF%BC%8C%E5%8F%AF%E4%BB%A5%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE%E3%80%902%E3%80%91%E3%80%82%E7%AE%80%E8%BF%B0%E5%A6%82%E4%B8%8B%EF%BC%9A%0A1.%20%E6%A0%B9%E6%8D%AEseusers%E6%96%87%E4%BB%B6%EF%BC%8C%E6%98%A0%E5%B0%84SELinux%E7%94%A8%E6%88%B7%EF%BC%8C%E5%A6%82%E6%9E%9C%E6%B2%A1%E6%9C%89seusers%E6%96%87%E4%BB%B6%EF%BC%8C%E7%B3%BB%E7%BB%9F%E5%B0%B1%E6%97%A0%E6%B3%95%E5%90%AF%E5%8A%A8%E4%BA%86%E3%80%82%E5%A6%82%E6%9E%9Cseusers%E6%96%87%E4%BB%B6%E6%B2%A1%E6%9C%89%E5%AF%B9%E5%BA%94%E7%9A%84%E7%94%A8%E6%88%B7%E6%8F%8F%E8%BF%B0%EF%BC%8C%E5%88%99%E7%BB%9F%E4%B8%80%E6%98%A0%E5%B0%84%E4%B8%BA%60__default__%60%E7%94%A8%E6%88%B7%E3%80%82%E5%A6%82%E6%9E%9C%60__default__%60%E7%94%A8%E6%88%B7%E6%8F%8F%E8%BF%B0%E4%B8%8D%E5%AD%98%E5%9C%A8%EF%BC%8C%E5%88%99%E6%97%A0%E6%B3%95%E7%99%BB%E5%BD%95%E3%80%82%0A2.%20%E6%A0%B9%E6%8D%AESELinux%E7%9A%84%E6%90%9C%E7%B4%A2%E4%BC%98%E5%85%88%E7%BA%A7%EF%BC%8C%E6%89%BE%E5%88%B0%E5%AF%B9%E5%BA%94SELinux%E7%94%A8%E6%88%B7%E7%9A%84%E5%AE%89%E5%85%A8%E4%B8%8A%E4%B8%8B%E6%96%87%E3%80%82%0A%0A%3E%20**%E5%8B%98%E8%AF%AF**%0A%3E%20%E5%9C%A8%5B1%5D%E4%B8%AD%EF%BC%8C%E5%AF%B9Linux%E7%94%A8%E6%88%B7%E5%92%8CSELinux%E7%9A%84%E6%98%A0%E5%B0%84%E5%85%B3%E7%B3%BB%E6%9C%89%E5%A6%82%E4%B8%8B%E6%8F%8F%E8%BF%B0%EF%BC%9A%0A%3E%20On%20login%2C%20if%20there%20is%20an%20SELinux%20user%20identifier%20that%20is%20exactly%20the%20same%20as%20the%20Linux%20user%20identifier%2C%20the%20matching%20SELinux%20user%20identifier%20becomes%20the%20user%20identifier%20in%20the%20security%20context%20for%20the%20initial%20shell%20process.%20In%20this%20way%2C%20if%20a%20Linux%20user%20identifier%20also%20exists%20as%20a%20user%20identifier%20in%20the%20SELinux%20policy%2C%20all%20login%20processes%20will%20set%20the%20initial%20shell%20process%20security%20context%20user%20identifier%20to%20that%20matching%20Linux%20identity.%0A%3E%20%E7%BB%8F%E5%AE%9E%E9%AA%8C%E8%AF%81%E6%98%8E%EF%BC%8C%E5%B9%B6%E9%9D%9E%E5%A6%82%E6%AD%A4%EF%BC%9A%0A%3E%20-%20%E5%AE%9A%E4%B9%89%E4%BA%86%E4%B8%80%E4%B8%AAguest_u%E7%94%A8%E6%88%B7%EF%BC%8C%E7%99%BB%E5%BD%95%E5%90%8E%EF%BC%8C%E5%85%B6shell%E7%9A%84%E5%AE%89%E5%85%A8%E4%B8%8A%E4%B8%8B%E6%96%87%E4%BB%8D%E4%B8%BA%EF%BC%9A%0A%3E%20!%5B1ca6909a350aa84947ea565bb4c8eaa2.png%5D(evernotecid%3A%2F%2FACEAA21A-C764-4256-94C6-40CA536E96D7%2Fappyinxiangcom%2F161681%2FENResource%2Fp6434)%0A%3E%20-%20%E4%BD%86%E4%BA%8B%E5%AE%9E%E8%AF%81%E6%98%8E%EF%BC%8C%E6%98%8E%E6%98%8E%E5%B0%B1%E6%9C%89guest_u%E8%BF%99%E4%B8%AA%E7%94%A8%E6%88%B7%0A%3E%20!%5B7737fbc74190005733b9f01b60178907.png%5D(evernotecid%3A%2F%2FACEAA21A-C764-4256-94C6-40CA536E96D7%2Fappyinxiangcom%2F161681%2FENResource%2Fp6436)%0A%3E%20%E6%8E%A8%E6%B5%8B%EF%BC%8C%E5%8F%AF%E8%83%BD%E6%98%AF%E5%9B%A0%E4%B8%BASELinux%E4%B9%9F%E4%B8%80%E7%9B%B4%E5%9C%A8%E5%8F%91%E5%B1%95%E6%94%B9%E8%BF%9B%E4%B8%AD%E3%80%82%5B1%5Dd%20%E6%88%90%E4%B9%A6%E6%97%B6%E9%97%B4%E6%98%AF2006%E5%B9%B4%EF%BC%8C%E5%BD%BC%E6%97%B6%E8%BF%98%E6%98%AFFC%EF%BC%88Fedora%20Core%EF%BC%895%E7%9A%84%E5%B9%B4%E4%BB%A3%EF%BC%8C%E7%8E%B0%E5%9C%A8%E6%9C%80%E6%96%B0%E7%89%88%E5%B7%B2%E7%BB%8F%E6%98%AFFedora%2033%EF%BC%8C2020%E5%B9%B410%E6%9C%88%E4%BB%BD%E5%8F%91%E5%B8%83%E3%80%82%0A%0A%23%23%20%E6%80%BB%E7%BB%93%0A%E7%8E%B0%E5%9C%A8%E5%8F%AF%E4%BB%A5%E5%BC%95%E7%94%A8%5B1%5D%E4%B8%AD%E7%9A%84%E4%B8%80%E5%B9%85%E5%9B%BE%E6%9D%A5%E6%80%BB%E7%BB%93%E4%B8%80%E4%B8%8BRBAC%E7%9A%84%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86%E4%BA%86%E3%80%82%0A!%5B115b4d2e2576fd1b93937d66425645d5.png%5D(evernotecid%3A%2F%2FACEAA21A-C764-4256-94C6-40CA536E96D7%2Fappyinxiangcom%2F161681%2FENResource%2Fp6373)%0A-%20Linux%E7%B3%BB%E7%BB%9F%E6%9C%89%E4%B8%80%E4%B8%AA%E7%94%A8%E6%88%B7%E8%BE%83joe%0A-%20SELinuxcelue%E4%B8%AD%E8%A7%84%E5%AE%9Ajoe%E5%92%8Cuser_r%E7%BB%91%E5%AE%9A%EF%BC%8Cuser_r%E5%92%8Cuser_t%E7%BB%91%E5%AE%9A%0A-%20%E5%BD%93joe%E7%99%BB%E5%BD%95%E6%97%B6%EF%BC%8C%E7%B3%BB%E7%BB%9F%E6%A0%B9%E6%8D%AEseusers%EF%BC%88%E6%AD%A4%E5%A4%84%E4%B8%8E%E5%9B%BE%E4%B8%8D%E5%90%8C%EF%BC%8C%E5%8F%82%E8%A7%81%E4%B8%8A%E4%B8%80%E7%AB%A0%E5%8B%98%E8%AF%AF%EF%BC%89%EF%BC%8C%E6%89%BE%E5%88%B0%E5%AF%B9%E5%BA%94%E7%9A%84SELinux%20user%EF%BC%8C%E6%89%BE%E4%B8%8D%E5%88%B0%E5%B0%B1%E6%98%AF__default__%2C%20__default__%E6%B2%A1%E6%9C%89%E5%B0%B1%E4%B8%8D%E8%83%BD%E7%99%BB%E5%BD%95%E4%BA%86%0A-%20%E6%A0%B9%E6%8D%AE%E4%BB%A5%E4%B8%8Bcontext%E6%96%87%E4%BB%B6%E9%A1%BA%E5%BA%8F%EF%BC%8C%E5%86%B3%E5%AE%9A%E5%85%B6shell%E7%9A%84%E5%AE%89%E5%85%A8%E4%B8%8A%E4%B8%8B%E6%96%87%EF%BC%8C%E5%8D%B3joe%3Auser_r%3Auser_t%0A%20%20%20%20-%20%2Fetc%2Fselinux%2Fspecified-policy%2Fcontexts%2Fusers%0A%20%20%20%20-%20%2Fetc%2Fselinux%2Fspecified-policy%2Fcontexts%2Fdefault_contexts%0A%20%20%20%20-%20%2Fetc%2Fselinux%2Fspecified-policy%2Fcontexts%2Ffailsafe_context%0A%20%20%20%20-%20sid%20kernel%E7%9A%84%E5%AE%89%E5%85%A8%E4%B8%8A%E4%B8%8B%E6%96%87%0A-%20joe%E6%89%A7%E8%A1%8C%E4%BA%86%E4%B8%80%E4%B8%AA%E5%BA%94%E7%94%A8%EF%BC%8C%E5%BC%80%E5%A7%8B%E8%BF%9B%E8%A1%8Cdomain_transition%2C%20%E8%A6%81%E4%BB%8Euser_t%E5%88%87%E6%8D%A2%E5%88%B0passwd_t%0A%20%20%20%20-%20%E5%A6%82%E6%9E%9C%E5%AE%9A%E4%B9%89%E4%BA%86%60role%20user_r%20types%20passwd_t%60%E5%92%8C%60role%20user_r%20types%20user_t%60%EF%BC%8C%E5%88%99%E8%BF%99%E6%AC%A1domain%20transition%E5%8F%AF%E4%BB%A5%E6%88%90%E5%8A%9F%0A%20%20%20%20-%20%E5%90%A6%E5%88%99%E4%BB%BB%E6%84%8F%E4%B8%80%E4%B8%AA%E6%9C%AA%E5%AE%9A%E4%B9%89%EF%BC%8Cdomain%20transition%E9%83%BD%E4%BC%9A%E5%A4%B1%E8%B4%A5%0A%0A%23%20%E9%AB%98%E9%98%B6%E7%94%A8%E6%B3%95%0A%23%23%20role_transition%0Arole%20transition%E5%92%8Cdomain%20transition%E9%9D%9E%E5%B8%B8%E7%B1%BB%E4%BC%BC%EF%BC%8C%E4%B9%9F%E6%98%AF%E5%9C%A8%E6%9F%90%E4%B8%AAdomain%E8%BF%9B%E7%A8%8B%E5%9C%A8%E6%89%A7%E8%A1%8C%E6%9F%90%E4%B8%AA%E5%8F%AF%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6%E6%97%B6%EF%BC%8C%E5%8D%B3exec%E7%B3%BB%E7%BB%9F%E8%B0%83%E7%94%A8%E6%97%B6%EF%BC%8C%E5%88%87%E6%8D%A2%E8%BF%9B%E7%A8%8B%E4%B8%BB%E4%BD%93%E7%9A%84%E5%AE%89%E5%85%A8%E4%B8%8A%E4%B8%8B%E6%96%87%E3%80%82domain%20transition%E5%88%87%E6%8D%A2%E7%9A%84%E6%97%B6domain%EF%BC%8Crole%20transtion%E5%88%87%E6%8D%A2%E7%9A%84%E6%98%AFrole%E3%80%82%E5%AE%9E%E7%8E%B0%E6%96%B9%E5%BC%8F%E9%80%9A%E8%BF%87%E4%BB%A5%E4%B8%8B%E4%B8%A4%E6%9D%A1%E8%AF%AD%E5%8F%A5%EF%BC%9A%0A%60%60%60%0Aallow%20staff_r%20sysadm_r%3B%20%23%20%E5%85%81%E8%AE%B8%E4%BB%8Estaff_r%E5%88%87%E6%8D%A2%E5%88%B0sysadm_r%0Arole_transition%20sysadm_r%20http_exec_t%20system_r%3B%20%23%20sysadm_r%E8%BF%9B%E7%A8%8B%E6%89%A7%E8%A1%8Chttp_exec_t%E7%B1%BB%E5%9E%8B%E6%96%87%E4%BB%B6%E6%97%B6%EF%BC%8Crole%E5%88%87%E6%8D%A2%E4%B8%BAsystem_r%0A%60%60%60%0A%23%23%20role_dominance%0A%E5%8F%AF%E4%BB%A5%E5%88%A9%E7%94%A8role%E6%9D%A5%E5%AE%9A%E4%B9%89%E5%85%B6%E4%BB%96role%EF%BC%8C%E5%8D%B3role%20dominance%E3%80%82%0A%60%60%60%0Adominance%20%7B%20role%20super_r%20%7Brole%20sysadm_r%3B%20role%20secadm_r%3B%20%7D%0A%60%60%60%0A%E4%B8%8A%E9%9D%A2%E4%BE%8B%E5%AD%90%E4%B8%AD%E7%9A%84super_r%E7%A7%B0%E4%B8%BAdominant%20role%EF%BC%8C%E5%AE%83%E5%8F%AF%E4%BB%A5%E4%BB%8E%E5%AE%83%E5%85%B3%E8%81%94%E7%9A%84role%E4%B8%AD%E5%8D%B3%E6%88%90types%E3%80%82%E4%BD%86%E5%AE%83%E5%8F%AA%E8%83%BD%E7%BB%A7%E6%89%BF%E8%AF%A5%E6%9D%A1%E8%AF%AD%E5%8F%A5%E4%B9%8B%E5%89%8D%E5%85%B3%E8%81%94%E7%9A%84types%E3%80%82%E6%88%91%E4%BB%AC%E4%B9%8B%E5%89%8D%E8%AF%B4role%E8%AF%AD%E5%8F%A5%E6%98%AF%E5%8F%AF%E4%BB%A5%E7%B4%AF%E7%A7%AF%E7%9A%84%E3%80%82%E9%82%A3%E4%B9%88%E5%9C%A8role_dominance%E8%AF%AD%E5%8F%A5%E4%B9%8B%E5%90%8E%E5%AE%9A%E4%B9%89%E7%9A%84types%EF%BC%8C%E5%B9%B6%E4%B8%8D%E8%83%BD%E5%8A%A8%E6%80%81%E7%9A%84%E6%B7%BB%E5%8A%A0%E5%88%B0dominant%20role%E4%B8%8A%E3%80%82%0A%23%20%E7%9B%B8%E5%85%B3%E5%B7%A5%E5%85%B7%0A%E8%B7%9Frole%E7%9B%B8%E5%85%B3%E7%9A%84%E4%B8%BB%E8%A6%81%E6%98%AFsemnage%E7%9A%84%E4%B8%80%E4%BA%9B%E7%94%A8%E6%B3%95%EF%BC%8C%E5%8F%A6%E5%A4%96%5B1%5D%E8%BF%98%E4%BB%8B%E7%BB%8D%E4%BA%86%E4%B8%80%E4%B8%AAapol%E7%9A%84%E5%8F%AF%E8%A7%86%E5%8C%96%E5%B7%A5%E5%85%B7%EF%BC%8C%E5%8F%AF%E4%BB%A5%E6%A3%80%E7%B4%A2user%E5%92%8Crole%E7%9A%84%E6%95%B0%E6%8D%AE%E3%80%82%E6%88%91%E7%90%86%E8%A7%A3semanage%E9%80%9A%E8%BF%87%E5%91%BD%E4%BB%A4%E8%A1%8C%E4%B9%9F%E9%83%BD%E5%8F%AF%E4%BB%A5%E5%AE%9E%E7%8E%B0%E3%80%82%0A1.%20%E5%89%8D%E6%96%87%E4%BB%8B%E7%BB%8D%E8%BF%87%E7%9A%84%60semanage%20user%20-l%60%E5%92%8C%60semanage%20login%20-l%60%2C%20%E5%89%8D%E8%80%85%E7%94%A8%E6%9D%A5%E6%9F%A5%E7%9C%8B%E6%89%80%E6%9C%89SELinux%E7%9A%84%E7%94%A8%E6%88%B7%EF%BC%8C%E5%90%8E%E8%80%85%E7%94%A8%E6%9D%A5%E6%9F%A5%E7%9C%8BLinux%E7%94%A8%E6%88%B7%E5%92%8CSELinux%E7%94%A8%E6%88%B7%E4%B8%A4%E8%80%85%E7%9A%84%E6%98%A0%E5%B0%84%E5%85%B3%E7%B3%BB.%0A2.%20Modify%20the%20default%20user%20on%20the%20system%20to%20the%20guest_u%20user%0A%20%20-%20%60semanage%20login%20-m%20-s%20guest_u%20__default__%60%0A3.%20%E4%BF%AE%E6%94%B9user%E5%92%8Crole%E7%9A%84%E5%AF%B9%E5%BA%94%E5%85%B3%E7%B3%BB%0A%20%20-%20%60semanage%20user%20-m%20-R%20%22message_filter_r%20unconfined_r%22%20user_u%60%0A4.%20%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%B8%AA%E7%94%A8%E6%88%B7%E5%B9%B6%E6%8C%87%E5%AE%9ASELinux%E7%94%A8%E6%88%B7%0A%20%20-%20%60useradd%20joe%20-Z%20user_u%60%0A%0A%23%20%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE%0A%5B1%5D%20%5BSELinux%20by%20Example_%20Using%20Security%20Enhanced%20Linux%5D(https%3A%2F%2Fapp.yinxiang.com%2Fshard%2Fs10%2Fnl%2F161681%2Fea41e2f7-d7a8-4629-9f8c-c08696f578af%2F)%0A%5B2%5D%20%5BSELinux%E5%88%9D%E5%A7%8B%E5%8C%96%E7%99%BB%E5%BD%95%E7%94%A8%E6%88%B7%E5%AE%89%E5%85%A8%E4%B8%8A%E4%B8%8B%E6%96%87%E7%9A%84%E6%96%B9%E6%B3%95%5D(https%3A%2F%2Fblog.csdn.net%2Fkeheinash%2Farticle%2Fdetails%2F81047520)%0A

单例模式本身很简单,就是为一个类只创建一个对象。并在全局引用这个对象。单例模式包含了两层涵义:

  • 一个类只有一个对象
  • 这个对象会被全局访问
    要实现一个简单的单例也很容易:
class A {
public:
    static A *GetInstance() {
        if (a != nullptr) {
            a = new A;
        }
        return a;
    }
private:
    A *a;
};

这里我故意用了一个千疮百孔的单例实现。下面我就列出这个单例的问题。

Read more »

SELinux对socket的控制包含这几个方面:

  • context语法中的nodecon, portcon, netifcon:这一类控制本端系统资源,确保合法进程才能访问本端网络资源
  • 通过iptables工具的SECMARK/CONNSECMARK扩展为socket packet打上的标签:这一类控制socket包的流向,确保只有合法进程才能访问某些网络报文
  • NetLable/Labeled IPSec:这一类还没看,留待后面继续学习
    本文关注第二种控制方法,并结合iptables,简要阐述其工作原理和使用方法。

iptables简介

from wiki
iptables is a user-space utility program that allows a system administrator to configure the IP packet filter rules of the Linux kernel firewall, implemented as different Netfilter modules. The filters are organized in different tables, which contain chains of rules for how to treat network traffic packets. Different kernel modules and programs are currently used for different protocols; iptables applies to IPv4, ip6tables to IPv6, arptables to ARP, and ebtables to Ethernet frames.

iptables其实就是Linux的防火墙,用户通过配置各种规则来实现数据包的过滤。他利用了Linux的Netfilter框架的hook点对数据包进行判断,并执行action。例如:

iptables -A INPUT -s 10.10.10.10 -j DROP # 来自10.10.10.10的packet全部被丢弃
iptables -A INPUT -s 10.10.10.0/24 -j DROP # 来自10.10.10.0/255.255.255.0(24表示掩码位数)的packet全部被丢弃

iptables支持的规则很多,具体可以参考iptables(8) - Linux man page

table & chain

如wiki page所述,iptables通过各种tables和chains来管理所有rules。其实chain就是对应了netfilter的hook点。netfilter的hook点有:

The following hooks represent various well-defined points in the networking stack:

  • NF_IP_PRE_ROUTING: This hook will be triggered by any incoming traffic very soon after entering the network stack. This hook is processed before any routing decisions have been made regarding where to send the packet.
  • NF_IP_LOCAL_IN: This hook is triggered after an incoming packet has been routed if the packet is destined for the local system.
  • NF_IP_FORWARD: This hook is triggered after an incoming packet has been routed if the packet is to be forwarded to another host.
  • NF_IP_LOCAL_OUT: This hook is triggered by any locally created outbound traffic as soon it hits the network stack.
  • NF_IP_POST_ROUTING: This hook is triggered by any outgoing or forwarded traffic after routing has taken place and just before being put out on the wire.

而chain就是和这些hook点一一对应的,例如:

  • PREROUTING: Triggered by the NF_IP_PRE_ROUTING hook.
  • INPUT: Triggered by the NF_IP_LOCAL_IN hook.
  • FORWARD: Triggered by the NF_IP_FORWARD hook.
  • OUTPUT: Triggered by the NF_IP_LOCAL_OUT hook.
  • POSTROUTING: Triggered by the NF_IP_POST_ROUTING hook.

而iptables又是怎么遍历这些table和chain的呢?
iptable在各个NetFilter的hook点上,依次遍历各个table的各个chain。其顺序按照如下表格:

  • chain从左到右
  • table从上到下
Tables↓/Chains→PREROUTINGINPUTFORWARDOUTPUTPOSTROUTING
(routing decision)
raw
(connection tracking enabled)
mangle
nat (DNAT)
(routing decision)
filter
security
nat (SNAT)

每个chain和table在整个协议栈的位置如下图。

用户还可以创建自己的chain,使用命令iptables -N <chain name>。然后使用-j参数跳转,例如:iptables -A INPUT -p tcp -j tcp_packets

When/If we reach the end of that chain, we get dropped back to the INPUT chain and the packet starts traversing from the rule one step below where it jumped to the other chain (tcp_packets in this case). If a packet is ACCEPTed within one of the sub chains, it will be ACCEPT’ed in the superset chain also and it will not traverse any of the superset chains any further. However, do note that the packet will traverse all other chains in the other tables in a normal fashion.

总结一下:

  • 如果自定义chain遍历结束,则回到原先跳出的chain(super chain),继续遍历
  • 如果子链(sub chain)中有ACCEPT,则父链中的规则不会再被继续遍历,但仍然会继续遍历其他chain中的规则,以及其他table中的规则。
  • 如果在任意位置,packet被DROP,则后续的chain和table都不会被执行

target

-j除了指定自定义chain外,一个更重要的用途就是指定packet的目的地,也就是target。

Targets on the other hand specify an action to take on the packet in question. We could for example, DROP or ACCEPT the packet depending on what we want to do. There are also a number of other actions we may want to take.
For example: ACCEPT, DROP, CONNMARK, CLASSIFY, LOG ...

  • Some targets will cause the packet to stop traversing that specific chain and superior chains as described above. ex. ACCEPT, DROP
  • Other targets, may take an action on the packet, after which the packet will continue passing through the rest of the rules. ex. LOG, ULOG, TOS
  • Some targets will accept extra options (What TOS value to use etc), while others don’t necessarily need any options.

:以上摘自[5],时间有点久,可能有些已经不成立了(例如[5]中通篇未提到security table),但基本思路应该是保持的。

SECMARK

上一章介绍了iptables的基本工作原理,和table/chain的遍历方法。而可以与SELinux联动,并提供基于socket packet的MAC机制的是iptables的security表格。从上面表格可以看到,security table只有3个chain,即:INPUT,FORWARD,OUTPUT。对应了输入,输出以及转发3种数据流。可以满足基本的packet强制访问控制需求。
一条SECMARK相关的iptables语句如下:

iptables -t security -A INPUT -i lo -p tcp --dport 9999 -j SECMARK --selctx system_u:object_r:ext_gateway_packet_t:s0

其中iptables -t security -A INPUT表示往security table的INPUT chain插入一条规则,match部分-i lo -p tcp --dport 9999表示匹配来自lo网卡,协议为tcp的报文,目标端口为9999的数据包被SECMARK目标进行处理。SECMARK目标使用--selctx参数为该类数据包打上system_u:object_r:ext_gateway_packet_t:s0的安全上下文。则SELinux的策略语法即可以针对该类packet进行权限判断。例如:

allow ext_gateway_t ext_gateway_packet_t : packet { send recv };

CONNSECMARK

CONNSECMARK实际上是SECMARK的扩展。从名字就可以看出CONNSECMARK是针对连接(connection)进行mark动作。iptables的连接管理基于NetFilter的conntrack。conntrack是内核模块,针对不同的协议类型,具有相应的连接控制管理。这已经超出本文的范围了。但不管conntrack多么复杂,功能多么强大,对应到iptables的状态只有4个,即NEW, EATABLISHED, RELATED, INVALID。所有的socket packet都被映射到这4歌状态。具体可以参考文献[5]的Chapter 7. The state machine的User-land states。

  • NEW: tells us that the packet is the first packet that we see.
  • ESTABLISHED: The only requirement to get into an ESTABLISHED state is that one host sends a packet, and that it later on gets a reply from the other host.
  • RELATED: The ESTABLISHED connection will then spawn a connection outside of the main connection. The newly spawned connection will then be considered RELATED, if the conntrack module is able to understand that it is RELATED.
    INVALID: The INVALID state means that the packet can’t be identified or that it does not have any state.

有了这状态定义,iptables就可以使用--state maches。例如:iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT定义了规则,处于ESTABLISHED, RELATED状态的packet才被ACCEPT。
iptables与SELinux配合完全基于对socket packet进行过滤。并没有allow规则,或SELinux object是针对网络连接的。所以,iptables可以通过配合state match以及CONNSECMARK为来自于某个连接的packet进行打标签。方法就是--save和--restore参数。

  • --save

    • Example: iptables -t mangle -A PREROUTING -p tcp --dport 80 -j CONNSECMARK --save
    • Explanation: Save the security context mark from the packet to the connection if the connection is not marked since before.
  • --restore

    • Example: iptables -t mangle -A PREROUTING -p tcp --dport 80 -j CONNSECMARK --restore
    • Explanation: If the packet has no security context mark set on it, the --restore option will set the security context mark associated with the connection on the packet.

总结一下就是:

  • --save将packet数据包的context赋予连接
  • --restore将连接的context赋予packet
    此时SELinux具备更丰富的上下文,来对socket packet进行强制访问控制。

Gateway实验

简介

文献[2]的2.2章节中提供了一个很好的练习,带我们认识iptables与SELinux配合做socket packet强制访问控制的方法。该方法通过iptables和SELinux实现客户端和服务端之间的数据包过滤。整个测试框架示意图如下所示,其中client和secure_client使用同一份源码编译,只是file context有所不同,server和secure_server同理。

示例代码通过定义可执行文件的安全上下文(如下所示),和type_transition规则,使得secure_*进程工作在ext_gateway_t domain,而非secure进程工作在unconfined_t domain。各可执行文件的安全上下文如下所示:

/usr/local/bin/secure_client system_u:object_r:secure_services_exec_t:s0
/usr/local/bin/secure_server system_u:object_r:secure_services_exec_t:s0
/usr/local/bin/client system_u:object_r:unconfined_t:s0
/usr/local/bin/server system_u:object_r:unconfined_t:s0

示例代码中的策略集(.conf)文件定义了示意图中4个方向数据流的权限,包括:

  • 允许访问未标记端口的数据流(default_secmark_packet_t):auditallow unconfined_t default_secmark_packet_t : packet { send recv };
  • 允许secure_*进程访问标记了端口的数据流(ext_gateway_packet_t):allow ext_gateway_t ext_gateway_packet_t : packet { send recv };
  • 允许secure_*进程访问无SECMARK标记的数据流(unconfined_t):allow ext_gateway_t unconfined_t : packet { recv send };
    iptables_secmark使用若干iptables命令,定义数据包的标签规则,例如:
  • 来自于lo网卡的,协议为tcp,目标IP为127.0.0.0,掩码为255.0.0.0输入数据包被设置成default_secmark_packet_t
# This OUTPUT rule sets all packets to default_secmark_packet_t: as it is
iptables -t security -A INPUT -i lo -p tcp -d 127.0.0.0/8 -j SECMARK --selctx system_u:object_r:default_secmark_packet_t:s0
  • 来自于lo网卡的,协议为tcp,目标/源端口为9999的输入/输出数据包被设置成ext_gateway_packet_t(节选)
# These rules will replace the above context with the internal or
iptables -t security -A INPUT -i lo -p tcp --dport 9999 -j SECMARK --selctx system_u:object_r:ext_gateway_packet_t:s0
iptables -t security -A OUTPUT -o lo -p tcp --sport 9999 -j SECMARK --selctx system_u:object_r:ext_gateway_packet_t:s0

两类规则定义的数据包范围实际是有重叠的,根据注释可知,实际两者的关系是,general和特例的关系。即前者将所有特定目标的数据包设置为default_secmark_packet_t,而后者将来自特定端口的数据包指定为ext_gateway_packet_t。
经过此类策略设置,client在访问secure_server时,数据包就会被拦截。查看/var/log/audit/audit.log:

type=AVC msg=audit(1602641071.967:3475): avc:  granted  { send } for  pid=0 comm="swapper/0" saddr=127.0.0.1 src=9999 daddr=127.0.0.1 dest=47076 netif=lo scontext=unconfined_u:message_filter_r:ext_gateway_t:s0-s0:c0.c1023 tcontext=system_u:object_r:ext_gateway_packet_t:s0 tclass=packet

type=AVC msg=audit(1602641071.967:3476): avc:  denied  { recv } for  pid=10 comm="ksoftirqd/0" saddr=127.0.0.1 src=9999 daddr=127.0.0.1 dest=47076 netif=lo scontext=unconfined_u:
unconfined_r:unconfined_t:s0-s0:c0.c1023 tcontext=system_u:object_r:ext_gateway_packet_t:s0 tclass=packet permissive=0

client连接secure_server监听的9999端口,数据流为:tcp,127.0.0.1:9999 => 127.0.0.1:47076。secure_server向client发送成功,但client接收失败。因为client运行于unconfined_t,没有对应ext_gateway_packet_t的recv权限。

勘误

参考文献[2]因为成书过久(写于2014年,现在2020年),且练习基于书中前导章节中的modular-test章节,所以直接运行会产生错误。错误主要包含:

  • 基于modular-test构建ext_gateway策略。因为可能是发行版变化(笔者用的CentOS8)或者时间过久的原因,直接用书中的基础策略会造成无法开机,所以modular-test练习中的策略不可用。解决方法是,编译ext_gateway module,并用semodule插入发行版自带的策略中。此时需要针对原生策略进行适配。例如:进程拉起时报错,需要增加相应allow规则,节选如下:
allow ext_gateway_t null_device_t : chr_file { read write open };
allow ext_gateway_t ld_so_t : file { map read execute };
allow ext_gateway_t ld_so_cache_t : file { open map read execute getattr };
allow ext_gateway_t lib_t : file { open map read execute getattr };
...
  • 本书给出的示例代码的安全上下文未给出mls描述,在编译时会报错。例如:
iptables -t security -A INPUT -i lo -p tcp --dport 9999 -j SECMARK --selctx system_u:object_r:ext_gateway_packet_t:s0
iptables -t security -A INPUT -i lo -p tcp --sport 9999 -j SECMARK --selctx system_u:object_r:ext_gateway_packet_t:s0
/usr/local/bin/secure_client system_u:object_r:secure_services_exec_t:s0

所有的context都加上了:s0
经过适配后,书中提供的示例可以顺利跑通,如下:
server

参考文献

[1] SELinux Networking Support

[2] The SELinux Notebook - Building The Sample Policy

[3] iptables wiki page

[4] A Deep Dive into Iptables and Netfilter Architecture

[5] Oskar Andreasson, 2001-2006, Iptables Tutorial 1.2.2

SELinux%E5%AF%B9socket%E7%9A%84%E6%8E%A7%E5%88%B6%E5%8C%85%E5%90%AB%E8%BF%99%E5%87%A0%E4%B8%AA%E6%96%B9%E9%9D%A2%EF%BC%9A%0A-%20context%E8%AF%AD%E6%B3%95%E4%B8%AD%E7%9A%84nodecon%2C%20portcon%2C%20netifcon%EF%BC%9A%E8%BF%99%E4%B8%80%E7%B1%BB%E6%8E%A7%E5%88%B6%E6%9C%AC%E7%AB%AF%E7%B3%BB%E7%BB%9F%E8%B5%84%E6%BA%90%EF%BC%8C%E7%A1%AE%E4%BF%9D%E5%90%88%E6%B3%95%E8%BF%9B%E7%A8%8B%E6%89%8D%E8%83%BD%E8%AE%BF%E9%97%AE%E6%9C%AC%E7%AB%AF%E7%BD%91%E7%BB%9C%E8%B5%84%E6%BA%90%0A-%20%E9%80%9A%E8%BF%87iptables%E5%B7%A5%E5%85%B7%E7%9A%84SECMARK%2FCONNSECMARK%E6%89%A9%E5%B1%95%E4%B8%BAsocket%20packet%E6%89%93%E4%B8%8A%E7%9A%84%E6%A0%87%E7%AD%BE%EF%BC%9A%E8%BF%99%E4%B8%80%E7%B1%BB%E6%8E%A7%E5%88%B6socket%E5%8C%85%E7%9A%84%E6%B5%81%E5%90%91%EF%BC%8C%E7%A1%AE%E4%BF%9D%E5%8F%AA%E6%9C%89%E5%90%88%E6%B3%95%E8%BF%9B%E7%A8%8B%E6%89%8D%E8%83%BD%E8%AE%BF%E9%97%AE%E6%9F%90%E4%BA%9B%E7%BD%91%E7%BB%9C%E6%8A%A5%E6%96%87%0A-%20NetLable%2FLabeled%20IPSec%EF%BC%9A%E8%BF%99%E4%B8%80%E7%B1%BB%E8%BF%98%E6%B2%A1%E7%9C%8B%EF%BC%8C%E7%95%99%E5%BE%85%E5%90%8E%E9%9D%A2%E7%BB%A7%E7%BB%AD%E5%AD%A6%E4%B9%A0%0A%E6%9C%AC%E6%96%87%E5%85%B3%E6%B3%A8%E7%AC%AC%E4%BA%8C%E7%A7%8D%E6%8E%A7%E5%88%B6%E6%96%B9%E6%B3%95%EF%BC%8C%E5%B9%B6%E7%BB%93%E5%90%88iptables%EF%BC%8C%E7%AE%80%E8%A6%81%E9%98%90%E8%BF%B0%E5%85%B6%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86%E5%92%8C%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95%E3%80%82%0A%23%20iptables%E7%AE%80%E4%BB%8B%0A%3E%20**from%20wiki**%0A%3E%20iptables%20is%20a%20user-space%20utility%20program%20that%20allows%20a%20system%20administrator%20to%20configure%20the%20IP%20packet%20filter%20rules%20of%20the%20Linux%20kernel%20firewall%2C%20implemented%20as%20different%20Netfilter%20modules.%20The%20filters%20are%20organized%20**in%20different%20tables%2C%20which%20contain%20chains%20of%20rules**%20for%20how%20to%20treat%20network%20traffic%20packets.%20Different%20kernel%20modules%20and%20programs%20are%20currently%20used%20for%20different%20protocols%3B%20iptables%20applies%20to%20IPv4%2C%20ip6tables%20to%20IPv6%2C%20arptables%20to%20ARP%2C%20and%20ebtables%20to%20Ethernet%20frames.%0A%0Aiptables%E5%85%B6%E5%AE%9E%E5%B0%B1%E6%98%AFLinux%E7%9A%84%E9%98%B2%E7%81%AB%E5%A2%99%EF%BC%8C%E7%94%A8%E6%88%B7%E9%80%9A%E8%BF%87%E9%85%8D%E7%BD%AE%E5%90%84%E7%A7%8D%E8%A7%84%E5%88%99%E6%9D%A5%E5%AE%9E%E7%8E%B0%E6%95%B0%E6%8D%AE%E5%8C%85%E7%9A%84%E8%BF%87%E6%BB%A4%E3%80%82%E4%BB%96%E5%88%A9%E7%94%A8%E4%BA%86Linux%E7%9A%84Netfilter%E6%A1%86%E6%9E%B6%E7%9A%84hook%E7%82%B9%E5%AF%B9%E6%95%B0%E6%8D%AE%E5%8C%85%E8%BF%9B%E8%A1%8C%E5%88%A4%E6%96%AD%EF%BC%8C%E5%B9%B6%E6%89%A7%E8%A1%8Caction%E3%80%82%E4%BE%8B%E5%A6%82%EF%BC%9A%0A%60%60%60shell%0Aiptables%20-A%20INPUT%20-s%2010.10.10.10%20-j%20DROP%20%23%20%E6%9D%A5%E8%87%AA10.10.10.10%E7%9A%84packet%E5%85%A8%E9%83%A8%E8%A2%AB%E4%B8%A2%E5%BC%83%0Aiptables%20-A%20INPUT%20-s%2010.10.10.0%2F24%20-j%20DROP%20%23%20%E6%9D%A5%E8%87%AA10.10.10.0%2F255.255.255.0%EF%BC%8824%E8%A1%A8%E7%A4%BA%E6%8E%A9%E7%A0%81%E4%BD%8D%E6%95%B0%EF%BC%89%E7%9A%84packet%E5%85%A8%E9%83%A8%E8%A2%AB%E4%B8%A2%E5%BC%83%0A%60%60%60%0Aiptables%E6%94%AF%E6%8C%81%E7%9A%84%E8%A7%84%E5%88%99%E5%BE%88%E5%A4%9A%EF%BC%8C%E5%85%B7%E4%BD%93%E5%8F%AF%E4%BB%A5%E5%8F%82%E8%80%83%5Biptables(8)%20-%20Linux%20man%20page%5D(https%3A%2F%2Flinux.die.net%2Fman%2F8%2Fiptables)%E3%80%82%0A%0A%23%23%20table%20%26%20chain%0A%E5%A6%82wiki%20page%E6%89%80%E8%BF%B0%EF%BC%8Ciptables%E9%80%9A%E8%BF%87%E5%90%84%E7%A7%8Dtables%E5%92%8Cchains%E6%9D%A5%E7%AE%A1%E7%90%86%E6%89%80%E6%9C%89rules%E3%80%82%E5%85%B6%E5%AE%9Echain%E5%B0%B1%E6%98%AF%E5%AF%B9%E5%BA%94%E4%BA%86netfilter%E7%9A%84hook%E7%82%B9%E3%80%82netfilter%E7%9A%84hook%E7%82%B9%E6%9C%89%EF%BC%9A%0A%3E%20The%20following%20hooks%20represent%20various%20well-defined%20points%20in%20the%20networking%20stack%3A%0A%3E%0A%3E-%20NF_IP_PRE_ROUTING%3A%20This%20hook%20will%20be%20triggered%20by%20any%20incoming%20traffic%20very%20soon%20after%20entering%20the%20network%20stack.%20This%20hook%20is%20processed%20before%20any%20routing%20decisions%20have%20been%20made%20regarding%20where%20to%20send%20the%20packet.%0A%3E-%20NF_IP_LOCAL_IN%3A%20This%20hook%20is%20triggered%20after%20an%20incoming%20packet%20has%20been%20routed%20if%20the%20packet%20is%20destined%20for%20the%20local%20system.%0A%3E-%20NF_IP_FORWARD%3A%20This%20hook%20is%20triggered%20after%20an%20incoming%20packet%20has%20been%20routed%20if%20the%20packet%20is%20to%20be%20forwarded%20to%20another%20host.%0A%3E-%20NF_IP_LOCAL_OUT%3A%20This%20hook%20is%20triggered%20by%20any%20locally%20created%20outbound%20traffic%20as%20soon%20it%20hits%20the%20network%20stack.%0A%3E-%20NF_IP_POST_ROUTING%3A%20This%20hook%20is%20triggered%20by%20any%20outgoing%20or%20forwarded%20traffic%20after%20routing%20has%20taken%20place%20and%20just%20before%20being%20put%20out%20on%20the%20wire.%0A%0A%E8%80%8Cchain%E5%B0%B1%E6%98%AF%E5%92%8C%E8%BF%99%E4%BA%9Bhook%E7%82%B9%E4%B8%80%E4%B8%80%E5%AF%B9%E5%BA%94%E7%9A%84%EF%BC%8C%E4%BE%8B%E5%A6%82%EF%BC%9A%0A%3E%20-%20PREROUTING%3A%20Triggered%20by%20the%20NF_IP_PRE_ROUTING%20hook.%0A%3E-%20INPUT%3A%20Triggered%20by%20the%20NF_IP_LOCAL_IN%20hook.%0A%3E-%20FORWARD%3A%20Triggered%20by%20the%20NF_IP_FORWARD%20hook.%0A%3E-%20OUTPUT%3A%20Triggered%20by%20the%20NF_IP_LOCAL_OUT%20hook.%0A%3E-%20POSTROUTING%3A%20Triggered%20by%20the%20NF_IP_POST_ROUTING%20hook.%0A%0A%E8%80%8Ciptables%E5%8F%88%E6%98%AF%E6%80%8E%E4%B9%88%E9%81%8D%E5%8E%86%E8%BF%99%E4%BA%9Btable%E5%92%8Cchain%E7%9A%84%E5%91%A2%EF%BC%9F%0Aiptable%E5%9C%A8%E5%90%84%E4%B8%AANetFilter%E7%9A%84hook%E7%82%B9%E4%B8%8A%EF%BC%8C%E4%BE%9D%E6%AC%A1%E9%81%8D%E5%8E%86%E5%90%84%E4%B8%AAtable%E7%9A%84%E5%90%84%E4%B8%AAchain%E3%80%82%E5%85%B6%E9%A1%BA%E5%BA%8F%E6%8C%89%E7%85%A7%E5%A6%82%E4%B8%8B%E8%A1%A8%E6%A0%BC%EF%BC%9A%0A-%20chain%E4%BB%8E%E5%B7%A6%E5%88%B0%E5%8F%B3%0A-%20table%E4%BB%8E%E4%B8%8A%E5%88%B0%E4%B8%8B%0A%0A%7C%20Tables%E2%86%93%2FChains%E2%86%92%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%20PREROUTING%20%7C%20INPUT%20%7C%20FORWARD%20%7C%20OUTPUT%20%7C%20POSTROUTING%20%7C%0A%7C-------------------------------%7C------------%7C-------%7C---------%7C--------%7C-------------%7C%0A%7C%20(routing%20decision)%20%20%20%20%20%20%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%0A%7C%20raw%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%0A%7C%20(connection%20tracking%20enabled)%20%7C%20%E2%9C%93%20%20%20%20%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%0A%7C%20mangle%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%20%20%20%20%20%7C%0A%7C%20nat%20(DNAT)%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%0A%7C%20(routing%20decision)%20%20%20%20%20%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%0A%7C%20filter%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%0A%7C%20security%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%0A%7C%20nat%20(SNAT)%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%7C%20%20%20%20%20%20%20%20%20%7C%20%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%20%20%20%20%20%7C%0A%E6%AF%8F%E4%B8%AAchain%E5%92%8Ctable%E5%9C%A8%E6%95%B4%E4%B8%AA%E5%8D%8F%E8%AE%AE%E6%A0%88%E7%9A%84%E4%BD%8D%E7%BD%AE%E5%A6%82%E4%B8%8B%E5%9B%BE%E3%80%82%0A%0A!%5Bfcbd15b235c892be235e74cb0e2f537f.png%5D(evernotecid%3A%2F%2FACEAA21A-C764-4256-94C6-40CA536E96D7%2Fappyinxiangcom%2F161681%2FENResource%2Fp6309)%0A%0A%E7%94%A8%E6%88%B7%E8%BF%98%E5%8F%AF%E4%BB%A5%E5%88%9B%E5%BB%BA%E8%87%AA%E5%B7%B1%E7%9A%84chain%EF%BC%8C%E4%BD%BF%E7%94%A8%E5%91%BD%E4%BB%A4%60iptables%20-N%20%3Cchain%20name%3E%60%E3%80%82%E7%84%B6%E5%90%8E%E4%BD%BF%E7%94%A8%60-j%60%E5%8F%82%E6%95%B0%E8%B7%B3%E8%BD%AC%EF%BC%8C%E4%BE%8B%E5%A6%82%EF%BC%9A%60iptables%20-A%20INPUT%20-p%20tcp%20-j%20tcp_packets%60%0A%3E%20When%2FIf%20we%20reach%20the%20end%20of%20that%20chain%2C%20we%20get%20dropped%20back%20to%20the%20INPUT%20chain%20and%20the%20packet%20starts%20traversing%20from%20the%20rule%20one%20step%20below%20where%20it%20jumped%20to%20the%20other%20chain%20(tcp_packets%20in%20this%20case).%20If%20a%20packet%20is%20ACCEPTed%20within%20one%20of%20the%20sub%20chains%2C%20it%20will%20be%20ACCEPT%E2%80%99ed%20in%20the%20superset%20chain%20also%20and%20it%20will%20not%20traverse%20any%20of%20the%20superset%20chains%20any%20further.%20However%2C%20do%20note%20that%20the%20packet%20will%20traverse%20all%20other%20chains%20in%20the%20other%20tables%20in%20a%20normal%20fashion.%0A%0A%E6%80%BB%E7%BB%93%E4%B8%80%E4%B8%8B%EF%BC%9A%0A-%20%E5%A6%82%E6%9E%9C%E8%87%AA%E5%AE%9A%E4%B9%89chain%E9%81%8D%E5%8E%86%E7%BB%93%E6%9D%9F%EF%BC%8C%E5%88%99%E5%9B%9E%E5%88%B0%E5%8E%9F%E5%85%88%E8%B7%B3%E5%87%BA%E7%9A%84chain%EF%BC%88super%20chain%EF%BC%89%EF%BC%8C%E7%BB%A7%E7%BB%AD%E9%81%8D%E5%8E%86%0A-%20%E5%A6%82%E6%9E%9C%E5%AD%90%E9%93%BE%EF%BC%88sub%20chain%EF%BC%89%E4%B8%AD%E6%9C%89ACCEPT%EF%BC%8C%E5%88%99%E7%88%B6%E9%93%BE%E4%B8%AD%E7%9A%84%E8%A7%84%E5%88%99%E4%B8%8D%E4%BC%9A%E5%86%8D%E8%A2%AB%E7%BB%A7%E7%BB%AD%E9%81%8D%E5%8E%86%EF%BC%8C%E4%BD%86%E4%BB%8D%E7%84%B6%E4%BC%9A%E7%BB%A7%E7%BB%AD%E9%81%8D%E5%8E%86%E5%85%B6%E4%BB%96chain%E4%B8%AD%E7%9A%84%E8%A7%84%E5%88%99%EF%BC%8C%E4%BB%A5%E5%8F%8A%E5%85%B6%E4%BB%96table%E4%B8%AD%E7%9A%84%E8%A7%84%E5%88%99%E3%80%82%0A-%20%E5%A6%82%E6%9E%9C%E5%9C%A8%E4%BB%BB%E6%84%8F%E4%BD%8D%E7%BD%AE%EF%BC%8Cpacket%E8%A2%ABDROP%EF%BC%8C%E5%88%99%E5%90%8E%E7%BB%AD%E7%9A%84chain%E5%92%8Ctable%E9%83%BD%E4%B8%8D%E4%BC%9A%E8%A2%AB%E6%89%A7%E8%A1%8C%0A%23%23%20target%0A%60-j%60%E9%99%A4%E4%BA%86%E6%8C%87%E5%AE%9A%E8%87%AA%E5%AE%9A%E4%B9%89chain%E5%A4%96%EF%BC%8C%E4%B8%80%E4%B8%AA%E6%9B%B4%E9%87%8D%E8%A6%81%E7%9A%84%E7%94%A8%E9%80%94%E5%B0%B1%E6%98%AF%E6%8C%87%E5%AE%9Apacket%E7%9A%84%E7%9B%AE%E7%9A%84%E5%9C%B0%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AFtarget%E3%80%82%0A%0A%3ETargets%20on%20the%20other%20hand%20specify%20an%20action%20to%20take%20on%20the%20packet%20in%20question.%20We%20could%20for%20example%2C%20DROP%20or%20ACCEPT%20the%20packet%20depending%20on%20what%20we%20want%20to%20do.%20There%20are%20also%20a%20number%20of%20other%20actions%20we%20may%20want%20to%20take.%0A%3EFor%20example%3A%20ACCEPT%2C%20DROP%2C%20CONNMARK%2C%20CLASSIFY%2C%20LOG%20...%0A%0A-%20Some%20targets%20will%20cause%20the%20packet%20to%20stop%20traversing%20that%20speci%EF%AC%81c%20chain%20and%20superior%20chains%20as%20described%20above.%20ex.%20ACCEPT%2C%20DROP%0A-%20Other%20targets%2C%20may%20take%20an%20action%20on%20the%20packet%2C%20after%20which%20the%20packet%20will%20continue%20passing%20through%20the%20rest%20of%20the%20rules.%20ex.%20LOG%2C%20ULOG%2C%20TOS%0A-%20Some%20targets%20will%20accept%20extra%20options%20(What%20TOS%20value%20to%20use%20etc)%2C%20while%20others%20don%E2%80%99t%20necessarily%20need%20any%20options.%0A%0A**%E6%B3%A8**%EF%BC%9A%E4%BB%A5%E4%B8%8A%E6%91%98%E8%87%AA%5B5%5D%2C%E6%97%B6%E9%97%B4%E6%9C%89%E7%82%B9%E4%B9%85%EF%BC%8C%E5%8F%AF%E8%83%BD%E6%9C%89%E4%BA%9B%E5%B7%B2%E7%BB%8F%E4%B8%8D%E6%88%90%E7%AB%8B%E4%BA%86%EF%BC%88%E4%BE%8B%E5%A6%82%5B5%5D%E4%B8%AD%E9%80%9A%E7%AF%87%E6%9C%AA%E6%8F%90%E5%88%B0security%20table)%EF%BC%8C%E4%BD%86%E5%9F%BA%E6%9C%AC%E6%80%9D%E8%B7%AF%E5%BA%94%E8%AF%A5%E6%98%AF%E4%BF%9D%E6%8C%81%E7%9A%84%E3%80%82%0A%23%20SECMARK%0A%E4%B8%8A%E4%B8%80%E7%AB%A0%E4%BB%8B%E7%BB%8D%E4%BA%86iptables%E7%9A%84%E5%9F%BA%E6%9C%AC%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86%EF%BC%8C%E5%92%8Ctable%2Fchain%E7%9A%84%E9%81%8D%E5%8E%86%E6%96%B9%E6%B3%95%E3%80%82%E8%80%8C%E5%8F%AF%E4%BB%A5%E4%B8%8ESELinux%E8%81%94%E5%8A%A8%EF%BC%8C%E5%B9%B6%E6%8F%90%E4%BE%9B%E5%9F%BA%E4%BA%8Esocket%20packet%E7%9A%84MAC%E6%9C%BA%E5%88%B6%E7%9A%84%E6%98%AFiptables%E7%9A%84security%E8%A1%A8%E6%A0%BC%E3%80%82%E4%BB%8E%E4%B8%8A%E9%9D%A2%E8%A1%A8%E6%A0%BC%E5%8F%AF%E4%BB%A5%E7%9C%8B%E5%88%B0%EF%BC%8Csecurity%20table%E5%8F%AA%E6%9C%893%E4%B8%AAchain%EF%BC%8C%E5%8D%B3%EF%BC%9AINPUT%EF%BC%8CFORWARD%EF%BC%8COUTPUT%E3%80%82%E5%AF%B9%E5%BA%94%E4%BA%86%E8%BE%93%E5%85%A5%EF%BC%8C%E8%BE%93%E5%87%BA%E4%BB%A5%E5%8F%8A%E8%BD%AC%E5%8F%913%E7%A7%8D%E6%95%B0%E6%8D%AE%E6%B5%81%E3%80%82%E5%8F%AF%E4%BB%A5%E6%BB%A1%E8%B6%B3%E5%9F%BA%E6%9C%AC%E7%9A%84packet%E5%BC%BA%E5%88%B6%E8%AE%BF%E9%97%AE%E6%8E%A7%E5%88%B6%E9%9C%80%E6%B1%82%E3%80%82%0A%E4%B8%80%E6%9D%A1SECMARK%E7%9B%B8%E5%85%B3%E7%9A%84iptables%E8%AF%AD%E5%8F%A5%E5%A6%82%E4%B8%8B%EF%BC%9A%0A%60%60%60shell%0Aiptables%20-t%20security%20-A%20INPUT%20-i%20lo%20-p%20tcp%20--dport%209999%20-j%20SECMARK%20--selctx%20system_u%3Aobject_r%3Aext_gateway_packet_t%3As0%0A%60%60%60%0A%E5%85%B6%E4%B8%AD%60iptables%20-t%20security%20-A%20INPUT%60%E8%A1%A8%E7%A4%BA%E5%BE%80security%20table%E7%9A%84INPUT%20chain%E6%8F%92%E5%85%A5%E4%B8%80%E6%9D%A1%E8%A7%84%E5%88%99%EF%BC%8Cmatch%E9%83%A8%E5%88%86%60-i%20lo%20-p%20tcp%20--dport%209999%60%E8%A1%A8%E7%A4%BA%E5%8C%B9%E9%85%8D%E6%9D%A5%E8%87%AAlo%E7%BD%91%E5%8D%A1%EF%BC%8C%E5%8D%8F%E8%AE%AE%E4%B8%BAtcp%E7%9A%84%E6%8A%A5%E6%96%87%EF%BC%8C%E7%9B%AE%E6%A0%87%E7%AB%AF%E5%8F%A3%E4%B8%BA9999%E7%9A%84%E6%95%B0%E6%8D%AE%E5%8C%85%E8%A2%ABSECMARK%E7%9B%AE%E6%A0%87%E8%BF%9B%E8%A1%8C%E5%A4%84%E7%90%86%E3%80%82SECMARK%E7%9B%AE%E6%A0%87%E4%BD%BF%E7%94%A8--selctx%E5%8F%82%E6%95%B0%E4%B8%BA%E8%AF%A5%E7%B1%BB%E6%95%B0%E6%8D%AE%E5%8C%85%E6%89%93%E4%B8%8A%60system_u%3Aobject_r%3Aext_gateway_packet_t%3As0%60%E7%9A%84%E5%AE%89%E5%85%A8%E4%B8%8A%E4%B8%8B%E6%96%87%E3%80%82%E5%88%99SELinux%E7%9A%84%E7%AD%96%E7%95%A5%E8%AF%AD%E6%B3%95%E5%8D%B3%E5%8F%AF%E4%BB%A5%E9%92%88%E5%AF%B9%E8%AF%A5%E7%B1%BBpacket%E8%BF%9B%E8%A1%8C%E6%9D%83%E9%99%90%E5%88%A4%E6%96%AD%E3%80%82%E4%BE%8B%E5%A6%82%3A%0A%60%60%60%0Aallow%20ext_gateway_t%20ext_gateway_packet_t%20%3A%20packet%20%7B%20send%20recv%20%7D%3B%0A%60%60%60%0A%23%20CONNSECMARK%0ACONNSECMARK%E5%AE%9E%E9%99%85%E4%B8%8A%E6%98%AFSECMARK%E7%9A%84%E6%89%A9%E5%B1%95%E3%80%82%E4%BB%8E%E5%90%8D%E5%AD%97%E5%B0%B1%E5%8F%AF%E4%BB%A5%E7%9C%8B%E5%87%BACONNSECMARK%E6%98%AF%E9%92%88%E5%AF%B9%E8%BF%9E%E6%8E%A5%EF%BC%88connection%EF%BC%89%E8%BF%9B%E8%A1%8Cmark%E5%8A%A8%E4%BD%9C%E3%80%82iptables%E7%9A%84%E8%BF%9E%E6%8E%A5%E7%AE%A1%E7%90%86%E5%9F%BA%E4%BA%8ENetFilter%E7%9A%84conntrack%E3%80%82conntrack%E6%98%AF%E5%86%85%E6%A0%B8%E6%A8%A1%E5%9D%97%EF%BC%8C%E9%92%88%E5%AF%B9%E4%B8%8D%E5%90%8C%E7%9A%84%E5%8D%8F%E8%AE%AE%E7%B1%BB%E5%9E%8B%EF%BC%8C%E5%85%B7%E6%9C%89%E7%9B%B8%E5%BA%94%E7%9A%84%E8%BF%9E%E6%8E%A5%E6%8E%A7%E5%88%B6%E7%AE%A1%E7%90%86%E3%80%82%E8%BF%99%E5%B7%B2%E7%BB%8F%E8%B6%85%E5%87%BA%E6%9C%AC%E6%96%87%E7%9A%84%E8%8C%83%E5%9B%B4%E4%BA%86%E3%80%82%E4%BD%86%E4%B8%8D%E7%AE%A1conntrack%E5%A4%9A%E4%B9%88%E5%A4%8D%E6%9D%82%EF%BC%8C%E5%8A%9F%E8%83%BD%E5%A4%9A%E4%B9%88%E5%BC%BA%E5%A4%A7%EF%BC%8C%E5%AF%B9%E5%BA%94%E5%88%B0iptables%E7%9A%84%E7%8A%B6%E6%80%81%E5%8F%AA%E6%9C%894%E4%B8%AA%EF%BC%8C%E5%8D%B3NEW%2C%20EATABLISHED%2C%20RELATED%2C%20INVALID%E3%80%82%E6%89%80%E6%9C%89%E7%9A%84socket%20packet%E9%83%BD%E8%A2%AB%E6%98%A0%E5%B0%84%E5%88%B0%E8%BF%994%E6%AD%8C%E7%8A%B6%E6%80%81%E3%80%82%E5%85%B7%E4%BD%93%E5%8F%AF%E4%BB%A5%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE%5B5%5D%E7%9A%84Chapter%207.%20The%20state%20machine%E7%9A%84User-land%20states%E3%80%82%0A%3E%20-%20NEW%3A%20tells%20us%20that%20the%20packet%20is%20the%20%EF%AC%81rst%20packet%20that%20we%20see.%0A%3E%20-%20ESTABLISHED%3A%20The%20only%20requirement%20to%20get%20into%20an%20ESTABLISHED%20state%20is%20that%20one%20host%20sends%20a%20packet%2C%20and%20that%20it%20later%20on%20gets%20a%20reply%20from%20the%20other%20host.%0A%3E%20-%20RELATED%3A%20The%20ESTABLISHED%20connection%20will%20then%20spawn%20a%20connection%20outside%20of%20the%20main%20connection.%20The%20newly%20spawned%20connection%20will%20then%20be%20considered%20RELATED%2C%20if%20the%20conntrack%20module%20is%20able%20to%20understand%20that%20it%20is%20RELATED.%0A%3E%20INVALID%3A%20The%20INVALID%20state%20means%20that%20the%20packet%20can%E2%80%99t%20be%20identi%EF%AC%81ed%20or%20that%20it%20does%20not%20have%20any%20state.%0A%0A%E6%9C%89%E4%BA%86%E8%BF%99%E7%8A%B6%E6%80%81%E5%AE%9A%E4%B9%89%EF%BC%8Ciptables%E5%B0%B1%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8--state%20maches%E3%80%82%E4%BE%8B%E5%A6%82%EF%BC%9A%60iptables%20-A%20INPUT%20-m%20state%20--state%20ESTABLISHED%2CRELATED%20-j%20ACCEPT%60%E5%AE%9A%E4%B9%89%E4%BA%86%E8%A7%84%E5%88%99%EF%BC%8C%E5%A4%84%E4%BA%8EESTABLISHED%2C%20RELATED%E7%8A%B6%E6%80%81%E7%9A%84packet%E6%89%8D%E8%A2%ABACCEPT%E3%80%82%0Aiptables%E4%B8%8ESELinux%E9%85%8D%E5%90%88%E5%AE%8C%E5%85%A8%E5%9F%BA%E4%BA%8E%E5%AF%B9socket%20packet%E8%BF%9B%E8%A1%8C%E8%BF%87%E6%BB%A4%E3%80%82%E5%B9%B6%E6%B2%A1%E6%9C%89allow%E8%A7%84%E5%88%99%EF%BC%8C%E6%88%96SELinux%20object%E6%98%AF%E9%92%88%E5%AF%B9%E7%BD%91%E7%BB%9C%E8%BF%9E%E6%8E%A5%E7%9A%84%E3%80%82%E6%89%80%E4%BB%A5%EF%BC%8Ciptables%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%E9%85%8D%E5%90%88state%20match%E4%BB%A5%E5%8F%8ACONNSECMARK%E4%B8%BA%E6%9D%A5%E8%87%AA%E4%BA%8E%E6%9F%90%E4%B8%AA%E8%BF%9E%E6%8E%A5%E7%9A%84packet%E8%BF%9B%E8%A1%8C%E6%89%93%E6%A0%87%E7%AD%BE%E3%80%82%E6%96%B9%E6%B3%95%E5%B0%B1%E6%98%AF--save%E5%92%8C--restore%E5%8F%82%E6%95%B0%E3%80%82%0A%0A-%20--save%20%0A%20%20%20%20-%20Example%3A%20%60iptables%20-t%20mangle%20-A%20PREROUTING%20-p%20tcp%20--dport%2080%20-j%20CONNSECMARK%20--save%60%0A%20%20%20%20-%20Explanation%3A%20Save%20the%20security%20context%20mark%20from%20the%20packet%20to%20the%20connection%20if%20the%20connection%20is%20not%20marked%20since%20before.%0A%0A-%20--restore%0A%20%20%20%20-%20Example%3A%20%60iptables%20-t%20mangle%20-A%20PREROUTING%20-p%20tcp%20--dport%2080%20-j%20CONNSECMARK%20--restore%60%0A%20%20%20%20-%20Explanation%3A%20If%20the%20packet%20has%20no%20security%20context%20mark%20set%20on%20it%2C%20the%20--restore%20option%20will%20set%20the%20security%20context%20mark%20associated%20with%20the%20connection%20on%20the%20packet.%0A%0A%E6%80%BB%E7%BB%93%E4%B8%80%E4%B8%8B%E5%B0%B1%E6%98%AF%EF%BC%9A%0A-%20--save%E5%B0%86packet%E6%95%B0%E6%8D%AE%E5%8C%85%E7%9A%84context%E8%B5%8B%E4%BA%88%E8%BF%9E%E6%8E%A5%0A-%20--restore%E5%B0%86%E8%BF%9E%E6%8E%A5%E7%9A%84context%E8%B5%8B%E4%BA%88packet%0A%E6%AD%A4%E6%97%B6SELinux%E5%85%B7%E5%A4%87%E6%9B%B4%E4%B8%B0%E5%AF%8C%E7%9A%84%E4%B8%8A%E4%B8%8B%E6%96%87%EF%BC%8C%E6%9D%A5%E5%AF%B9socket%20packet%E8%BF%9B%E8%A1%8C%E5%BC%BA%E5%88%B6%E8%AE%BF%E9%97%AE%E6%8E%A7%E5%88%B6%E3%80%82%0A%23%20Gateway%E5%AE%9E%E9%AA%8C%0A%23%23%20%E7%AE%80%E4%BB%8B%0A%E6%96%87%E7%8C%AE%5B2%5D%E7%9A%842.2%E7%AB%A0%E8%8A%82%E4%B8%AD%E6%8F%90%E4%BE%9B%E4%BA%86%E4%B8%80%E4%B8%AA%E5%BE%88%E5%A5%BD%E7%9A%84%E7%BB%83%E4%B9%A0%EF%BC%8C%E5%B8%A6%E6%88%91%E4%BB%AC%E8%AE%A4%E8%AF%86iptables%E4%B8%8ESELinux%E9%85%8D%E5%90%88%E5%81%9Asocket%20packet%E5%BC%BA%E5%88%B6%E8%AE%BF%E9%97%AE%E6%8E%A7%E5%88%B6%E7%9A%84%E6%96%B9%E6%B3%95%E3%80%82%E8%AF%A5%E6%96%B9%E6%B3%95%E9%80%9A%E8%BF%87iptables%E5%92%8CSELinux%E5%AE%9E%E7%8E%B0%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AB%AF%E4%B9%8B%E9%97%B4%E7%9A%84%E6%95%B0%E6%8D%AE%E5%8C%85%E8%BF%87%E6%BB%A4%E3%80%82%E6%95%B4%E4%B8%AA%E6%B5%8B%E8%AF%95%E6%A1%86%E6%9E%B6%E7%A4%BA%E6%84%8F%E5%9B%BE%E5%A6%82%E4%B8%8B%E6%89%80%E7%A4%BA%EF%BC%8C%E5%85%B6%E4%B8%ADclient%E5%92%8Csecure_client%E4%BD%BF%E7%94%A8%E5%90%8C%E4%B8%80%E4%BB%BD%E6%BA%90%E7%A0%81%E7%BC%96%E8%AF%91%EF%BC%8C%E5%8F%AA%E6%98%AFfile%20context%E6%9C%89%E6%89%80%E4%B8%8D%E5%90%8C%EF%BC%8Cserver%E5%92%8Csecure_server%E5%90%8C%E7%90%86%E3%80%82%0A!%5Bafd271fe524baadc38c595d0b74f9fae.png%5D(evernotecid%3A%2F%2FACEAA21A-C764-4256-94C6-40CA536E96D7%2Fappyinxiangcom%2F161681%2FENResource%2Fp6313)%0A%0A%E7%A4%BA%E4%BE%8B%E4%BB%A3%E7%A0%81%E9%80%9A%E8%BF%87%E5%AE%9A%E4%B9%89%E5%8F%AF%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6%E7%9A%84%E5%AE%89%E5%85%A8%E4%B8%8A%E4%B8%8B%E6%96%87%EF%BC%88%E5%A6%82%E4%B8%8B%E6%89%80%E7%A4%BA%EF%BC%89%EF%BC%8C%E5%92%8Ctype_transition%E8%A7%84%E5%88%99%EF%BC%8C%E4%BD%BF%E5%BE%97secure_%5C*%E8%BF%9B%E7%A8%8B%E5%B7%A5%E4%BD%9C%E5%9C%A8ext_gateway_t%20domain%EF%BC%8C%E8%80%8C%E9%9D%9Esecure%E8%BF%9B%E7%A8%8B%E5%B7%A5%E4%BD%9C%E5%9C%A8unconfined_t%20domain%E3%80%82%E5%90%84%E5%8F%AF%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6%E7%9A%84%E5%AE%89%E5%85%A8%E4%B8%8A%E4%B8%8B%E6%96%87%E5%A6%82%E4%B8%8B%E6%89%80%E7%A4%BA%EF%BC%9A%0A%60%60%60%0A%2Fusr%2Flocal%2Fbin%2Fsecure_client%20system_u%3Aobject_r%3Asecure_services_exec_t%3As0%0A%2Fusr%2Flocal%2Fbin%2Fsecure_server%20system_u%3Aobject_r%3Asecure_services_exec_t%3As0%0A%2Fusr%2Flocal%2Fbin%2Fclient%20system_u%3Aobject_r%3Aunconfined_t%3As0%0A%2Fusr%2Flocal%2Fbin%2Fserver%20system_u%3Aobject_r%3Aunconfined_t%3As0%0A%60%60%60%0A%E7%A4%BA%E4%BE%8B%E4%BB%A3%E7%A0%81%E4%B8%AD%E7%9A%84%E7%AD%96%E7%95%A5%E9%9B%86%EF%BC%88.conf)%E6%96%87%E4%BB%B6%E5%AE%9A%E4%B9%89%E4%BA%86%E7%A4%BA%E6%84%8F%E5%9B%BE%E4%B8%AD4%E4%B8%AA%E6%96%B9%E5%90%91%E6%95%B0%E6%8D%AE%E6%B5%81%E7%9A%84%E6%9D%83%E9%99%90%EF%BC%8C%E5%8C%85%E6%8B%AC%EF%BC%9A%0A-%20%E5%85%81%E8%AE%B8%E8%AE%BF%E9%97%AE%E6%9C%AA%E6%A0%87%E8%AE%B0%E7%AB%AF%E5%8F%A3%E7%9A%84%E6%95%B0%E6%8D%AE%E6%B5%81(default_secmark_packet_t)%EF%BC%9A%60auditallow%20unconfined_t%20default_secmark_packet_t%20%3A%20packet%20%7B%20send%20recv%20%7D%3B%60%0A-%20%E5%85%81%E8%AE%B8secure_%5C*%E8%BF%9B%E7%A8%8B%E8%AE%BF%E9%97%AE%E6%A0%87%E8%AE%B0%E4%BA%86%E7%AB%AF%E5%8F%A3%E7%9A%84%E6%95%B0%E6%8D%AE%E6%B5%81%EF%BC%88ext_gateway_packet_t%EF%BC%89%EF%BC%9A%60allow%20ext_gateway_t%20ext_gateway_packet_t%20%3A%20packet%20%7B%20send%20recv%20%7D%3B%60%0A-%20%E5%85%81%E8%AE%B8secure_%5C*%E8%BF%9B%E7%A8%8B%E8%AE%BF%E9%97%AE%E6%97%A0SECMARK%E6%A0%87%E8%AE%B0%E7%9A%84%E6%95%B0%E6%8D%AE%E6%B5%81%EF%BC%88unconfined_t%EF%BC%89%EF%BC%9A%60allow%20ext_gateway_t%20unconfined_t%20%3A%20packet%20%7B%20recv%20send%20%7D%3B%60%0Aiptables_secmark%E4%BD%BF%E7%94%A8%E8%8B%A5%E5%B9%B2iptables%E5%91%BD%E4%BB%A4%EF%BC%8C%E5%AE%9A%E4%B9%89%E6%95%B0%E6%8D%AE%E5%8C%85%E7%9A%84%E6%A0%87%E7%AD%BE%E8%A7%84%E5%88%99%EF%BC%8C%E4%BE%8B%E5%A6%82%EF%BC%9A%0A-%20%E6%9D%A5%E8%87%AA%E4%BA%8Elo%E7%BD%91%E5%8D%A1%E7%9A%84%EF%BC%8C%E5%8D%8F%E8%AE%AE%E4%B8%BAtcp%EF%BC%8C%E7%9B%AE%E6%A0%87IP%E4%B8%BA127.0.0.0%EF%BC%8C%E6%8E%A9%E7%A0%81%E4%B8%BA255.0.0.0%E8%BE%93%E5%85%A5%E6%95%B0%E6%8D%AE%E5%8C%85%E8%A2%AB%E8%AE%BE%E7%BD%AE%E6%88%90default_secmark_packet_t%0A%60%60%60shell%0A%23%20This%20OUTPUT%20rule%20sets%20all%20packets%20to%20default_secmark_packet_t%3A%20as%20it%20is%0Aiptables%20-t%20security%20-A%20INPUT%20-i%20lo%20-p%20tcp%20-d%20127.0.0.0%2F8%20-j%20SECMARK%20--selctx%20system_u%3Aobject_r%3Adefault_secmark_packet_t%3As0%0A%60%60%60%0A-%20%E6%9D%A5%E8%87%AA%E4%BA%8Elo%E7%BD%91%E5%8D%A1%E7%9A%84%EF%BC%8C%E5%8D%8F%E8%AE%AE%E4%B8%BAtcp%EF%BC%8C%E7%9B%AE%E6%A0%87%2F%E6%BA%90%E7%AB%AF%E5%8F%A3%E4%B8%BA9999%E7%9A%84%E8%BE%93%E5%85%A5%2F%E8%BE%93%E5%87%BA%E6%95%B0%E6%8D%AE%E5%8C%85%E8%A2%AB%E8%AE%BE%E7%BD%AE%E6%88%90ext_gateway_packet_t%EF%BC%88%E8%8A%82%E9%80%89%EF%BC%89%0A%60%60%60shell%0A%23%20These%20rules%20will%20replace%20the%20above%20context%20with%20the%20internal%20or%0Aiptables%20-t%20security%20-A%20INPUT%20-i%20lo%20-p%20tcp%20--dport%209999%20-j%20SECMARK%20--selctx%20system_u%3Aobject_r%3Aext_gateway_packet_t%3As0%0Aiptables%20-t%20security%20-A%20OUTPUT%20-o%20lo%20-p%20tcp%20--sport%209999%20-j%20SECMARK%20--selctx%20system_u%3Aobject_r%3Aext_gateway_packet_t%3As0%0A%60%60%60%0A%E4%B8%A4%E7%B1%BB%E8%A7%84%E5%88%99%E5%AE%9A%E4%B9%89%E7%9A%84%E6%95%B0%E6%8D%AE%E5%8C%85%E8%8C%83%E5%9B%B4%E5%AE%9E%E9%99%85%E6%98%AF%E6%9C%89%E9%87%8D%E5%8F%A0%E7%9A%84%EF%BC%8C%E6%A0%B9%E6%8D%AE%E6%B3%A8%E9%87%8A%E5%8F%AF%E7%9F%A5%EF%BC%8C%E5%AE%9E%E9%99%85%E4%B8%A4%E8%80%85%E7%9A%84%E5%85%B3%E7%B3%BB%E6%98%AF%EF%BC%8Cgeneral%E5%92%8C%E7%89%B9%E4%BE%8B%E7%9A%84%E5%85%B3%E7%B3%BB%E3%80%82%E5%8D%B3%E5%89%8D%E8%80%85%E5%B0%86%E6%89%80%E6%9C%89%E7%89%B9%E5%AE%9A%E7%9B%AE%E6%A0%87%E7%9A%84%E6%95%B0%E6%8D%AE%E5%8C%85%E8%AE%BE%E7%BD%AE%E4%B8%BAdefault_secmark_packet_t%EF%BC%8C%E8%80%8C%E5%90%8E%E8%80%85%E5%B0%86%E6%9D%A5%E8%87%AA%E7%89%B9%E5%AE%9A%E7%AB%AF%E5%8F%A3%E7%9A%84%E6%95%B0%E6%8D%AE%E5%8C%85%E6%8C%87%E5%AE%9A%E4%B8%BAext_gateway_packet_t%E3%80%82%0A%E7%BB%8F%E8%BF%87%E6%AD%A4%E7%B1%BB%E7%AD%96%E7%95%A5%E8%AE%BE%E7%BD%AE%EF%BC%8Cclient%E5%9C%A8%E8%AE%BF%E9%97%AEsecure_server%E6%97%B6%EF%BC%8C%E6%95%B0%E6%8D%AE%E5%8C%85%E5%B0%B1%E4%BC%9A%E8%A2%AB%E6%8B%A6%E6%88%AA%E3%80%82%E6%9F%A5%E7%9C%8B%2Fvar%2Flog%2Faudit%2Faudit.log%3A%0A%60%60%60%0Atype%3DAVC%20msg%3Daudit(1602641071.967%3A3475)%3A%20avc%3A%20%20granted%20%20%7B%20send%20%7D%20for%20%20pid%3D0%20comm%3D%22swapper%2F0%22%20saddr%3D127.0.0.1%20src%3D9999%20daddr%3D127.0.0.1%20dest%3D47076%20netif%3Dlo%20scontext%3Dunconfined_u%3Amessage_filter_r%3Aext_gateway_t%3As0-s0%3Ac0.c1023%20tcontext%3Dsystem_u%3Aobject_r%3Aext_gateway_packet_t%3As0%20tclass%3Dpacket%0A%0Atype%3DAVC%20msg%3Daudit(1602641071.967%3A3476)%3A%20avc%3A%20%20denied%20%20%7B%20recv%20%7D%20for%20%20pid%3D10%20comm%3D%22ksoftirqd%2F0%22%20saddr%3D127.0.0.1%20src%3D9999%20daddr%3D127.0.0.1%20dest%3D47076%20netif%3Dlo%20scontext%3Dunconfined_u%3A%0Aunconfined_r%3Aunconfined_t%3As0-s0%3Ac0.c1023%20tcontext%3Dsystem_u%3Aobject_r%3Aext_gateway_packet_t%3As0%20tclass%3Dpacket%20permissive%3D0%0A%60%60%60%0Aclient%E8%BF%9E%E6%8E%A5secure_server%E7%9B%91%E5%90%AC%E7%9A%849999%E7%AB%AF%E5%8F%A3%EF%BC%8C%E6%95%B0%E6%8D%AE%E6%B5%81%E4%B8%BA%EF%BC%9Atcp%EF%BC%8C127.0.0.1%3A9999%20%3D%3E%20127.0.0.1%3A47076%E3%80%82secure_server%E5%90%91client%E5%8F%91%E9%80%81%E6%88%90%E5%8A%9F%EF%BC%8C%E4%BD%86client%E6%8E%A5%E6%94%B6%E5%A4%B1%E8%B4%A5%E3%80%82%E5%9B%A0%E4%B8%BAclient%E8%BF%90%E8%A1%8C%E4%BA%8Eunconfined_t%EF%BC%8C%E6%B2%A1%E6%9C%89%E5%AF%B9%E5%BA%94ext_gateway_packet_t%E7%9A%84recv%E6%9D%83%E9%99%90%E3%80%82%0A%0A%23%23%20%E5%8B%98%E8%AF%AF%0A%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE%5B2%5D%E5%9B%A0%E4%B8%BA%E6%88%90%E4%B9%A6%E8%BF%87%E4%B9%85%EF%BC%88%E5%86%99%E4%BA%8E2014%E5%B9%B4%EF%BC%8C%E7%8E%B0%E5%9C%A82020%E5%B9%B4%EF%BC%89%EF%BC%8C%E4%B8%94%E7%BB%83%E4%B9%A0%E5%9F%BA%E4%BA%8E%E4%B9%A6%E4%B8%AD%E5%89%8D%E5%AF%BC%E7%AB%A0%E8%8A%82%E4%B8%AD%E7%9A%84modular-test%E7%AB%A0%E8%8A%82%EF%BC%8C%E6%89%80%E4%BB%A5%E7%9B%B4%E6%8E%A5%E8%BF%90%E8%A1%8C%E4%BC%9A%E4%BA%A7%E7%94%9F%E9%94%99%E8%AF%AF%E3%80%82%E9%94%99%E8%AF%AF%E4%B8%BB%E8%A6%81%E5%8C%85%E5%90%AB%EF%BC%9A%0A-%20%E5%9F%BA%E4%BA%8Emodular-test%E6%9E%84%E5%BB%BAext_gateway%E7%AD%96%E7%95%A5%E3%80%82%E5%9B%A0%E4%B8%BA%E5%8F%AF%E8%83%BD%E6%98%AF%E5%8F%91%E8%A1%8C%E7%89%88%E5%8F%98%E5%8C%96%EF%BC%88%E7%AC%94%E8%80%85%E7%94%A8%E7%9A%84CentOS8%EF%BC%89%E6%88%96%E8%80%85%E6%97%B6%E9%97%B4%E8%BF%87%E4%B9%85%E7%9A%84%E5%8E%9F%E5%9B%A0%EF%BC%8C%E7%9B%B4%E6%8E%A5%E7%94%A8%E4%B9%A6%E4%B8%AD%E7%9A%84%E5%9F%BA%E7%A1%80%E7%AD%96%E7%95%A5%E4%BC%9A%E9%80%A0%E6%88%90%E6%97%A0%E6%B3%95%E5%BC%80%E6%9C%BA%EF%BC%8C%E6%89%80%E4%BB%A5modular-test%E7%BB%83%E4%B9%A0%E4%B8%AD%E7%9A%84%E7%AD%96%E7%95%A5%E4%B8%8D%E5%8F%AF%E7%94%A8%E3%80%82%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95%E6%98%AF%EF%BC%8C%E7%BC%96%E8%AF%91ext_gateway%20module%EF%BC%8C%E5%B9%B6%E7%94%A8semodule%E6%8F%92%E5%85%A5%E5%8F%91%E8%A1%8C%E7%89%88%E8%87%AA%E5%B8%A6%E7%9A%84%E7%AD%96%E7%95%A5%E4%B8%AD%E3%80%82%E6%AD%A4%E6%97%B6%E9%9C%80%E8%A6%81%E9%92%88%E5%AF%B9%E5%8E%9F%E7%94%9F%E7%AD%96%E7%95%A5%E8%BF%9B%E8%A1%8C%E9%80%82%E9%85%8D%E3%80%82%E4%BE%8B%E5%A6%82%EF%BC%9A%E8%BF%9B%E7%A8%8B%E6%8B%89%E8%B5%B7%E6%97%B6%E6%8A%A5%E9%94%99%EF%BC%8C%E9%9C%80%E8%A6%81%E5%A2%9E%E5%8A%A0%E7%9B%B8%E5%BA%94allow%E8%A7%84%E5%88%99%EF%BC%8C%E8%8A%82%E9%80%89%E5%A6%82%E4%B8%8B%EF%BC%9A%0A%60%60%60%0Aallow%20ext_gateway_t%20null_device_t%20%3A%20chr_file%20%7B%20read%20write%20open%20%7D%3B%0Aallow%20ext_gateway_t%20ld_so_t%20%3A%20file%20%7B%20map%20read%20execute%20%7D%3B%0Aallow%20ext_gateway_t%20ld_so_cache_t%20%3A%20file%20%7B%20open%20map%20read%20execute%20getattr%20%7D%3B%0Aallow%20ext_gateway_t%20lib_t%20%3A%20file%20%7B%20open%20map%20read%20execute%20getattr%20%7D%3B%0A...%0A%60%60%60%0A-%20%E6%9C%AC%E4%B9%A6%E7%BB%99%E5%87%BA%E7%9A%84%E7%A4%BA%E4%BE%8B%E4%BB%A3%E7%A0%81%E7%9A%84%E5%AE%89%E5%85%A8%E4%B8%8A%E4%B8%8B%E6%96%87%E6%9C%AA%E7%BB%99%E5%87%BAmls%E6%8F%8F%E8%BF%B0%EF%BC%8C%E5%9C%A8%E7%BC%96%E8%AF%91%E6%97%B6%E4%BC%9A%E6%8A%A5%E9%94%99%E3%80%82%E4%BE%8B%E5%A6%82%EF%BC%9A%0A%60%60%60%0Aiptables%20-t%20security%20-A%20INPUT%20-i%20lo%20-p%20tcp%20--dport%209999%20-j%20SECMARK%20--selctx%20system_u%3Aobject_r%3Aext_gateway_packet_t%3As0%0Aiptables%20-t%20security%20-A%20INPUT%20-i%20lo%20-p%20tcp%20--sport%209999%20-j%20SECMARK%20--selctx%20system_u%3Aobject_r%3Aext_gateway_packet_t%3As0%0A%2Fusr%2Flocal%2Fbin%2Fsecure_client%20system_u%3Aobject_r%3Asecure_services_exec_t%3As0%0A%60%60%60%0A%E6%89%80%E6%9C%89%E7%9A%84context%E9%83%BD%E5%8A%A0%E4%B8%8A%E4%BA%86%60%3As0%60%E3%80%82%0A%E7%BB%8F%E8%BF%87%E9%80%82%E9%85%8D%E5%90%8E%EF%BC%8C%E4%B9%A6%E4%B8%AD%E6%8F%90%E4%BE%9B%E7%9A%84%E7%A4%BA%E4%BE%8B%E5%8F%AF%E4%BB%A5%E9%A1%BA%E5%88%A9%E8%B7%91%E9%80%9A%EF%BC%8C%E5%A6%82%E4%B8%8B%EF%BC%9A%0Aserver%0A!%5Be19e063bd6c8c6ea612eab6441924451.png%5D(evernotecid%3A%2F%2FACEAA21A-C764-4256-94C6-40CA536E96D7%2Fappyinxiangcom%2F161681%2FENResource%2Fp6311)%0Aclient%E7%AB%AF%0A!%5B2cf32398daa366c050fa0a9cbebd4dae.png%5D(evernotecid%3A%2F%2FACEAA21A-C764-4256-94C6-40CA536E96D7%2Fappyinxiangcom%2F161681%2FENResource%2Fp6312)%0A%0A%23%20%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE%0A%5B1%5D%20%5BSELinux%20Networking%20Support%5D(https%3A%2F%2Fselinuxproject.org%2Fpage%2FNB_Networking)%0A%5B2%5D%20%5BThe%20SELinux%20Notebook%20-%20Building%20The%20Sample%20Policy%5D(https%3A%2F%2Fapp.yinxiang.com%2Fshard%2Fs10%2Fnl%2F161681%2Fb51d0a9e-c5fc-48aa-8eb9-0b9bee14f832%2F)%0A%5B3%5D%20%5Biptables%20wiki%20page%5D(https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FIptables)%0A%5B4%5D%20%5BA%20Deep%20Dive%20into%20Iptables%20and%20Netfilter%20Architecture%5D(https%3A%2F%2Fwww.digitalocean.com%2Fcommunity%2Ftutorials%2Fa-deep-dive-into-iptables-and-netfilter-architecture)%0A%5B5%5D%20Oskar%20Andreasson%2C%202001-2006%2C%20Iptables%20Tutorial%201.2.2

SELinux启动流程包含了几个阶段:

  • init进程
  • libselinux
  • 内核部分

1号进程

SELinux的启动由用户态init程序发起,例如CentOS上的systemd,再例如busybox的init进程。用户态初始化方法大同小异,都是利用SELinux提供的用户态接口,包括libselinux,selinuxfs调用SELinux内核接口。本文以busybox init为例介绍。
其实用户态进程部分代码非常少:

Read more »

Intro

SID = Security Identifier (即Security ID)。其作用就是取代安全上下文,在权限匹配时,提升规则搜索速度,以及降低整个策略数据的空间复杂度,提升了整个SELinux特性的性能损耗。
例如一次权限匹配的函数调用原型如下:

int avc_has_perm(struct selinux_state *state, u32 ssid, u32 tsid, u16 tclass,
		 u32 requested, struct common_audit_data *auditdata)

其中ssid, tsid就代表了源(source)SID和目的(target)SID。在最终的av(access vector)计算中,SID被转化为context。

Read more »

如果想修改POSIX API的行为,通常我们的第一想法是修改libc库函数,并维护一份自定义的libc。这样做的代价非常大,因为libc是基础库,接口非常多,涉及的面也很广。修改可能不难,但后期维护,merge主干的工作比较麻烦,也没有价值。修改libc函数实现,还有一个缺点是,编译时修改,而非运行时。这会给一些无法下线并重新打包的程序带来困扰,例如程序已经分发,重新打包再分发耗时耗力。如果能找到运行时修改的方法,例如,暂停服务,替换一个库文件就可以修改某些行为。如果能做到运行时修改,对于调试也是非常友好的。
幸运的是,在Linux上,修改libc的方法很多:

  1. 使用LD_PRELOAD,覆盖libc中的函数
  2. 使用alias替代weak_alias,编译替换libc函数
  3. 使用GOT表覆盖libc函数实现

1和3都是动态,运行时修改。3更棒的是,可以做运行时动态获得libc的原实现函数指针,并用自定义实例去覆写。这样在内部可以保存两份实例,而无需维护开源实例。
在整个的学习和实验中查阅了不少资料,回头看来,其中比较有价值的应当是文末的参考文献中列出的一些链接。

Android so注入(inject)和Hook技术学习(二)——Got表hook之导入表hook
我的实验代码基于这个网页中的方法二实例代码,通过解析.dynamic section来获取GOT地址,并覆盖对应表项

Executable and Linkable Format
这个帖子非常棒,详细阐述了动态链接的过程,包括link editor以及runtime dynamic link流程。只是可能时间比较久,其中的一些链接都失效了

Oracle Documentation

Executable and Linking Format Specification, Version 1.2
这两个链接都给出了一些较为官方的阐述,针对各个section,以及对应的取值等等,作为手册查询很好。

ELF概述

from Wiki
Executable and Linkable Format (ELF, formerly named Extensible Linking Format), is a common standard file format for executable files, object code, shared libraries, and core dumps.

              +-----------------+
         +----| ELF File Header |----+
         |    +-----------------+    |
         v                           v
 +-----------------+      +-----------------+
 | Program Headers |      | Section Headers |
 +-----------------+      +-----------------+
      ||                               ||
      ||                               ||
      ||                               ||
      ||   +------------------------+  ||
      +--> | Contents (Byte Stream) |<--+
           +------------------------+

ELF格式通常有linking view和execution view,即编译时,和运行时的不同。

我理解之所以要这么分成不同的view的原因是,运行时,内存比较宝贵,ELF文件被加载时,相关的节(section)被合并成segment。

segment列表[2]

section列表节选[2]

动态链接

我们知道当引用第三方库的时候,通常有两种链接方式,一种是动态链接,一种是静态链接。静态链接库在Windows上是.lib结尾的,在Linux平台上是.a结尾的。静态库不是一种可执行文件,而只是一些代码和数据打包(Archive)。当发生链接时,由链接器将其中的代码和数据分别放到最终的ELF文件的对应的节(section)。
而动态库是一种完全不一样的东西,动态库的行为更趋近于可执行文件。在Windows平台上,动态库文件以.dll结尾,在Linux平台上,动态库文件以.so结尾。
在Windows下,如果要进行动态链接,必须使用LoadLibrary函数打开一个.dll库文件,再用GetProcAddress获取具体函数的地址,进行调用。dll导出函数列表可以使用命令查看:dumpbin /exports <dll文件完整路径>
Linux下也有类似的方式,就是可以用dlopen打开一个.so文件,再用dlsym找到对应的函数。但是Linux通常使用动态链接库的方式,是直接链接。例如:
gcc -L/lib -ltest main.c -o test
这就是在lib搜索路径下,找到libtest.so,并链接。注意这里默认先尝试动态链接,如果没有.so文件,会再尝试静态链接.a文件。如果都没有,就会报错。这也就是说Linux平台上,通过-l参数指定的链接参数,是默认尝试动态链接,其次才是静态链接。
如果想指定使用静态链接,可以用下面的命令:
gcc -L/lib -static -ltest main.c -o test
或者
gcc -L/lib libtest.a main.c -o test

How is an executable binary in Linux being executed ?[2]

  1. sys_execve function (in arch/x86/kernel/process.c) handles the execvc system call from user space. It calls do_execve function.

  2. do_execve function (in fs/exec.c) opens the executable binary file and does some preparation. It calls search_binary_handler function.

  3. search_binary_handler function (in fs/exec.c) finds out the type of executable binary and calls the corresponding handler, which in our case, is load_elf_binary function.

  4. load_elf_binary (in fs/binfmt_elf.c) loads the user's executable binary file into memory. It allocates memory segments and zeros out the BSS section by calling the padzero function.
    load_elf_binary also examines whether the user's executable binary contains an INTERP segment or not.

  5. If the executable binary is dynamically linked, then the compiler will usually creates an INTERP segment (which is usually the same as .interp section in ELF's "linking view"), which contains the full pathname of an "interpreter", usually is the Glibc runtime linker ld.so.
    To see this, use command readelf -p .interp a.out

  6. Thus, if the ELF executable binary file contains an INTERP segment, load_elf_binary will call load_elf_interp function to load the image of this interpreter as well.

  7. Finally, load_elf_binary calls start_thread (in arch/x86/kernel/process_64.c) and passes control to either the interpreter or the user program.

这个1-7就是ELF文件被加载的过程,之后,再只要一个跳转语句,就可以真正的执行这个程序了。这里值得关注的就是第5步。如果被加载的二进制是动态链接生成的,即要么是动态链接库,要么是可执行文件,则加载时,内核会给ELF的内存镜像(即所谓的executing view)加一个INTERP段(segment)。而这个段就是所谓的runtime linker(compile时的linker,即ld,称为link editor),也就是ld.so。

ld.so

什么是ld.so? ld.so做了些啥?文献[2]都做了很好的说明。

ld.so is the runtime linker/loader (the compile-time linker ld is formally called "link editor") for dynamic executables. It provides the following services [2]:

  • Analyzes the user's executable binary's DYNAMIC segment and determines what dependencies are required.
  • Locates and loads these dependencies, analyzes their DYNAMIC segments to determine if more dependencies are required.
  • Performs any necessary relocations to bind these objects.
  • Calls any initialization functions (see below) provided by these dependencies.
  • Passes control to user's executable binary.

How does ld.so work ?[2]

ld.so是用来加载所有的动态库的,所以ld.so本身不是动态加载的。ld.so的入口在_dl_start。可以通过gdb停在这个函数上。

(gdb) break _dl_start
Function "_dl_start" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (_dl_start) pending.
(gdb) run
Starting program: a.out

Breakpoint 1, 0x0000003433e00fa0 in _dl_start () from /lib64/ld-linux-x86-64.so.2
(gdb) bt
#0  0x0000003433e00fa0 in _dl_start () from /lib64/ld-linux-x86-64.so.2
#1  0x0000003433e00a78 in _start () from /lib64/ld-linux-x86-64.so.2
#2  0x0000000000000001 in ?? ()
#3  0x00007fffffffe4f2 in ?? ()
#4  0x0000000000000000 in ?? ()
...
(gdb) x/10i $pc
   0x3433e00a70 <_start>:       mov    %rsp,%rdi
   0x3433e00a73 <_start+3>:     callq  0x3433e00fa0 <_dl_start>
   0x3433e00a78 <_dl_start_user>:       mov    %rax,%r12
   0x3433e00a7b <_dl_start_user+3>:     mov    0x21b30b(%rip),%eax        # 0x343401bd8c <_dl_skip_args>
...

当_dl_start执行完后,ld.so就会为我们分析依赖关系,并加载起所有必需的动态库文件。

0000003434551000      4K rw---  /lib64/libc-2.5.so     <-- .got.plt .data sections

PLT & GOT

PLT = Procedure Linkage Table
GOT = Global Offsets Table
PLT表搭配GOT表就可以完成动态库函数的重定向。
当编译时,在链接阶段,编译器会查找函数定义,如果在所有的可重定向代码中,即.o、.a文件,无法找到函数定义,则会去链接指定的动态库.so文件中找。这里有两层意思:

  1. 会优先查找有函数定义的,也就是说静态库或源文件中定义的函数是可以覆盖动态库中函数的
  2. 编译器会为动态库中函数生成跳转代码。而这个跳转代码就是PLT表

可以用objdump -M intel -dj .plt a.out命令查看PLT表具体反编译代码,例如:

  • 第一条汇编语句,就是跳转到GOT对应表项,当该表项尚未被填充时(函数第一次被调用),GOT表项会重新跳回到PLT表项的下一条汇编
  • 第二条汇编语句,将函数编号push到栈上,此时是准备一次函数调用
  • 第三条汇编语句,跳转到PLT表开始的地方。PLT第一个表项指向的是_dl_runtime_resolve函数,该函数会找到之前传入的函数编号对应的函数地址,并填充对应的GOT表项。

关于函数编号,举个例子,解释一下:

#include <stdio.h>
#include <fcntl.h>
int func(void)
{
    open("foo.txt", O_CREAT);
    fopen("foo.txt", "rw");
    printf("hello, in test.so\n");
    return 0;
}

这里引用了glibc里的3个函数,用readelf -r查看,则会得到下面的结果:

重定位节 '.rela.plt' at offset 0x508 contains 3 entries:
  偏移量          信息           类型           符号值        符号名称 + 加数
000000201018  000200000007 R_X86_64_JUMP_SLO 0000000000000000 puts@GLIBC_2.2.5 + 0
000000201020  000400000007 R_X86_64_JUMP_SLO 0000000000000000 open@GLIBC_2.2.5 + 0
000000201028  000500000007 R_X86_64_JUMP_SLO 0000000000000000 fopen@GLIBC_2.2.5 + 0

则puts对应的编号就是0,open是1,fopen是2。看看PLT表:

000000000000580 <puts@plt>:
 580:	ff 25 92 0a 20 00    	jmp    QWORD PTR [rip+0x200a92]        # 201018 <puts@GLIBC_2.2.5>
 586:	68 00 00 00 00       	push   0x0
 58b:	e9 e0 ff ff ff       	jmp    570 <.plt>

0000000000000590 <open@plt>:
 590:	ff 25 8a 0a 20 00    	jmp    QWORD PTR [rip+0x200a8a]        # 201020 <open@GLIBC_2.2.5>
 596:	68 01 00 00 00       	push   0x1
 59b:	e9 d0 ff ff ff       	jmp    570 <.plt>

00000000000005a0 <fopen@plt>:
 5a0:	ff 25 82 0a 20 00    	jmp    QWORD PTR [rip+0x200a82]        # 201028 <fopen@GLIBC_2.2.5>
 5a6:	68 02 00 00 00       	push   0x2
 5ab:	e9 c0 ff ff ff       	jmp    570 <.plt>

理解了PLT和GOT表在解析函数地址中的作用,就可以着手修改GOT表,让函数跳转到我们希望的函数执行。

替换GOT表项

正如前文所说,要做这个替换的操作,就是要找到GOT表对应的表项在哪里,然后修改对应的函数地址即可。这涉及到解析内存中的程序elf格式的镜像。

dynamic section

所有和重定向有关的信息都包含在dynamic section中,在elf的execution view中,也可以称作dynamic segment。实际上,这两者是同一个东西,只是存在的方式不同。当然,因为我们要做的是动态的GOT修改,所以我们要找到dynamic segment在内存中的位置。
由前文可知,要在execution view中查找段,应该要用到Programm Header Table(PHT)。通过objdump -x命令可以查看PHT表项。其中我们关心的就是DYNAMIC段。它包含了所有dynamic section的信息。代码里面,可以如下的获得dynamic。

// 1. 通过/proc/<pid>/maps得到elf加载的地址
    snprintf(filename, sizeof(filename), "/proc/%d/maps", pid);

    // 打开文件/proc/pid/maps,获取指定pid进程加载的内存模块信息
    fp = fopen(filename, "r");
    if(fp != NULL){
        // 每次一行,读取文件 /proc/pid/maps中内容
        while(fgets(line, sizeof(line), fp)){
            // 查找指定的so模块
            if(strstr(line, module_name)){
                // 分割字符串
                pch = strtok(line, "-");
                // 字符串转长整形
                addr = strtoul(pch, NULL, 16);
                break;
            }
        }
    }
    fclose(fp);
  
// 2. 通过遍历program header table,找到dynameic段
    unsigned long long dynamicAddr = 0;
    unsigned int dynamicSize = 0;
    int j = 0;
    for (j = 0; j < phdr_count; j++)
    {
        if (phdr_table[j].p_type == PT_DYNAMIC)
        {
            dynamicAddr = phdr_table[j].p_vaddr + (uint64_t)base_addr;
            dynamicSize = phdr_table[j].p_memsz;
            break;
        }
    }

relocation tables

通过objdump -h命令可以查看文件包含的section。和relocation相关的节有:

  • .got
  • .got.plt
  • .plt
  • rel(a).dyn
  • rel(a).plt
  • 其他rel(a).xxx节
    刚开始的时候,这些类似的节名很容易让人混淆。其实和我们目标真正相关的是rel(a).plt。其他的让我依次澄清一下。不过都是我个人的理解,可能有偏颇之处。
    先用readelf -S查看一下section header table。

PROGBITS is stored in the disk image, as opposed to allocated and initialized at load.
节区类型:PROGBITS-程序定义的信息,NOBITS-不占用文件空间(bss),REL-重定位表项

对于各节区,[2]中的解释为:

  • .plt: For dynamic binaries, this Procedure Linkage Table holds the trampoline/linkage code. See paragraphs below.
  • .got: For dynamic binaries, this Global Offset Table holds the addresses of variables which are relocated upon loading.
  • .got.plt: For dynamic binaries, this Global Offset Table holds the addresses of functions in dynamic libraries. They are used by trampoline code in .plt section.

对于.plt.got区网上搜到的解释是:

  • This just seems to contain code to jump to the first entry of the .got.

这里很容易让人有很混乱的感觉,又是.got.plt的, 又是.plt.got的。网络上也很难查到两者之间的联系和区别。根据我个人的实验经验,后文尝试解释一下。先对这几个节区做一个总结。

  • 这4个都是编译时决定的,节类型都是PROGBITS。信息都是存在可执行文件里,而runtime可用的信息都是通过重定向得到的,即通过rel(a).xxx节区获得的内存地址中存储的数据
  • 所有以.plt开头的节区,都是一些跳板代码。
  • 所有以.got开头的节区,都是一些数据,存储着这些函数被resolve后最终的地址。
  • .plt开头表项的跳板代码,就是跳转到对应的.got表项中决定最终的执行地址。
# table of a dynamic library (.so)
  [10] .plt              PROGBITS         0000000000000610  00000610
  [11] .plt.got          PROGBITS         0000000000000640  00000640
  [20] .got              PROGBITS         0000000000200fc0  00000fc0
  [21] .got.plt          PROGBITS         0000000000201000  00001000

.plt vs .plt.got

先上2个例子,分别是.plt和.plt.got节的。可以看出,这2个节都是一些跳转代码。按照前文的解释,.plt节表项就是需要动态链接的一些函数的跳板代码。跳转代码的目的地是GOT表项。然后通过runtime linker(ld.so)来完成函数地址的解析。
.plt.got的内容与.plt非常类似,也是一些跳板代码。而且jmpq指令后,没有push指令和另一条jmpq指令。这个节和.plt节到底有啥区别?啥时候会用到该节的跳转指令?

# .plt节举例
00000000000008c0 <fopen@plt>:
 8c0:	ff 25 ea 16 20 00    	jmpq   *0x2016ea(%rip)        # 201fb0 <fopen@GLIBC_2.2.5>
 8c6:	68 09 00 00 00       	pushq  $0x9
 8cb:	e9 50 ff ff ff       	jmpq   820 <.plt>


# .plt.got节举例
00000000000005d0 <fopen@plt>:
 5d0:	ff 25 12 0a 20 00    	jmpq   *0x200a12(%rip)        # 200fe8 <fopen@GLIBC_2.2.5>
 5d6:	66 90                	xchg   %ax,%ax

经过我的实验发现,当发生类似这种函数指针赋值时,动态链接函数就会出现在.plt.got节,同时.plt节中就不再包含这个函数。

FuncPuts old_puts = NULL;
old_puts = puts; // puts as a function pointer, assigned to a variable

当函数不在.plt节时,函数的跳转变成静态的了。用objdump -S对照汇编和源码,可以发现,对此类函数的调用就是跳转到对应的.plt.got表项。

puts("hello");
 751:   48 8d 3d 8c 00 00 00    lea    0x8c(%rip),%rdi        # 7e4 <_fini+0x14>
 758:   e8 e3 fe ff ff          callq  640 <puts@plt>
 
 # 对应的.plt.got表项
 0000000000000640 <puts@plt>:
 640:   ff 25 82 09 20 00       jmpq   *0x200982(%rip)        # 200fc8 <puts@GLIBC_2.2.5>
 646:   66 90                   xchg   %ax,%ax 

: xchg %ax, %ax是一条NOP指令,参看Why does Visual Studio use xchg ax,ax

当只有.plt.got包含该函数表项时,我们的GOT替换魔法就失效了。所以如果想保存原函数指针,正确的做法应当是:

// Don't do like this.
// It will kick puts from .plt and put it into .plt.got.
// We might not be able to substitute its address via rel tables.
// old_puts = puts; 

// Below is RECOMMENDED!!!
if (old_puts == NULL) { // save original libc function pointer
    old_puts = (FuncPuts)*(uint64_t *)(rel_table[i].r_offset + base_addr);
}
*(uint64_t *)(rel_table[i].r_offset + base_addr) = (uint64_t)my_puts;

.got vs .got.plt

按照前文的解释,.got节存储的是需要动态resolve的变量(应当是动态库中定义的全局变量)。而.got.plt是对应.plt节的函数地址表项。
实际的实验结果是:

  • 对于可执行文件,.got.plt不存在,而.plt表项直接跳转到.got表项执行。函数的GOT表位置(GLOBAL_OFFSET_TABLE)在0x201f50
> objdump -d --section=.plt mytest 

mytest:     文件格式 elf64-x86-64

Disassembly of section .plt:

0000000000000820 <.plt>:
 820:   ff 35 32 17 20 00       pushq  0x201732(%rip)        # 201f58 <_GLOBAL_OFFSET_TABLE_+0x8>
 826:   ff 25 34 17 20 00       jmpq   *0x201734(%rip)        # 201f60 <_GLOBAL_OFFSET_TABLE_+0x10>
 82c:   0f 1f 40 00             nopl   0x0(%rax)
 
 > objdump -d --section=.got mytest    

mytest:     文件格式 elf64-x86-64

Disassembly of section .got:

0000000000201f50 <_GLOBAL_OFFSET_TABLE_>:
  201f50:       50 1d 20 00 00 00 00 00 00 00 00 00 00 00 00 00
        ...
  • 对于一个动态链接库文件,则如前文所述一致,即.got负责跳转变量,而.got.plt负责跳转函数。函数的GOT表位置(GLOBAL_OFFSET_TABLE)在0x201000
> objdump -d --section=.plt libtest.so    

libtest.so:     文件格式 elf64-x86-64

Disassembly of section .plt:

0000000000000610 <.plt>:
 610:   ff 35 f2 09 20 00       pushq  0x2009f2(%rip)        # 201008 <_GLOBAL_OFFSET_TABLE_+0x8>
 616:   ff 25 f4 09 20 00       jmpq   *0x2009f4(%rip)        # 201010 <_GLOBAL_OFFSET_TABLE_+0x10>
 61c:   0f 1f 40 00             nopl   0x0(%rax)

> objdump -d --section=.got.plt libtest.so    

libtest.so:     文件格式 elf64-x86-64

Disassembly of section .got.plt:

0000000000201000 <_GLOBAL_OFFSET_TABLE_>:
  201000:       00 0e 20 00 00 00 00 00 00 00 00 00 00 00 00 00 
        ...

但其实,我们需要关注的是重定向的表格,而不是直接查看.got和.got.plt节区。后文会进一步解释。而在真正的GOT表项替换中,可执行文件和动态链接库并没有表现出什么不同。

Rerwrite GOT

重写GOT表项的思路就是前面讲述的PLT+GOT动态解析函数地址的方法。而覆写的方法是通过重定向表格找到GOT表,并找到对应的表项索引,修改该索引处的内存。流程大致如下:

PHN2ZyBpZD0iZGFmeGI5YWFyMGEiIHdpZHRoPSIxMDAlIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHN0eWxlPSJtYXgtd2lkdGg6IDk1OS43MTg3NXB4OyIgdmlld0JveD0iMCAwIDk1OS43MTg3NSA5NTQuOTgxMjQ2OTQ4MjQyMiI+PHN0eWxlPgoKCiNkYWZ4YjlhYXIwYSAubGFiZWwgewogIGZvbnQtZmFtaWx5OiAndHJlYnVjaGV0IG1zJywgdmVyZGFuYSwgYXJpYWw7CiAgY29sb3I6ICMzMzM7IH0KCiNkYWZ4YjlhYXIwYSAubm9kZSByZWN0LAojZGFmeGI5YWFyMGEgLm5vZGUgY2lyY2xlLAojZGFmeGI5YWFyMGEgLm5vZGUgZWxsaXBzZSwKI2RhZnhiOWFhcjBhIC5ub2RlIHBvbHlnb24gewogIGZpbGw6ICNFQ0VDRkY7CiAgc3Ryb2tlOiAjOTM3MERCOwogIHN0cm9rZS13aWR0aDogMXB4OyB9CgojZGFmeGI5YWFyMGEgLm5vZGUuY2xpY2thYmxlIHsKICBjdXJzb3I6IHBvaW50ZXI7IH0KCiNkYWZ4YjlhYXIwYSAuYXJyb3doZWFkUGF0aCB7CiAgZmlsbDogIzMzMzMzMzsgfQoKI2RhZnhiOWFhcjBhIC5lZGdlUGF0aCAucGF0aCB7CiAgc3Ryb2tlOiAjMzMzMzMzOwogIHN0cm9rZS13aWR0aDogMS41cHg7IH0KCiNkYWZ4YjlhYXIwYSAuZWRnZUxhYmVsIHsKICBiYWNrZ3JvdW5kLWNvbG9yOiAjZThlOGU4OyB9CgojZGFmeGI5YWFyMGEgLmNsdXN0ZXIgcmVjdCB7CiAgZmlsbDogI2ZmZmZkZSAhaW1wb3J0YW50OwogIHN0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m09InRyYW5zbGF0ZSgwLDApIj48ZyB0cmFuc2Zvcm09InRyYW5zbGF0ZSgtMTEuMTc5Njg3NSwtOC4xNDA2MjUpIj48dGV4dD48dHNwYW4geG1sOnNwYWNlPSJwcmVzZXJ2ZSIgZHk9IjFlbSIgeD0iMSI+RW5kPC90c3Bhbj48L3RleHQ+PC9nPjwvZz48L2c+PC9nPjwvZz48L2c+PC9zdmc+

我的基础代码来自于[1],总的项目后面我会更新到zhougy0717/inject_got仓库中。

Get module base

这里要做的其实就是获取对应的image在虚拟内存中的位置。例如:
可执行文件

    // 打开文件/proc/pid/maps,获取指定pid进程加载的内存模块信息
    fp = fopen(filename, "r");
    if(fp != NULL){
        // 每次一行,读取文件 /proc/pid/maps中内容
        while(fgets(line, sizeof(line), fp)){
            // 查找指定的so模块
            if(strstr(line, module_name)){
                // 分割字符串
                pch = strtok(line, "-");
                // 字符串转长整形
                addr = strtoul(pch, NULL, 16);
                break;
            }
        }
    }
    fclose(fp);
    return (void*)addr;

.rel.plt还是.rela.plt

rel和rela是两种relocation type。是rel还是rela会影响到后续选择的数据结构类型。到底该用rel还是rela,是取决于processor type的。而x86_64都是rela类型的,i386和arm32都是rel类型的。除了通过Google来得到rel type,还有更靠谱的方法是,检查.dynamic section的DT_PLTREL字段。

    for(i=0;i < dynamicSize / sizeof(Elf64_Dyn);i ++)
    {
        uint64_t val = dynamic_table[i].d_un.d_val;
        if (dynamic_table[i].d_tag == DT_PLTREL)
        {
            // DT_RELA = 7
            // DT_REL = 17
            relType = dynamic_table[i].d_un.d_val;
        }
    }

从.rel(a).plt index到.strtab index

这一段代码要做的就是找到.rel(a).plt表项所代表的函数的名字。这个函数的名字是存储在.strtab节的。代码大致如下:

    // 获取.rel(a).plt, .symtab, .strtab地址
    for(i=0;i < dynamicSize / sizeof(Elf64_Dyn);i ++)
    {
        uint64_t val = dynamic_table[i].d_un.d_val;
        if (dynamic_table[i].d_tag == DT_JMPREL)
        {
            jmpRelOff = dynamic_table[i].d_un.d_ptr;
        }
        if (dynamic_table[i].d_tag == DT_STRTAB)
        {
            strTabOff = dynamic_table[i].d_un.d_ptr;
        }
        if (dynamic_table[i].d_tag == DT_PLTRELSZ)
        {
            pltRelSz = dynamic_table[i].d_un.d_val;
        }
        if (dynamic_table[i].d_tag == DT_SYMTAB)
        {
            symTabOff = dynamic_table[i].d_un.d_ptr;
        }
    }
    
    Elf64_Rela* rel_table = (Elf64_Rela*)jmpRelOff;
    // 遍历查找要hook的导入函数
    // i ==> .rela.plt item index
    for(i = 0;i < pltRelSz / sizeof(Elf64_Rela);i++)
    {
        int number = ELF64_R_SYM(rel_table[i].r_info); // .symtab index
        Elf64_Sym* symEnt = (Elf64_Sym*)(number*sizeof(Elf64_Sym) + symTabOff);
        char* funcName = (char*)(symEnt->st_name + strTabOff);
        if(strcmp(funcName, "puts") == 0)
        {
            // 获取当前内存分页的大小
            uint64_t page_size = getpagesize();
            // 获取内存分页的起始地址(需要内存对齐)
            uint64_t mem_page_start = (uint64_t)(((Elf64_Addr)rel_table[i].r_offset + (uint64_t)base_addr)) & (~(page_size - 1));
            mprotect((void *)mem_page_start, page_size, PROT_READ | PROT_WRITE | PROT_EXEC);
            *(uint64_t *)(rel_table[i].r_offset + base_addr) = (uint64_t)my_puts; // overwrite GOT item
            break;
        }
    }

下图就是上面这段代码的示意图。

  • 在解析.dynamic节,获取.rel(a).plt, .symtab, .strtab信息时,要注意的是Elf64_Dyn的定义,它是一个union结构,是区分值类型和指针类型的,其定义如下:
typedef struct {
        Elf64_Xword d_tag;
        union {
                Elf64_Xword     d_val;
                Elf64_Addr      d_ptr;
        } d_un;
} Elf64_Dyn;

在获取内存地址的时候要用d_ptr,而在获取例如DT_PLTRELSZ时,就显然是一个值类型。

  • 前面说的relocation type在这里就会发挥作用。.rel(a).plt表项在不同的relocation type的情况下,其数据结构是不同的。他们的结构和尺寸都是不同的。
    • rel是Elf64_Rel
    • rela是Elf64_Rela
  • DT_SYMTAB是.symtab节,每一个symbol是一个Elf64_Sym数据结构
  • .strtab是所有符号的名字字符串表格。而Elf64_Sym.st_name是表格的偏移地址。注意,不是表格索引。所以获取名字的方法是symEnt->st_name + strTabOff
  • 最后,修改对应的页表属性,然后修改对应的内存地址就可以水到渠成了

参考文献

[1] Android so注入(inject)和Hook技术学习(二)——Got表hook之导入表hook

[2] Executable and Linkable Format

[3] Oracle Documentation

[4] Executable and Linking Format Specification, Version 1.2

%E5%A6%82%E6%9E%9C%E6%83%B3%E4%BF%AE%E6%94%B9POSIX%20API%E7%9A%84%E8%A1%8C%E4%B8%BA%EF%BC%8C%E9%80%9A%E5%B8%B8%E6%88%91%E4%BB%AC%E7%9A%84%E7%AC%AC%E4%B8%80%E6%83%B3%E6%B3%95%E6%98%AF%E4%BF%AE%E6%94%B9libc%E5%BA%93%E5%87%BD%E6%95%B0%EF%BC%8C%E5%B9%B6%E7%BB%B4%E6%8A%A4%E4%B8%80%E4%BB%BD%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9A%84libc%E3%80%82%E8%BF%99%E6%A0%B7%E5%81%9A%E7%9A%84%E4%BB%A3%E4%BB%B7%E9%9D%9E%E5%B8%B8%E5%A4%A7%EF%BC%8C%E5%9B%A0%E4%B8%BAlibc%E6%98%AF%E5%9F%BA%E7%A1%80%E5%BA%93%EF%BC%8C%E6%8E%A5%E5%8F%A3%E9%9D%9E%E5%B8%B8%E5%A4%9A%EF%BC%8C%E6%B6%89%E5%8F%8A%E7%9A%84%E9%9D%A2%E4%B9%9F%E5%BE%88%E5%B9%BF%E3%80%82%E4%BF%AE%E6%94%B9%E5%8F%AF%E8%83%BD%E4%B8%8D%E9%9A%BE%EF%BC%8C%E4%BD%86%E5%90%8E%E6%9C%9F%E7%BB%B4%E6%8A%A4%EF%BC%8Cmerge%E4%B8%BB%E5%B9%B2%E7%9A%84%E5%B7%A5%E4%BD%9C%E6%AF%94%E8%BE%83%E9%BA%BB%E7%83%A6%EF%BC%8C%E4%B9%9F%E6%B2%A1%E6%9C%89%E4%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E4%BB%BD%E5%AE%9E%E4%BE%8B%EF%BC%8C%E8%80%8C%E6%97%A0%E9%9C%80%E7%BB%B4%E6%8A%A4%E5%BC%80%E6%BA%90%E5%AE%9E%E4%BE%8B%E3%80%82%0A%E5%9C%A8%E6%95%B4%E4%B8%AA%E7%9A%84%E5%AD%A6%E4%B9%A0%E5%92%8C%E5%AE%9E%E9%AA%8C%E4%B8%AD%E6%9F%A5%E9%98%85%E4%BA%86%E4%B8%8D%E5%B0%91%E8%B5%84%E6%96%99%EF%BC%8C%E5%9B%9E%E5%A4%B4%E7%9C%8B%E6%9D%A5%EF%BC%8C%E5%85%B6%E4%B8%AD%E6%AF%94%E8%BE%83%E6%9C%89%E4%BB%B7%E5%80%BC%E7%9A%84%E5%BA%94%E5%BD%93%E6%98%AF%E6%96%87%E6%9C%AB%E7%9A%84%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE%E4%B8%AD%E5%88%97%E5%87%BA%E7%9A%84%E4%B8%80%E4%BA%9B%E9%93%BE%E6%8E%A5%E3%80%82%0A%5BAndroid%20so%E6%B3%A8%E5%85%A5(inject)%E5%92%8CHook%E6%8A%80%E6%9C%AF%E5%AD%A6%E4%B9%A0%EF%BC%88%E4%BA%8C%EF%BC%89%E2%80%94%E2%80%94Got%E8%A1%A8hook%E4%B9%8B%E5%AF%BC%E5%85%A5%E8%A1%A8hook%5D(https%3A%2F%2Fwww.cnblogs.com%2Fgoodhacker%2Fp%2F9306997.html)%0A%E6%88%91%E7%9A%84%E5%AE%9E%E9%AA%8C%E4%BB%A3%E7%A0%81%E5%9F%BA%E4%BA%8E%E8%BF%99%E4%B8%AA%E7%BD%91%E9%A1%B5%E4%B8%AD%E7%9A%84%E6%96%B9%E6%B3%95%E4%BA%8C%E5%AE%9E%E4%BE%8B%E4%BB%A3%E7%A0%81%EF%BC%8C%E9%80%9A%E8%BF%87%E8%A7%A3%E6%9E%90.dynamic%20section%E6%9D%A5%E8%8E%B7%E5%8F%96GOT%E5%9C%B0%E5%9D%80%EF%BC%8C%E5%B9%B6%E8%A6%86%E7%9B%96%E5%AF%B9%E5%BA%94%E8%A1%A8%E9%A1%B9%0A%5BExecutable%20and%20Linkable%20Format%5D(https%3A%2F%2Fstevens.netmeister.org%2F631%2Felf.html)%0A%E8%BF%99%E4%B8%AA%E5%B8%96%E5%AD%90%E9%9D%9E%E5%B8%B8%E6%A3%92%EF%BC%8C%E8%AF%A6%E7%BB%86%E9%98%90%E8%BF%B0%E4%BA%86%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%E7%9A%84%E8%BF%87%E7%A8%8B%EF%BC%8C%E5%8C%85%E6%8B%AClink%20editor%E4%BB%A5%E5%8F%8Aruntime%20dynamic%20link%E6%B5%81%E7%A8%8B%E3%80%82%E5%8F%AA%E6%98%AF%E5%8F%AF%E8%83%BD%E6%97%B6%E9%97%B4%E6%AF%94%E8%BE%83%E4%B9%85%EF%BC%8C%E5%85%B6%E4%B8%AD%E7%9A%84%E4%B8%80%E4%BA%9B%E9%93%BE%E6%8E%A5%E9%83%BD%E5%A4%B1%E6%95%88%E4%BA%86%0A%5BOracle%20Documentation%5D(https%3A%2F%2Fdocs.oracle.com%2Fcd%2FE19683-01%2F817-3677%2F6mj8mbtc9%2Findex.html%23chapter6-79797)%0A%5BExecutable%20and%20Linking%20Format%20Specification%2C%20Version%201.2%5D(https%3A%2F%2Frefspecs.linuxbase.org%2Felf%2Felf.pdf)%0A%E8%BF%99%E4%B8%A4%E4%B8%AA%E9%93%BE%E6%8E%A5%E9%83%BD%E7%BB%99%E5%87%BA%E4%BA%86%E4%B8%80%E4%BA%9B%E8%BE%83%E4%B8%BA%E5%AE%98%E6%96%B9%E7%9A%84%E9%98%90%E8%BF%B0%EF%BC%8C%E9%92%88%E5%AF%B9%E5%90%84%E4%B8%AAsection%EF%BC%8C%E4%BB%A5%E5%8F%8A%E5%AF%B9%E5%BA%94%E7%9A%84%E5%8F%96%E5%80%BC%E7%AD%89%E7%AD%89%EF%BC%8C%E4%BD%9C%E4%B8%BA%E6%89%8B%E5%86%8C%E6%9F%A5%E8%AF%A2%E5%BE%88%E5%A5%BD%E3%80%82%0A%0A%23%23%20ELF%E6%A6%82%E8%BF%B0%0A%3E**from%20Wiki**%0A%3EExecutable%20and%20Linkable%20Format%20(ELF%2C%20formerly%20named%20Extensible%20Linking%20Format)%2C%20is%20a%20common%20standard%20file%20format%20for%20executable%20files%2C%20object%20code%2C%20shared%20libraries%2C%20and%20core%20dumps.%20%0A%0A%60%60%60%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2B-----------------%2B%0A%20%20%20%20%20%20%20%20%20%2B----%7C%20ELF%20File%20Header%20%7C----%2B%0A%20%20%20%20%20%20%20%20%20%7C%20%20%20%20%2B-----------------%2B%20%20%20%20%7C%0A%20%20%20%20%20%20%20%20%20v%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20v%0A%20%2B-----------------%2B%20%20%20%20%20%20%2B-----------------%2B%0A%20%7C%20Program%20Headers%20%7C%20%20%20%20%20%20%7C%20Section%20Headers%20%7C%0A%20%2B-----------------%2B%20%20%20%20%20%20%2B-----------------%2B%0A%20%20%20%20%20%20%7C%7C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%7C%0A%20%20%20%20%20%20%7C%7C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%7C%0A%20%20%20%20%20%20%7C%7C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%7C%0A%20%20%20%20%20%20%7C%7C%20%20%20%2B------------------------%2B%20%20%7C%7C%0A%20%20%20%20%20%20%2B--%3E%20%7C%20Contents%20(Byte%20Stream)%20%7C%3C--%2B%0A%20%20%20%20%20%20%20%20%20%20%20%2B------------------------%2B%0A%60%60%60%0AELF%E6%A0%BC%E5%BC%8F%E9%80%9A%E5%B8%B8%E6%9C%89linking%20view%E5%92%8Cexecution%20view%EF%BC%8C%E5%8D%B3%E7%BC%96%E8%AF%91%E6%97%B6%EF%BC%8C%E5%92%8C%E8%BF%90%E8%A1%8C%E6%97%B6%E7%9A%84%E4%B8%8D%E5%90%8C%E3%80%82%0A!%5Bc6e4a6b28cbbfe15ec89929d8885ef51.png%5D(evernotecid%3A%2F%2F22617523-9521-4D00-B771-5F27B85F00EB%2Fappyinxiangcom%2F161681%2FENResource%2Fp6377)%0Alinking%20view%E6%97%B6%EF%BC%8C%E5%8F%AF%E4%BB%A5%E6%B2%A1%E6%9C%89Program%20Header%20Table%EF%BC%8C%E4%BD%86%E5%BF%85%E9%A1%BB%E8%A6%81%E6%9C%89Section%20Header%20Table%0A%E5%8F%8D%E4%B9%8B%EF%BC%8Cexecution%20view%E6%97%B6%EF%BC%8C%E5%BF%85%E9%A1%BB%E6%9C%89Program%20Header%20Table%2C%20%E4%BD%86%E5%8F%AF%E4%BB%A5%E6%B2%A1%E6%9C%89Section%20Header%20Table%0A%3E%E6%88%91%E7%90%86%E8%A7%A3%E4%B9%8B%E6%89%80%E4%BB%A5%E8%A6%81%E8%BF%99%E4%B9%88%E5%88%86%E6%88%90%E4%B8%8D%E5%90%8C%E7%9A%84view%E7%9A%84%E5%8E%9F%E5%9B%A0%E6%98%AF%EF%BC%8C%E8%BF%90%E8%A1%8C%E6%97%B6%EF%BC%8C%E5%86%85%E5%AD%98%E6%AF%94%E8%BE%83%E5%AE%9D%E8%B4%B5%EF%BC%8CELF%E6%96%87%E4%BB%B6%E8%A2%AB%E5%8A%A0%E8%BD%BD%E6%97%B6%EF%BC%8C%E7%9B%B8%E5%85%B3%E7%9A%84%E8%8A%82(section)%E8%A2%AB%E5%90%88%E5%B9%B6%E6%88%90segment%E3%80%82%0A%0Asegment%E5%88%97%E8%A1%A8%5B2%5D%0A!%5B3b25828c42fd0bec473b2eded7e98d9b.png%5D(evernotecid%3A%2F%2F22617523-9521-4D00-B771-5F27B85F00EB%2Fappyinxiangcom%2F161681%2FENResource%2Fp6378)%0A%E7%A8%8B%E5%BA%8F%E8%BF%90%E8%A1%8C%E6%97%B6%EF%BC%8C%E5%B0%B1%E4%BD%93%E7%8E%B0%E4%B8%BA%E8%BF%99%E4%BA%9B%E6%AE%B5%E3%80%82%E8%80%8C%E5%AF%B9%E4%BA%8E%E6%9C%AC%E6%96%87%E6%AF%94%E8%BE%83%E9%87%8D%E8%A6%81%E7%9A%84%E6%AE%B5%E5%B0%B1%E6%98%AFDYNAMIC%E6%AE%B5%EF%BC%8C%E5%85%B6%E4%B8%AD%E5%8C%85%E5%90%AB%E4%BA%86%E4%B8%80%E7%BB%84_DYNAMIC%20array%E3%80%82%E5%90%8E%E6%96%87%E5%86%8D%E5%81%9A%E4%BB%8B%E7%BB%8D%E3%80%82%0A%0Asection%E5%88%97%E8%A1%A8%E8%8A%82%E9%80%89%5B2%5D%0A!%5B4531bf460ddcca48ecd458d30faa9021.png%5D(evernotecid%3A%2F%2F22617523-9521-4D00-B771-5F27B85F00EB%2Fappyinxiangcom%2F161681%2FENResource%2Fp6379)%0Asection%E5%B0%B1%E6%98%AF%E6%88%91%E4%BB%AC%E5%B8%B8%E8%A7%81%E7%9A%84%E4%BB%A5%E7%82%B9%E5%BC%80%E5%A4%B4%E7%9A%84%E4%B8%80%E4%BA%9B%E6%A0%87%E8%AE%B0%E3%80%82%E9%93%BE%E6%8E%A5%E8%84%9A%E6%9C%AC%EF%BC%88linker%20script%2C%20.lds%E6%96%87%E4%BB%B6%EF%BC%89%EF%BC%8C%E4%B9%9F%E6%AD%A3%E6%98%AF%E5%AE%9A%E4%B9%89%E7%9A%84%E8%BF%99%E4%BA%9BELF%E6%96%87%E4%BB%B6%E4%B8%AD%E7%9A%84%E8%8A%82%E3%80%82%E5%B8%B8%E8%A7%81%E7%9A%84%E8%8A%82%E6%9C%89%3A%20.bss%2C%20.data%2C%20.text%2C%20.init%E7%AD%89%E7%AD%89%E3%80%82%0A%0A%23%23%20%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%0A%E6%88%91%E4%BB%AC%E7%9F%A5%E9%81%93%E5%BD%93%E5%BC%95%E7%94%A8%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%93%E7%9A%84%E6%97%B6%E5%80%99%EF%BC%8C%E9%80%9A%E5%B8%B8%E6%9C%89%E4%B8%A4%E7%A7%8D%E9%93%BE%E6%8E%A5%E6%96%B9%E5%BC%8F%EF%BC%8C%E4%B8%80%E7%A7%8D%E6%98%AF%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%EF%BC%8C%E4%B8%80%E7%A7%8D%E6%98%AF%E9%9D%99%E6%80%81%E9%93%BE%E6%8E%A5%E3%80%82%E9%9D%99%E6%80%81%E9%93%BE%E6%8E%A5%E5%BA%93%E5%9C%A8Windows%E4%B8%8A%E6%98%AF.lib%E7%BB%93%E5%B0%BE%E7%9A%84%EF%BC%8C%E5%9C%A8Linux%E5%B9%B3%E5%8F%B0%E4%B8%8A%E6%98%AF.a%E7%BB%93%E5%B0%BE%E7%9A%84%E3%80%82%E9%9D%99%E6%80%81%E5%BA%93%E4%B8%8D%E6%98%AF%E4%B8%80%E7%A7%8D%E5%8F%AF%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6%EF%BC%8C%E8%80%8C%E5%8F%AA%E6%98%AF%E4%B8%80%E4%BA%9B%E4%BB%A3%E7%A0%81%E5%92%8C%E6%95%B0%E6%8D%AE%E6%89%93%E5%8C%85%EF%BC%88Archive%EF%BC%89%E3%80%82%E5%BD%93%E5%8F%91%E7%94%9F%E9%93%BE%E6%8E%A5%E6%97%B6%EF%BC%8C%E7%94%B1%E9%93%BE%E6%8E%A5%E5%99%A8%E5%B0%86%E5%85%B6%E4%B8%AD%E7%9A%84%E4%BB%A3%E7%A0%81%E5%92%8C%E6%95%B0%E6%8D%AE%E5%88%86%E5%88%AB%E6%94%BE%E5%88%B0%E6%9C%80%E7%BB%88%E7%9A%84ELF%E6%96%87%E4%BB%B6%E7%9A%84%E5%AF%B9%E5%BA%94%E7%9A%84%E8%8A%82%EF%BC%88section%EF%BC%89%E3%80%82%0A%E8%80%8C%E5%8A%A8%E6%80%81%E5%BA%93%E6%98%AF%E4%B8%80%E7%A7%8D%E5%AE%8C%E5%85%A8%E4%B8%8D%E4%B8%80%E6%A0%B7%E7%9A%84%E4%B8%9C%E8%A5%BF%EF%BC%8C%E5%8A%A8%E6%80%81%E5%BA%93%E7%9A%84%E8%A1%8C%E4%B8%BA%E6%9B%B4%E8%B6%8B%E8%BF%91%E4%BA%8E%E5%8F%AF%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6%E3%80%82%E5%9C%A8Windows%E5%B9%B3%E5%8F%B0%E4%B8%8A%EF%BC%8C%E5%8A%A8%E6%80%81%E5%BA%93%E6%96%87%E4%BB%B6%E4%BB%A5.dll%E7%BB%93%E5%B0%BE%EF%BC%8C%E5%9C%A8Linux%E5%B9%B3%E5%8F%B0%E4%B8%8A%EF%BC%8C%E5%8A%A8%E6%80%81%E5%BA%93%E6%96%87%E4%BB%B6%E4%BB%A5.so%E7%BB%93%E5%B0%BE%E3%80%82%0A%E5%9C%A8Windows%E4%B8%8B%EF%BC%8C%E5%A6%82%E6%9E%9C%E8%A6%81%E8%BF%9B%E8%A1%8C%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%EF%BC%8C%E5%BF%85%E9%A1%BB%E4%BD%BF%E7%94%A8LoadLibrary%E5%87%BD%E6%95%B0%E6%89%93%E5%BC%80%E4%B8%80%E4%B8%AA.dll%E5%BA%93%E6%96%87%E4%BB%B6%EF%BC%8C%E5%86%8D%E7%94%A8GetProcAddress%E8%8E%B7%E5%8F%96%E5%85%B7%E4%BD%93%E5%87%BD%E6%95%B0%E7%9A%84%E5%9C%B0%E5%9D%80%EF%BC%8C%E8%BF%9B%E8%A1%8C%E8%B0%83%E7%94%A8%E3%80%82dll%E5%AF%BC%E5%87%BA%E5%87%BD%E6%95%B0%E5%88%97%E8%A1%A8%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8%E5%91%BD%E4%BB%A4%E6%9F%A5%E7%9C%8B%EF%BC%9A%60dumpbin%20%2Fexports%20%3Cdll%E6%96%87%E4%BB%B6%E5%AE%8C%E6%95%B4%E8%B7%AF%E5%BE%84%3E%60%E3%80%82%0ALinux%E4%B8%8B%E4%B9%9F%E6%9C%89%E7%B1%BB%E4%BC%BC%E7%9A%84%E6%96%B9%E5%BC%8F%EF%BC%8C%E5%B0%B1%E6%98%AF%E5%8F%AF%E4%BB%A5%E7%94%A8dlopen%E6%89%93%E5%BC%80%E4%B8%80%E4%B8%AA.so%E6%96%87%E4%BB%B6%EF%BC%8C%E5%86%8D%E7%94%A8dlsym%E6%89%BE%E5%88%B0%E5%AF%B9%E5%BA%94%E7%9A%84%E5%87%BD%E6%95%B0%E3%80%82%E4%BD%86%E6%98%AFLinux%E9%80%9A%E5%B8%B8%E4%BD%BF%E7%94%A8%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%E5%BA%93%E7%9A%84%E6%96%B9%E5%BC%8F%EF%BC%8C%E6%98%AF%E7%9B%B4%E6%8E%A5%E9%93%BE%E6%8E%A5%E3%80%82%E4%BE%8B%E5%A6%82%EF%BC%9A%0A%60gcc%20-L%2Flib%20-ltest%20main.c%20-o%20test%60%0A%E8%BF%99%E5%B0%B1%E6%98%AF%E5%9C%A8lib%E6%90%9C%E7%B4%A2%E8%B7%AF%E5%BE%84%E4%B8%8B%EF%BC%8C%E6%89%BE%E5%88%B0libtest.so%EF%BC%8C%E5%B9%B6%E9%93%BE%E6%8E%A5%E3%80%82%E6%B3%A8%E6%84%8F%E8%BF%99%E9%87%8C%E9%BB%98%E8%AE%A4%E5%85%88%E5%B0%9D%E8%AF%95%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%EF%BC%8C%E5%A6%82%E6%9E%9C%E6%B2%A1%E6%9C%89.so%E6%96%87%E4%BB%B6%EF%BC%8C%E4%BC%9A%E5%86%8D%E5%B0%9D%E8%AF%95%E9%9D%99%E6%80%81%E9%93%BE%E6%8E%A5.a%E6%96%87%E4%BB%B6%E3%80%82%E5%A6%82%E6%9E%9C%E9%83%BD%E6%B2%A1%E6%9C%89%EF%BC%8C%E5%B0%B1%E4%BC%9A%E6%8A%A5%E9%94%99%E3%80%82%E8%BF%99%E4%B9%9F%E5%B0%B1%E6%98%AF%E8%AF%B4Linux%E5%B9%B3%E5%8F%B0%E4%B8%8A%EF%BC%8C%E9%80%9A%E8%BF%87-l%E5%8F%82%E6%95%B0%E6%8C%87%E5%AE%9A%E7%9A%84%E9%93%BE%E6%8E%A5%E5%8F%82%E6%95%B0%EF%BC%8C%E6%98%AF%E9%BB%98%E8%AE%A4%E5%B0%9D%E8%AF%95%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%EF%BC%8C%E5%85%B6%E6%AC%A1%E6%89%8D%E6%98%AF%E9%9D%99%E6%80%81%E9%93%BE%E6%8E%A5%E3%80%82%0A%E5%A6%82%E6%9E%9C%E6%83%B3%E6%8C%87%E5%AE%9A%E4%BD%BF%E7%94%A8%E9%9D%99%E6%80%81%E9%93%BE%E6%8E%A5%EF%BC%8C%E5%8F%AF%E4%BB%A5%E7%94%A8%E4%B8%8B%E9%9D%A2%E7%9A%84%E5%91%BD%E4%BB%A4%EF%BC%9A%0A%60gcc%20-L%2Flib%20-static%20-ltest%20main.c%20-o%20test%60%0A%E6%88%96%E8%80%85%0A%60gcc%20-L%2Flib%20libtest.a%20main.c%20-o%20test%60%0A%0A%23%23%23%20How%20is%20an%20executable%20binary%20in%20Linux%20being%20executed%20%3F%5B2%5D%0A1.%20%60sys_execve%60%20function%20(in%20arch%2Fx86%2Fkernel%2Fprocess.c)%20handles%20the%20execvc%20system%20call%20from%20user%20space.%20It%20calls%20%60do_execve%60%20function.%20%0A2.%20%60do_execve%60%20function%20(in%20fs%2Fexec.c)%20opens%20the%20executable%20binary%20file%20and%20does%20some%20preparation.%20It%20calls%20%60search_binary_handler%60%20function.%20%0A3.%20%60search_binary_handler%60%20function%20(in%20fs%2Fexec.c)%20finds%20out%20the%20type%20of%20executable%20binary%20and%20calls%20the%20corresponding%20handler%2C%20which%20in%20our%20case%2C%20is%20%60load_elf_binary%60%20function.%0A4.%20%60load_elf_binary%60%20(in%20fs%2Fbinfmt_elf.c)%20loads%20the%20user's%20executable%20binary%20file%20into%20memory.%20It%20allocates%20memory%20segments%20and%20zeros%20out%20the%20BSS%20section%20by%20calling%20the%20padzero%20function.%0A%60load_elf_binary%60%20also%20examines%20whether%20the%20user's%20executable%20binary%20contains%20an%20INTERP%20segment%20or%20not.%0A5.%20If%20the%20executable%20binary%20is%20dynamically%20linked%2C%20then%20the%20compiler%20will%20usually%20creates%20an%20**INTERP**%20segment%20(which%20is%20usually%20the%20same%20as%20.interp%20section%20in%20ELF's%20%22linking%20view%22)%2C%20which%20contains%20the%20full%20pathname%20of%20an%20%22interpreter%22%2C%20usually%20is%20the%20Glibc%20runtime%20linker%20ld.so.%0ATo%20see%20this%2C%20use%20command%20%60readelf%20-p%20.interp%20a.out%60%0A%0A6.%20Thus%2C%20if%20the%20ELF%20executable%20binary%20file%20contains%20an%20**INTERP**%20segment%2C%20%60load_elf_binary%60%20will%20call%20load_elf_interp%20function%20to%20load%20the%20image%20of%20this%20interpreter%20as%20well.%0A7.%20Finally%2C%20%60load_elf_binary%60%20calls%20start_thread%20(in%20arch%2Fx86%2Fkernel%2Fprocess_64.c)%20and%20passes%20control%20to%20either%20the%20interpreter%20or%20the%20user%20program.%0A%0A%E8%BF%99%E4%B8%AA1-7%E5%B0%B1%E6%98%AFELF%E6%96%87%E4%BB%B6%E8%A2%AB%E5%8A%A0%E8%BD%BD%E7%9A%84%E8%BF%87%E7%A8%8B%EF%BC%8C%E4%B9%8B%E5%90%8E%EF%BC%8C%E5%86%8D%E5%8F%AA%E8%A6%81%E4%B8%80%E4%B8%AA%E8%B7%B3%E8%BD%AC%E8%AF%AD%E5%8F%A5%EF%BC%8C%E5%B0%B1%E5%8F%AF%E4%BB%A5%E7%9C%9F%E6%AD%A3%E7%9A%84%E6%89%A7%E8%A1%8C%E8%BF%99%E4%B8%AA%E7%A8%8B%E5%BA%8F%E4%BA%86%E3%80%82%E8%BF%99%E9%87%8C%E5%80%BC%E5%BE%97%E5%85%B3%E6%B3%A8%E7%9A%84%E5%B0%B1%E6%98%AF%E7%AC%AC5%E6%AD%A5%E3%80%82%E5%A6%82%E6%9E%9C%E8%A2%AB%E5%8A%A0%E8%BD%BD%E7%9A%84%E4%BA%8C%E8%BF%9B%E5%88%B6%E6%98%AF%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%E7%94%9F%E6%88%90%E7%9A%84%EF%BC%8C%E5%8D%B3%E8%A6%81%E4%B9%88%E6%98%AF%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%E5%BA%93%EF%BC%8C%E8%A6%81%E4%B9%88%E6%98%AF%E5%8F%AF%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6%EF%BC%8C%E5%88%99%E5%8A%A0%E8%BD%BD%E6%97%B6%EF%BC%8C%E5%86%85%E6%A0%B8%E4%BC%9A%E7%BB%99ELF%E7%9A%84%E5%86%85%E5%AD%98%E9%95%9C%E5%83%8F%EF%BC%88%E5%8D%B3%E6%89%80%E8%B0%93%E7%9A%84executing%20view%EF%BC%89%E5%8A%A0%E4%B8%80%E4%B8%AAINTERP%E6%AE%B5%EF%BC%88segment%EF%BC%89%E3%80%82%E8%80%8C%E8%BF%99%E4%B8%AA%E6%AE%B5%E5%B0%B1%E6%98%AF%E6%89%80%E8%B0%93%E7%9A%84runtime%20linker%EF%BC%88compile%E6%97%B6%E7%9A%84linker%EF%BC%8C%E5%8D%B3ld%EF%BC%8C%E7%A7%B0%E4%B8%BAlink%20editor%EF%BC%89%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AFld.so%E3%80%82%0A%0A%23%23%23%20ld.so%0A%E4%BB%80%E4%B9%88%E6%98%AFld.so%3F%20ld.so%E5%81%9A%E4%BA%86%E4%BA%9B%E5%95%A5%EF%BC%9F%E6%96%87%E7%8C%AE%5B2%5D%E9%83%BD%E5%81%9A%E4%BA%86%E5%BE%88%E5%A5%BD%E7%9A%84%E8%AF%B4%E6%98%8E%E3%80%82%0A%3E%20ld.so%20is%20the%20runtime%20linker%2Floader%20(the%20compile-time%20linker%20ld%20is%20formally%20called%20%22link%20editor%22)%20for%20dynamic%20executables.%20It%20provides%20the%20following%20services%20%5B2%5D%3A%0A%3E%20-%20Analyzes%20the%20user's%20executable%20binary's%20DYNAMIC%20segment%20and%20determines%20what%20dependencies%20are%20required.%20%0A%3E%20-%20Locates%20and%20loads%20these%20**dependencies**%2C%20analyzes%20their%20DYNAMIC%20segments%20to%20determine%20if%20more%20dependencies%20are%20required.%0A%3E%20-%20Performs%20any%20necessary%20relocations%20to%20bind%20these%20objects.%0A%3E%20-%20Calls%20any%20initialization%20functions%20(see%20below)%20provided%20by%20these%20dependencies.%0A%3E%20-%20Passes%20control%20to%20user's%20executable%20binary.%0A%0A%23%23%23%20How%20does%20ld.so%20work%20%3F%5B2%5D%0Ald.so%E6%98%AF%E7%94%A8%E6%9D%A5%E5%8A%A0%E8%BD%BD%E6%89%80%E6%9C%89%E7%9A%84%E5%8A%A8%E6%80%81%E5%BA%93%E7%9A%84%EF%BC%8C%E6%89%80%E4%BB%A5ld.so%E6%9C%AC%E8%BA%AB%E4%B8%8D%E6%98%AF%E5%8A%A8%E6%80%81%E5%8A%A0%E8%BD%BD%E7%9A%84%E3%80%82ld.so%E7%9A%84%E5%85%A5%E5%8F%A3%E5%9C%A8_dl_start%E3%80%82%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87gdb%E5%81%9C%E5%9C%A8%E8%BF%99%E4%B8%AA%E5%87%BD%E6%95%B0%E4%B8%8A%E3%80%82%0A%60%60%60%0A(gdb)%20break%20_dl_start%0AFunction%20%22_dl_start%22%20not%20defined.%0AMake%20breakpoint%20pending%20on%20future%20shared%20library%20load%3F%20(y%20or%20%5Bn%5D)%20y%0ABreakpoint%201%20(_dl_start)%20pending.%0A(gdb)%20run%0AStarting%20program%3A%20a.out%0A%0ABreakpoint%201%2C%200x0000003433e00fa0%20in%20_dl_start%20()%20from%20%2Flib64%2Fld-linux-x86-64.so.2%0A(gdb)%20bt%0A%230%20%200x0000003433e00fa0%20in%20_dl_start%20()%20from%20%2Flib64%2Fld-linux-x86-64.so.2%0A%231%20%200x0000003433e00a78%20in%20_start%20()%20from%20%2Flib64%2Fld-linux-x86-64.so.2%0A%232%20%200x0000000000000001%20in%20%3F%3F%20()%0A%233%20%200x00007fffffffe4f2%20in%20%3F%3F%20()%0A%234%20%200x0000000000000000%20in%20%3F%3F%20()%0A...%0A(gdb)%20x%2F10i%20%24pc%0A%20%20%200x3433e00a70%20%3C_start%3E%3A%20%20%20%20%20%20%20mov%20%20%20%20%25rsp%2C%25rdi%0A%20%20%200x3433e00a73%20%3C_start%2B3%3E%3A%20%20%20%20%20callq%20%200x3433e00fa0%20%3C_dl_start%3E%0A%20%20%200x3433e00a78%20%3C_dl_start_user%3E%3A%20%20%20%20%20%20%20mov%20%20%20%20%25rax%2C%25r12%0A%20%20%200x3433e00a7b%20%3C_dl_start_user%2B3%3E%3A%20%20%20%20%20mov%20%20%20%200x21b30b(%25rip)%2C%25eax%20%20%20%20%20%20%20%20%23%200x343401bd8c%20%3C_dl_skip_args%3E%0A...%0A%60%60%60%0A%E5%BD%93_dl_start%E6%89%A7%E8%A1%8C%E5%AE%8C%E5%90%8E%EF%BC%8Cld.so%E5%B0%B1%E4%BC%9A%E4%B8%BA%E6%88%91%E4%BB%AC%E5%88%86%E6%9E%90%E4%BE%9D%E8%B5%96%E5%85%B3%E7%B3%BB%EF%BC%8C%E5%B9%B6%E5%8A%A0%E8%BD%BD%E8%B5%B7%E6%89%80%E6%9C%89%E5%BF%85%E9%9C%80%E7%9A%84%E5%8A%A8%E6%80%81%E5%BA%93%E6%96%87%E4%BB%B6%E3%80%82%0A!%5Be64fb8aa42aac26092b764a6ebccaf43.png%5D(evernotecid%3A%2F%2F22617523-9521-4D00-B771-5F27B85F00EB%2Fappyinxiangcom%2F161681%2FENResource%2Fp6382)%0A%E4%B8%8A%E5%9B%BE%E5%B0%B1%E6%98%AFld.so%E5%8A%A0%E8%BD%BD%E5%AE%8C%E6%88%90%E5%90%8E%EF%BC%8C%E7%A8%8B%E5%BA%8F%E7%9A%84%E5%86%85%E5%AD%98%E5%88%86%E5%B8%83%E3%80%82%E5%85%B6%E4%B8%AD%E5%8F%AF%E4%BB%A5%E5%8F%91%E7%8E%B0%E6%AF%8F%E4%B8%AAso%E6%96%87%E4%BB%B6%E9%83%BD%E5%8D%A0%E4%BA%864%E4%B8%AA%E8%A1%A8%E9%A1%B9%E3%80%82%E6%88%91%E4%B8%80%E5%BA%A6%E4%BB%A5%E4%B8%BA%E8%BF%994%E4%B8%AA%E8%A1%A8%E9%A1%B9%E9%83%BD%E6%98%AF%E5%90%8C%E6%A0%B7%E7%9A%84%E4%B8%9C%E8%A5%BF%E3%80%82%E4%BD%86%E5%A6%82%E4%B8%8A%E5%9B%BE%E6%89%80%E7%A4%BA%2C%E8%BF%99%E6%AF%8F%E4%B8%80%E6%AE%B5%E5%AE%9E%E9%99%85%E6%98%AF%E5%8A%A8%E6%80%81%E5%BA%93%E8%A2%AB%E5%8A%A0%E8%BD%BD%E7%94%9F%E6%88%90%E7%9A%84%E6%AE%B5%EF%BC%8C%E6%AF%8F%E4%B8%80%E6%AE%B5%E6%9C%89%E4%B8%8D%E5%90%8C%E7%9A%84%E5%86%85%E5%AE%B9%E5%92%8C%E4%B8%8D%E5%90%8C%E7%9A%84%E6%9D%83%E9%99%90%E6%A0%87%E8%AE%B0%E3%80%82%E8%80%8C%E6%88%91%E4%BB%AC%E5%85%B3%E5%BF%83%E7%9A%84%E5%92%8C%E5%87%BD%E6%95%B0%E8%B7%B3%E8%BD%AC%E7%9B%B8%E5%85%B3%E7%9A%84PLT%26GOT%E6%95%B0%E6%8D%AE%E5%9C%A8%E8%BF%99%E9%87%8C%EF%BC%9A%0A%60%60%60%0A0000003434551000%20%20%20%20%20%204K%20rw---%20%20%2Flib64%2Flibc-2.5.so%20%20%20%20%20%3C--%20.got.plt%20.data%20sections%0A%60%60%60%0A%23%23%20PLT%20%26%20GOT%0APLT%20%3D%20Procedure%20Linkage%20Table%0AGOT%20%3D%20Global%20Offsets%20Table%0APLT%E8%A1%A8%E6%90%AD%E9%85%8DGOT%E8%A1%A8%E5%B0%B1%E5%8F%AF%E4%BB%A5%E5%AE%8C%E6%88%90%E5%8A%A8%E6%80%81%E5%BA%93%E5%87%BD%E6%95%B0%E7%9A%84%E9%87%8D%E5%AE%9A%E5%90%91%E3%80%82%0A%E5%BD%93%E7%BC%96%E8%AF%91%E6%97%B6%EF%BC%8C%E5%9C%A8%E9%93%BE%E6%8E%A5%E9%98%B6%E6%AE%B5%EF%BC%8C%E7%BC%96%E8%AF%91%E5%99%A8%E4%BC%9A%E6%9F%A5%E6%89%BE%E5%87%BD%E6%95%B0%E5%AE%9A%E4%B9%89%EF%BC%8C%E5%A6%82%E6%9E%9C%E5%9C%A8%E6%89%80%E6%9C%89%E7%9A%84%E5%8F%AF%E9%87%8D%E5%AE%9A%E5%90%91%E4%BB%A3%E7%A0%81%E4%B8%AD%EF%BC%8C%E5%8D%B3.o%E3%80%81.a%E6%96%87%E4%BB%B6%EF%BC%8C%E6%97%A0%E6%B3%95%E6%89%BE%E5%88%B0%E5%87%BD%E6%95%B0%E5%AE%9A%E4%B9%89%EF%BC%8C%E5%88%99%E4%BC%9A%E5%8E%BB%E9%93%BE%E6%8E%A5%E6%8C%87%E5%AE%9A%E7%9A%84%E5%8A%A8%E6%80%81%E5%BA%93.so%E6%96%87%E4%BB%B6%E4%B8%AD%E6%89%BE%E3%80%82%E8%BF%99%E9%87%8C%E6%9C%89%E4%B8%A4%E5%B1%82%E6%84%8F%E6%80%9D%EF%BC%9A%0A1.%20%E4%BC%9A%E4%BC%98%E5%85%88%E6%9F%A5%E6%89%BE%E6%9C%89%E5%87%BD%E6%95%B0%E5%AE%9A%E4%B9%89%E7%9A%84%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AF%E8%AF%B4%E9%9D%99%E6%80%81%E5%BA%93%E6%88%96%E6%BA%90%E6%96%87%E4%BB%B6%E4%B8%AD%E5%AE%9A%E4%B9%89%E7%9A%84%E5%87%BD%E6%95%B0%E6%98%AF%E5%8F%AF%E4%BB%A5%E8%A6%86%E7%9B%96%E5%8A%A8%E6%80%81%E5%BA%93%E4%B8%AD%E5%87%BD%E6%95%B0%E7%9A%84%0A2.%20%E7%BC%96%E8%AF%91%E5%99%A8%E4%BC%9A%E4%B8%BA%E5%8A%A8%E6%80%81%E5%BA%93%E4%B8%AD%E5%87%BD%E6%95%B0%E7%94%9F%E6%88%90%E8%B7%B3%E8%BD%AC%E4%BB%A3%E7%A0%81%E3%80%82%E8%80%8C%E8%BF%99%E4%B8%AA%E8%B7%B3%E8%BD%AC%E4%BB%A3%E7%A0%81%E5%B0%B1%E6%98%AFPLT%E8%A1%A8%0A%0A%E5%8F%AF%E4%BB%A5%E7%94%A8%60objdump%20-M%20intel%20-dj%20.plt%20a.out%60%E5%91%BD%E4%BB%A4%E6%9F%A5%E7%9C%8BPLT%E8%A1%A8%E5%85%B7%E4%BD%93%E5%8F%8D%E7%BC%96%E8%AF%91%E4%BB%A3%E7%A0%81%EF%BC%8C%E4%BE%8B%E5%A6%82%EF%BC%9A%0A!%5B0cedb50bdb3533f742e00a36b7e1ecc7.png%5D(evernotecid%3A%2F%2F22617523-9521-4D00-B771-5F27B85F00EB%2Fappyinxiangcom%2F161681%2FENResource%2Fp6383)%0A%E4%B8%80%E4%B8%AAPLT%E8%A1%A8%E9%A1%B9%E5%B0%B1%E6%98%AF3%E6%9D%A1%E6%B1%87%E7%BC%96%E8%AF%AD%E5%8F%A5%2C%E5%85%B6%E6%B5%81%E7%A8%8B%E5%B0%B1%E6%98%AF%E4%B8%8B%E5%9B%BE%E4%B8%AD%E7%9A%841-9%0A!%5B72a1cbeb63b77c76658f39d3659009d0.png%5D(evernotecid%3A%2F%2F22617523-9521-4D00-B771-5F27B85F00EB%2Fappyinxiangcom%2F161681%2FENResource%2Fp6384)%0A-%20%E7%AC%AC%E4%B8%80%E6%9D%A1%E6%B1%87%E7%BC%96%E8%AF%AD%E5%8F%A5%EF%BC%8C%E5%B0%B1%E6%98%AF%E8%B7%B3%E8%BD%AC%E5%88%B0GOT%E5%AF%B9%E5%BA%94%E8%A1%A8%E9%A1%B9%EF%BC%8C%E5%BD%93%E8%AF%A5%E8%A1%A8%E9%A1%B9%E5%B0%9A%E6%9C%AA%E8%A2%AB%E5%A1%AB%E5%85%85%E6%97%B6%EF%BC%88%E5%87%BD%E6%95%B0%E7%AC%AC%E4%B8%80%E6%AC%A1%E8%A2%AB%E8%B0%83%E7%94%A8%EF%BC%89%EF%BC%8CGOT%E8%A1%A8%E9%A1%B9%E4%BC%9A%E9%87%8D%E6%96%B0%E8%B7%B3%E5%9B%9E%E5%88%B0PLT%E8%A1%A8%E9%A1%B9%E7%9A%84%E4%B8%8B%E4%B8%80%E6%9D%A1%E6%B1%87%E7%BC%96%0A-%20%E7%AC%AC%E4%BA%8C%E6%9D%A1%E6%B1%87%E7%BC%96%E8%AF%AD%E5%8F%A5%EF%BC%8C%E5%B0%86%E5%87%BD%E6%95%B0%E7%BC%96%E5%8F%B7push%E5%88%B0%E6%A0%88%E4%B8%8A%EF%BC%8C%E6%AD%A4%E6%97%B6%E6%98%AF%E5%87%86%E5%A4%87%E4%B8%80%E6%AC%A1%E5%87%BD%E6%95%B0%E8%B0%83%E7%94%A8%0A-%20%E7%AC%AC%E4%B8%89%E6%9D%A1%E6%B1%87%E7%BC%96%E8%AF%AD%E5%8F%A5%EF%BC%8C%E8%B7%B3%E8%BD%AC%E5%88%B0PLT%E8%A1%A8%E5%BC%80%E5%A7%8B%E7%9A%84%E5%9C%B0%E6%96%B9%E3%80%82PLT%E7%AC%AC%E4%B8%80%E4%B8%AA%E8%A1%A8%E9%A1%B9%E6%8C%87%E5%90%91%E7%9A%84%E6%98%AF_dl_runtime_resolve%E5%87%BD%E6%95%B0%EF%BC%8C%E8%AF%A5%E5%87%BD%E6%95%B0%E4%BC%9A%E6%89%BE%E5%88%B0%E4%B9%8B%E5%89%8D%E4%BC%A0%E5%85%A5%E7%9A%84%E5%87%BD%E6%95%B0%E7%BC%96%E5%8F%B7%E5%AF%B9%E5%BA%94%E7%9A%84%E5%87%BD%E6%95%B0%E5%9C%B0%E5%9D%80%EF%BC%8C%E5%B9%B6%E5%A1%AB%E5%85%85%E5%AF%B9%E5%BA%94%E7%9A%84GOT%E8%A1%A8%E9%A1%B9%E3%80%82%0A%0A%E5%85%B3%E4%BA%8E%E5%87%BD%E6%95%B0%E7%BC%96%E5%8F%B7%EF%BC%8C%E4%B8%BE%E4%B8%AA%E4%BE%8B%E5%AD%90%EF%BC%8C%E8%A7%A3%E9%87%8A%E4%B8%80%E4%B8%8B%EF%BC%9A%0A%60%60%60%0A%23include%20%3Cstdio.h%3E%0A%23include%20%3Cfcntl.h%3E%0Aint%20func(void)%0A%7B%0A%20%20%20%20open(%22foo.txt%22%2C%20O_CREAT)%3B%0A%20%20%20%20fopen(%22foo.txt%22%2C%20%22rw%22)%3B%0A%20%20%20%20printf(%22hello%2C%20in%20test.so%5Cn%22)%3B%0A%20%20%20%20return%200%3B%0A%7D%0A%60%60%60%0A%E8%BF%99%E9%87%8C%E5%BC%95%E7%94%A8%E4%BA%86glibc%E9%87%8C%E7%9A%843%E4%B8%AA%E5%87%BD%E6%95%B0%EF%BC%8C%E7%94%A8readelf%20-r%E6%9F%A5%E7%9C%8B%EF%BC%8C%E5%88%99%E4%BC%9A%E5%BE%97%E5%88%B0%E4%B8%8B%E9%9D%A2%E7%9A%84%E7%BB%93%E6%9E%9C%EF%BC%9A%0A%60%60%60%0A%E9%87%8D%E5%AE%9A%E4%BD%8D%E8%8A%82%20'.rela.plt'%20at%20offset%200x508%20contains%203%20entries%3A%0A%20%20%E5%81%8F%E7%A7%BB%E9%87%8F%20%20%20%20%20%20%20%20%20%20%E4%BF%A1%E6%81%AF%20%20%20%20%20%20%20%20%20%20%20%E7%B1%BB%E5%9E%8B%20%20%20%20%20%20%20%20%20%20%20%E7%AC%A6%E5%8F%B7%E5%80%BC%20%20%20%20%20%20%20%20%E7%AC%A6%E5%8F%B7%E5%90%8D%E7%A7%B0%20%2B%20%E5%8A%A0%E6%95%B0%0A000000201018%20%20000200000007%20R_X86_64_JUMP_SLO%200000000000000000%20puts%40GLIBC_2.2.5%20%2B%200%0A000000201020%20%20000400000007%20R_X86_64_JUMP_SLO%200000000000000000%20open%40GLIBC_2.2.5%20%2B%200%0A000000201028%20%20000500000007%20R_X86_64_JUMP_SLO%200000000000000000%20fopen%40GLIBC_2.2.5%20%2B%200%0A%60%60%60%0A%E5%88%99puts%E5%AF%B9%E5%BA%94%E7%9A%84%E7%BC%96%E5%8F%B7%E5%B0%B1%E6%98%AF0%EF%BC%8Copen%E6%98%AF1%EF%BC%8Cfopen%E6%98%AF2%E3%80%82%E7%9C%8B%E7%9C%8BPLT%E8%A1%A8%EF%BC%9A%0A%60%60%60%0A000000000000580%20%3Cputs%40plt%3E%3A%0A%20580%3A%09ff%2025%2092%200a%2020%2000%20%20%20%20%09jmp%20%20%20%20QWORD%20PTR%20%5Brip%2B0x200a92%5D%20%20%20%20%20%20%20%20%23%20201018%20%3Cputs%40GLIBC_2.2.5%3E%0A%20586%3A%0968%2000%2000%2000%2000%20%20%20%20%20%20%20%09push%20%20%200x0%0A%2058b%3A%09e9%20e0%20ff%20ff%20ff%20%20%20%20%20%20%20%09jmp%20%20%20%20570%20%3C.plt%3E%0A%0A0000000000000590%20%3Copen%40plt%3E%3A%0A%20590%3A%09ff%2025%208a%200a%2020%2000%20%20%20%20%09jmp%20%20%20%20QWORD%20PTR%20%5Brip%2B0x200a8a%5D%20%20%20%20%20%20%20%20%23%20201020%20%3Copen%40GLIBC_2.2.5%3E%0A%20596%3A%0968%2001%2000%2000%2000%20%20%20%20%20%20%20%09push%20%20%200x1%0A%2059b%3A%09e9%20d0%20ff%20ff%20ff%20%20%20%20%20%20%20%09jmp%20%20%20%20570%20%3C.plt%3E%0A%0A00000000000005a0%20%3Cfopen%40plt%3E%3A%0A%205a0%3A%09ff%2025%2082%200a%2020%2000%20%20%20%20%09jmp%20%20%20%20QWORD%20PTR%20%5Brip%2B0x200a82%5D%20%20%20%20%20%20%20%20%23%20201028%20%3Cfopen%40GLIBC_2.2.5%3E%0A%205a6%3A%0968%2002%2000%2000%2000%20%20%20%20%20%20%20%09push%20%20%200x2%0A%205ab%3A%09e9%20c0%20ff%20ff%20ff%20%20%20%20%20%20%20%09jmp%20%20%20%20570%20%3C.plt%3E%0A%60%60%60%0A%E7%90%86%E8%A7%A3%E4%BA%86PLT%E5%92%8CGOT%E8%A1%A8%E5%9C%A8%E8%A7%A3%E6%9E%90%E5%87%BD%E6%95%B0%E5%9C%B0%E5%9D%80%E4%B8%AD%E7%9A%84%E4%BD%9C%E7%94%A8%EF%BC%8C%E5%B0%B1%E5%8F%AF%E4%BB%A5%E7%9D%80%E6%89%8B%E4%BF%AE%E6%94%B9GOT%E8%A1%A8%EF%BC%8C%E8%AE%A9%E5%87%BD%E6%95%B0%E8%B7%B3%E8%BD%AC%E5%88%B0%E6%88%91%E4%BB%AC%E5%B8%8C%E6%9C%9B%E7%9A%84%E5%87%BD%E6%95%B0%E6%89%A7%E8%A1%8C%E3%80%82%0A%23%23%20%E6%9B%BF%E6%8D%A2GOT%E8%A1%A8%E9%A1%B9%0A%E6%AD%A3%E5%A6%82%E5%89%8D%E6%96%87%E6%89%80%E8%AF%B4%EF%BC%8C%E8%A6%81%E5%81%9A%E8%BF%99%E4%B8%AA%E6%9B%BF%E6%8D%A2%E7%9A%84%E6%93%8D%E4%BD%9C%EF%BC%8C%E5%B0%B1%E6%98%AF%E8%A6%81%E6%89%BE%E5%88%B0GOT%E8%A1%A8%E5%AF%B9%E5%BA%94%E7%9A%84%E8%A1%A8%E9%A1%B9%E5%9C%A8%E5%93%AA%E9%87%8C%EF%BC%8C%E7%84%B6%E5%90%8E%E4%BF%AE%E6%94%B9%E5%AF%B9%E5%BA%94%E7%9A%84%E5%87%BD%E6%95%B0%E5%9C%B0%E5%9D%80%E5%8D%B3%E5%8F%AF%E3%80%82%E8%BF%99%E6%B6%89%E5%8F%8A%E5%88%B0%E8%A7%A3%E6%9E%90%E5%86%85%E5%AD%98%E4%B8%AD%E7%9A%84%E7%A8%8B%E5%BA%8Felf%E6%A0%BC%E5%BC%8F%E7%9A%84%E9%95%9C%E5%83%8F%E3%80%82%0A%23%23%23%20dynamic%20section%0A%E6%89%80%E6%9C%89%E5%92%8C%E9%87%8D%E5%AE%9A%E5%90%91%E6%9C%89%E5%85%B3%E7%9A%84%E4%BF%A1%E6%81%AF%E9%83%BD%E5%8C%85%E5%90%AB%E5%9C%A8dynamic%20section%E4%B8%AD%EF%BC%8C%E5%9C%A8elf%E7%9A%84execution%20view%E4%B8%AD%EF%BC%8C%E4%B9%9F%E5%8F%AF%E4%BB%A5%E7%A7%B0%E4%BD%9Cdynamic%20segment%E3%80%82%E5%AE%9E%E9%99%85%E4%B8%8A%EF%BC%8C%E8%BF%99%E4%B8%A4%E8%80%85%E6%98%AF%E5%90%8C%E4%B8%80%E4%B8%AA%E4%B8%9C%E8%A5%BF%EF%BC%8C%E5%8F%AA%E6%98%AF%E5%AD%98%E5%9C%A8%E7%9A%84%E6%96%B9%E5%BC%8F%E4%B8%8D%E5%90%8C%E3%80%82%E5%BD%93%E7%84%B6%EF%BC%8C%E5%9B%A0%E4%B8%BA%E6%88%91%E4%BB%AC%E8%A6%81%E5%81%9A%E7%9A%84%E6%98%AF%E5%8A%A8%E6%80%81%E7%9A%84GOT%E4%BF%AE%E6%94%B9%EF%BC%8C%E6%89%80%E4%BB%A5%E6%88%91%E4%BB%AC%E8%A6%81%E6%89%BE%E5%88%B0dynamic%20segment%E5%9C%A8%E5%86%85%E5%AD%98%E4%B8%AD%E7%9A%84%E4%BD%8D%E7%BD%AE%E3%80%82%0A%E7%94%B1%E5%89%8D%E6%96%87%E5%8F%AF%E7%9F%A5%EF%BC%8C%E8%A6%81%E5%9C%A8execution%20view%E4%B8%AD%E6%9F%A5%E6%89%BE%E6%AE%B5%EF%BC%8C%E5%BA%94%E8%AF%A5%E8%A6%81%E7%94%A8%E5%88%B0Programm%20Header%20Table%EF%BC%88PHT%EF%BC%89%E3%80%82%E9%80%9A%E8%BF%87%60objdump%20-x%60%E5%91%BD%E4%BB%A4%E5%8F%AF%E4%BB%A5%E6%9F%A5%E7%9C%8BPHT%E8%A1%A8%E9%A1%B9%E3%80%82%E5%85%B6%E4%B8%AD%E6%88%91%E4%BB%AC%E5%85%B3%E5%BF%83%E7%9A%84%E5%B0%B1%E6%98%AFDYNAMIC%E6%AE%B5%E3%80%82%E5%AE%83%E5%8C%85%E5%90%AB%E4%BA%86%E6%89%80%E6%9C%89dynamic%20section%E7%9A%84%E4%BF%A1%E6%81%AF%E3%80%82%E4%BB%A3%E7%A0%81%E9%87%8C%E9%9D%A2%EF%BC%8C%E5%8F%AF%E4%BB%A5%E5%A6%82%E4%B8%8B%E7%9A%84%E8%8E%B7%E5%BE%97dynamic%E3%80%82%0A%60%60%60%20c%0A%2F%2F%201.%20%E9%80%9A%E8%BF%87%2Fproc%2F%3Cpid%3E%2Fmaps%E5%BE%97%E5%88%B0elf%E5%8A%A0%E8%BD%BD%E7%9A%84%E5%9C%B0%E5%9D%80%0A%20%20%20%20snprintf(filename%2C%20sizeof(filename)%2C%20%22%2Fproc%2F%25d%2Fmaps%22%2C%20pid)%3B%0A%0A%20%20%20%20%2F%2F%20%E6%89%93%E5%BC%80%E6%96%87%E4%BB%B6%2Fproc%2Fpid%2Fmaps%EF%BC%8C%E8%8E%B7%E5%8F%96%E6%8C%87%E5%AE%9Apid%E8%BF%9B%E7%A8%8B%E5%8A%A0%E8%BD%BD%E7%9A%84%E5%86%85%E5%AD%98%E6%A8%A1%E5%9D%97%E4%BF%A1%E6%81%AF%0A%20%20%20%20fp%20%3D%20fopen(filename%2C%20%22r%22)%3B%0A%20%20%20%20if(fp%20!%3D%20NULL)%7B%0A%20%20%20%20%20%20%20%20%2F%2F%20%E6%AF%8F%E6%AC%A1%E4%B8%80%E8%A1%8C%EF%BC%8C%E8%AF%BB%E5%8F%96%E6%96%87%E4%BB%B6%20%2Fproc%2Fpid%2Fmaps%E4%B8%AD%E5%86%85%E5%AE%B9%0A%20%20%20%20%20%20%20%20while(fgets(line%2C%20sizeof(line)%2C%20fp))%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20%E6%9F%A5%E6%89%BE%E6%8C%87%E5%AE%9A%E7%9A%84so%E6%A8%A1%E5%9D%97%0A%20%20%20%20%20%20%20%20%20%20%20%20if(strstr(line%2C%20module_name))%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20%E5%88%86%E5%89%B2%E5%AD%97%E7%AC%A6%E4%B8%B2%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20pch%20%3D%20strtok(line%2C%20%22-%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BD%AC%E9%95%BF%E6%95%B4%E5%BD%A2%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20addr%20%3D%20strtoul(pch%2C%20NULL%2C%2016)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20break%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20fclose(fp)%3B%0A%20%20%0A%2F%2F%202.%20%E9%80%9A%E8%BF%87%E9%81%8D%E5%8E%86program%20header%20table%EF%BC%8C%E6%89%BE%E5%88%B0dynameic%E6%AE%B5%0A%20%20%20%20unsigned%20long%20long%20dynamicAddr%20%3D%200%3B%0A%20%20%20%20unsigned%20int%20dynamicSize%20%3D%200%3B%0A%20%20%20%20int%20j%20%3D%200%3B%0A%20%20%20%20for%20(j%20%3D%200%3B%20j%20%3C%20phdr_count%3B%20j%2B%2B)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20if%20(phdr_table%5Bj%5D.p_type%20%3D%3D%20PT_DYNAMIC)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20dynamicAddr%20%3D%20phdr_table%5Bj%5D.p_vaddr%20%2B%20(uint64_t)base_addr%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20dynamicSize%20%3D%20phdr_table%5Bj%5D.p_memsz%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20break%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%60%60%60%0A%23%23%23%20relocation%20tables%0A%E9%80%9A%E8%BF%87%60objdump%20-h%60%E5%91%BD%E4%BB%A4%E5%8F%AF%E4%BB%A5%E6%9F%A5%E7%9C%8B%E6%96%87%E4%BB%B6%E5%8C%85%E5%90%AB%E7%9A%84section%E3%80%82%E5%92%8Crelocation%E7%9B%B8%E5%85%B3%E7%9A%84%E8%8A%82%E6%9C%89%EF%BC%9A%0A-%20.got%0A-%20.got.plt%0A-%20.plt%0A-%20rel(a).dyn%0A-%20rel(a).plt%0A-%20%E5%85%B6%E4%BB%96rel(a).xxx%E8%8A%82%0A%E5%88%9A%E5%BC%80%E5%A7%8B%E7%9A%84%E6%97%B6%E5%80%99%EF%BC%8C%E8%BF%99%E4%BA%9B%E7%B1%BB%E4%BC%BC%E7%9A%84%E8%8A%82%E5%90%8D%E5%BE%88%E5%AE%B9%E6%98%93%E8%AE%A9%E4%BA%BA%E6%B7%B7%E6%B7%86%E3%80%82%E5%85%B6%E5%AE%9E%E5%92%8C%E6%88%91%E4%BB%AC%E7%9B%AE%E6%A0%87%E7%9C%9F%E6%AD%A3%E7%9B%B8%E5%85%B3%E7%9A%84%E6%98%AFrel(a).plt%E3%80%82%E5%85%B6%E4%BB%96%E7%9A%84%E8%AE%A9%E6%88%91%E4%BE%9D%E6%AC%A1%E6%BE%84%E6%B8%85%E4%B8%80%E4%B8%8B%E3%80%82%E4%B8%8D%E8%BF%87%E9%83%BD%E6%98%AF%E6%88%91%E4%B8%AA%E4%BA%BA%E7%9A%84%E7%90%86%E8%A7%A3%EF%BC%8C%E5%8F%AF%E8%83%BD%E6%9C%89%E5%81%8F%E9%A2%87%E4%B9%8B%E5%A4%84%E3%80%82%0A%E5%85%88%E7%94%A8%60readelf%20-S%60%E6%9F%A5%E7%9C%8B%E4%B8%80%E4%B8%8Bsection%20header%20table%E3%80%82%0A!%5B019332646fc3af113a870a76896c8b89.png%5D(evernotecid%3A%2F%2F22617523-9521-4D00-B771-5F27B85F00EB%2Fappyinxiangcom%2F161681%2FENResource%2Fp6385)%0A.plt%E5%92%8C.plt.got%E4%BB%A5%E5%8F%8A.got%E5%92%8C.got.plt%E9%83%BD%E6%98%AFPROGBITS%E7%B1%BB%E5%9E%8B%E3%80%82%E5%85%B3%E4%BA%8EPROGBITS%E7%B1%BB%E5%9E%8B%E7%9A%84%E8%A7%A3%E9%87%8A%E6%98%AF%EF%BC%9A%0A%3E%20**PROGBITS**%20is%20stored%20in%20the%20disk%20image%2C%20as%20opposed%20to%20allocated%20and%20initialized%20at%20load.%0A%3E%20%E8%8A%82%E5%8C%BA%E7%B1%BB%E5%9E%8B%EF%BC%9APROGBITS-%E7%A8%8B%E5%BA%8F%E5%AE%9A%E4%B9%89%E7%9A%84%E4%BF%A1%E6%81%AF%EF%BC%8CNOBITS-%E4%B8%8D%E5%8D%A0%E7%94%A8%E6%96%87%E4%BB%B6%E7%A9%BA%E9%97%B4(bss)%2CREL-%E9%87%8D%E5%AE%9A%E4%BD%8D%E8%A1%A8%E9%A1%B9%0A%0A%E5%AF%B9%E4%BA%8E%E5%90%84%E8%8A%82%E5%8C%BA%EF%BC%8C%5B2%5D%E4%B8%AD%E7%9A%84%E8%A7%A3%E9%87%8A%E4%B8%BA%EF%BC%9A%0A-%20.plt%3A%09For%20dynamic%20binaries%2C%20this%20Procedure%20Linkage%20Table%20holds%20the%20trampoline%2Flinkage%20code.%20See%20paragraphs%20below.%0A-%20.got%3A%09For%20dynamic%20binaries%2C%20this%20Global%20Offset%20Table%20holds%20the%20addresses%20of%20variables%20which%20are%20relocated%20upon%20loading.%0A-%20.got.plt%3A%09For%20dynamic%20binaries%2C%20this%20Global%20Offset%20Table%20holds%20the%20addresses%20of%20functions%20in%20dynamic%20libraries.%20They%20are%20used%20by%20trampoline%20code%20in%20.plt%20section.%0A%0A%E5%AF%B9%E4%BA%8E.plt.got%E5%8C%BA%E7%BD%91%E4%B8%8A%E6%90%9C%E5%88%B0%E7%9A%84%E8%A7%A3%E9%87%8A%E6%98%AF%EF%BC%9A%0A-%20This%20just%20seems%20to%20contain%20code%20to%20jump%20to%20the%20first%20entry%20of%20the%20.got.%0A%0A%E8%BF%99%E9%87%8C%E5%BE%88%E5%AE%B9%E6%98%93%E8%AE%A9%E4%BA%BA%E6%9C%89%E5%BE%88%E6%B7%B7%E4%B9%B1%E7%9A%84%E6%84%9F%E8%A7%89%EF%BC%8C%E5%8F%88%E6%98%AF.got.plt%E7%9A%84%2C%20%E5%8F%88%E6%98%AF.plt.got%E7%9A%84%E3%80%82%E7%BD%91%E7%BB%9C%E4%B8%8A%E4%B9%9F%E5%BE%88%E9%9A%BE%E6%9F%A5%E5%88%B0%E4%B8%A4%E8%80%85%E4%B9%8B%E9%97%B4%E7%9A%84%E8%81%94%E7%B3%BB%E5%92%8C%E5%8C%BA%E5%88%AB%E3%80%82%E6%A0%B9%E6%8D%AE%E6%88%91%E4%B8%AA%E4%BA%BA%E7%9A%84%E5%AE%9E%E9%AA%8C%E7%BB%8F%E9%AA%8C%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E6%95%B0%E6%8D%AE%EF%BC%8C%E5%AD%98%E5%82%A8%E7%9D%80%E8%BF%99%E4%BA%9B%E5%87%BD%E6%95%B0%E8%A2%ABresolve%E5%90%8E%E6%9C%80%E7%BB%88%E7%9A%84%E5%9C%B0%E5%9D%80%E3%80%82%0A-%20.plt%E5%BC%80%E5%A4%B4%E8%A1%A8%E9%A1%B9%E7%9A%84%E8%B7%B3%E6%9D%BF%E4%BB%A3%E7%A0%81%EF%BC%8C%E5%B0%B1%E6%98%AF%E8%B7%B3%E8%BD%AC%E5%88%B0%E5%AF%B9%E5%BA%94%E7%9A%84.got%E8%A1%A8%E9%A1%B9%E4%B8%AD%E5%86%B3%E5%AE%9A%E6%9C%80%E7%BB%88%E7%9A%84%E6%89%A7%E8%A1%8C%E5%9C%B0%E5%9D%80%E3%80%82%0A%60%60%60x86asm%0A%23%20table%20of%20a%20dynamic%20library%20(.so)%0A%20%20%5B10%5D%20.plt%20%20%20%20%20%20%20%20%20%20%20%20%20%20PROGBITS%20%20%20%20%20%20%20%20%200000000000000610%20%2000000610%0A%20%20%5B11%5D%20.plt.got%20%20%20%20%20%20%20%20%20%20PROGBITS%20%20%20%20%20%20%20%20%200000000000000640%20%2000000640%0A%20%20%5B20%5D%20.got%20%20%20%20%20%20%20%20%20%20%20%20%20%20PROGBITS%20%20%20%20%20%20%20%20%200000000000200fc0%20%2000000fc0%0A%20%20%5B21%5D%20.got.plt%20%20%20%20%20%20%20%20%20%20PROGBITS%20%20%20%20%20%20%20%20%200000000000201000%20%2000001000%0A%60%60%60%0A%0A%23%23%23%23%20.plt%20vs%20.plt.got%0A%E5%85%88%E4%B8%8A2%E4%B8%AA%E4%BE%8B%E5%AD%90%EF%BC%8C%E5%88%86%E5%88%AB%E6%98%AF.plt%E5%92%8C.plt.got%E8%8A%82%E7%9A%84%E3%80%82%E5%8F%AF%E4%BB%A5%E7%9C%8B%E5%87%BA%EF%BC%8C%E8%BF%992%E4%B8%AA%E8%8A%82%E9%83%BD%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5%88%B0%E8%AF%A5%E8%8A%82%E7%9A%84%E8%B7%B3%E8%BD%AC%E6%8C%87%E4%BB%A4%EF%BC%9F%0A%60%60%60armasm%0A%23%20.plt%E8%8A%82%E4%B8%BE%E4%BE%8B%0A00000000000008c0%20%3Cfopen%40plt%3E%3A%0A%208c0%3A%09ff%2025%20ea%2016%2020%2000%20%20%20%20%09jmpq%20%20%20*0x2016ea(%25rip)%20%20%20%20%20%20%20%20%23%20201fb0%20%3Cfopen%40GLIBC_2.2.5%3E%0A%208c6%3A%0968%2009%2000%2000%2000%20%20%20%20%20%20%20%09pushq%20%20%240x9%0A%208cb%3A%09e9%2050%20ff%20ff%20ff%20%20%20%20%20%20%20%09jmpq%20%20%20820%20%3C.plt%3E%0A%0A%0A%23%20.plt.got%E8%8A%82%E4%B8%BE%E4%BE%8B%0A00000000000005d0%20%3Cfopen%40plt%3E%3A%0A%205d0%3A%09ff%2025%2012%200a%2020%2000%20%20%20%20%09jmpq%20%20%20*0x200a12(%25rip)%20%20%20%20%20%20%20%20%23%20200fe8%20%3Cfopen%40GLIBC_2.2.5%3E%0A%205d6%3A%0966%2090%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%09xchg%20%20%20%25ax%2C%25ax%0A%60%60%60%0A%E7%BB%8F%E8%BF%87%E6%88%91%E7%9A%84%E5%AE%9E%E9%AA%8C%E5%8F%91%E7%8E%B0%EF%BC%8C%E5%BD%93%E5%8F%91%E7%94%9F%E7%B1%BB%E4%BC%BC%E8%BF%99%E7%A7%8D%E5%87%BD%E6%95%B0%E6%8C%87%E9%92%88%E8%B5%8B%E5%80%BC%E6%97%B6%EF%BC%8C%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%E5%87%BD%E6%95%B0%E5%B0%B1%E4%BC%9A%E5%87%BA%E7%8E%B0%E5%9C%A8.plt.got%E8%8A%82%EF%BC%8C%E5%90%8C%E6%97%B6.plt%E8%8A%82%E4%B8%AD%E5%B0%B1%E4%B8%8D%E5%86%8D%E5%8C%85%E5%90%AB%E8%BF%99%E4%B8%AA%E5%87%BD%E6%95%B0%E3%80%82%0A%60%60%60c%0AFuncPuts%20old_puts%20%3D%20NULL%3B%0Aold_puts%20%3D%20puts%3B%20%2F%2F%20puts%20as%20a%20function%20pointer%2C%20assigned%20to%20a%20variable%0A%60%60%60%0A%E5%BD%93%E5%87%BD%E6%95%B0%E4%B8%8D%E5%9C%A8.plt%E8%8A%82%E6%97%B6%EF%BC%8C%E5%87%BD%E6%95%B0%E7%9A%84%E8%B7%B3%E8%BD%AC%E5%8F%98%E6%88%90%E9%9D%99%E6%80%81%E7%9A%84%E4%BA%86%E3%80%82%E7%94%A8%60objdump%20-S%60%E5%AF%B9%E7%85%A7%E6%B1%87%E7%BC%96%E5%92%8C%E6%BA%90%E7%A0%81%EF%BC%8C%E5%8F%AF%E4%BB%A5%E5%8F%91%E7%8E%B0%EF%BC%8C%E5%AF%B9%E6%AD%A4%E7%B1%BB%E5%87%BD%E6%95%B0%E7%9A%84%E8%B0%83%E7%94%A8%E5%B0%B1%E6%98%AF%E8%B7%B3%E8%BD%AC%E5%88%B0%E5%AF%B9%E5%BA%94%E7%9A%84.plt.got%E8%A1%A8%E9%A1%B9%E3%80%82%0A%60%60%60x86asm%0Aputs(%22hello%22)%3B%0A%20751%3A%20%20%2048%208d%203d%208c%2000%2000%2000%20%20%20%20lea%20%20%20%200x8c(%25rip)%2C%25rdi%20%20%20%20%20%20%20%20%23%207e4%20%3C_fini%2B0x14%3E%0A%20758%3A%20%20%20e8%20e3%20fe%20ff%20ff%20%20%20%20%20%20%20%20%20%20callq%20%20640%20%3Cputs%40plt%3E%0A%20%0A%20%23%20%E5%AF%B9%E5%BA%94%E7%9A%84.plt.got%E8%A1%A8%E9%A1%B9%0A%200000000000000640%20%3Cputs%40plt%3E%3A%0A%20640%3A%20%20%20ff%2025%2082%2009%2020%2000%20%20%20%20%20%20%20jmpq%20%20%20*0x200982(%25rip)%20%20%20%20%20%20%20%20%23%20200fc8%20%3Cputs%40GLIBC_2.2.5%3E%0A%20646%3A%20%20%2066%2090%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20xchg%20%20%20%25ax%2C%25ax%20%0A%60%60%60%0A%3E%20**%E6%B3%A8**%3A%20%60xchg%20%25ax%2C%20%25ax%60%E6%98%AF%E4%B8%80%E6%9D%A1NOP%E6%8C%87%E4%BB%A4%EF%BC%8C%E5%8F%82%E7%9C%8B%5BWhy%20does%20Visual%20Studio%20use%20xchg%20ax%2Cax%5D(https%3A%2F%2Fstackoverflow.com%2Fquestions%2F2136043%2Fwhy-does-visual-studio-use-xchg-ax-ax)%0A%0A%E5%BD%93%E5%8F%AA%E6%9C%89.plt.got%E5%8C%85%E5%90%AB%E8%AF%A5%E5%87%BD%E6%95%B0%E8%A1%A8%E9%A1%B9%E6%97%B6%EF%BC%8C%E6%88%91%E4%BB%AC%E7%9A%84GOT%E6%9B%BF%E6%8D%A2%E9%AD%94%E6%B3%95%E5%B0%B1%E5%A4%B1%E6%95%88%E4%BA%86%E3%80%82%E6%89%80%E4%BB%A5%E5%A6%82%E6%9E%9C%E6%83%B3%E4%BF%9D%E5%AD%98%E5%8E%9F%E5%87%BD%E6%95%B0%E6%8C%87%E9%92%88%EF%BC%8C%E6%AD%A3%E7%A1%AE%E7%9A%84%E5%81%9A%E6%B3%95%E5%BA%94%E5%BD%93%E6%98%AF%EF%BC%9A%0A%60%60%60c%0A%2F%2F%20Don't%20do%20like%20this.%0A%2F%2F%20It%20will%20kick%20puts%20from%20.plt%20and%20put%20it%20into%20.plt.got.%0A%2F%2F%20We%20might%20not%20be%20able%20to%20substitute%20its%20address%20via%20rel%20tables.%0A%2F%2F%20old_puts%20%3D%20puts%3B%20%0A%0A%2F%2F%20Below%20is%20RECOMMENDED!!!%0Aif%20(old_puts%20%3D%3D%20NULL)%20%7B%20%2F%2F%20save%20original%20libc%20function%20pointer%0A%20%20%20%20old_puts%20%3D%20(FuncPuts)*(uint64_t%20*)(rel_table%5Bi%5D.r_offset%20%2B%20base_addr)%3B%0A%7D%0A*(uint64_t%20*)(rel_table%5Bi%5D.r_offset%20%2B%20base_addr)%20%3D%20(uint64_t)my_puts%3B%0A%60%60%60%0A%0A%23%23%23%23%20.got%20vs%20.got.plt%0A%E6%8C%89%E7%85%A7%E5%89%8D%E6%96%87%E7%9A%84%E8%A7%A3%E9%87%8A%EF%BC%8C.got%E8%8A%82%E5%AD%98%E5%82%A8%E7%9A%84%E6%98%AF%E9%9C%80%E8%A6%81%E5%8A%A8%E6%80%81resolve%E7%9A%84%E5%8F%98%E9%87%8F%EF%BC%88%E5%BA%94%E5%BD%93%E6%98%AF%E5%8A%A8%E6%80%81%E5%BA%93%E4%B8%AD%E5%AE%9A%E4%B9%89%E7%9A%84%E5%85%A8%E5%B1%80%E5%8F%98%E9%87%8F%EF%BC%89%E3%80%82%E8%80%8C.got.plt%E6%98%AF%E5%AF%B9%E5%BA%94.plt%E8%8A%82%E7%9A%84%E5%87%BD%E6%95%B0%E5%9C%B0%E5%9D%80%E8%A1%A8%E9%A1%B9%E3%80%82%0A%E5%AE%9E%E9%99%85%E7%9A%84%E5%AE%9E%E9%AA%8C%E7%BB%93%E6%9E%9C%E6%98%AF%EF%BC%9A%0A-%20%E5%AF%B9%E4%BA%8E%E5%8F%AF%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6%EF%BC%8C.got.plt%E4%B8%8D%E5%AD%98%E5%9C%A8%EF%BC%8C%E8%80%8C.plt%E8%A1%A8%E9%A1%B9%E7%9B%B4%E6%8E%A5%E8%B7%B3%E8%BD%AC%E5%88%B0.got%E8%A1%A8%E9%A1%B9%E6%89%A7%E8%A1%8C%E3%80%82%E5%87%BD%E6%95%B0%E7%9A%84GOT%E8%A1%A8%E4%BD%8D%E7%BD%AE%EF%BC%88_GLOBAL_OFFSET_TABLE_%EF%BC%89%E5%9C%A80x201f50%0A%60%60%60x86asm%0A%3E%20objdump%20-d%20--section%3D.plt%20mytest%20%0A%0Amytest%EF%BC%9A%20%20%20%20%20%E6%96%87%E4%BB%B6%E6%A0%BC%E5%BC%8F%20elf64-x86-64%0A%0ADisassembly%20of%20section%20.plt%3A%0A%0A0000000000000820%20%3C.plt%3E%3A%0A%20820%3A%20%20%20ff%2035%2032%2017%2020%2000%20%20%20%20%20%20%20pushq%20%200x201732(%25rip)%20%20%20%20%20%20%20%20%23%20201f58%20%3C_GLOBAL_OFFSET_TABLE_%2B0x8%3E%0A%20826%3A%20%20%20ff%2025%2034%2017%2020%2000%20%20%20%20%20%20%20jmpq%20%20%20*0x201734(%25rip)%20%20%20%20%20%20%20%20%23%20201f60%20%3C_GLOBAL_OFFSET_TABLE_%2B0x10%3E%0A%2082c%3A%20%20%200f%201f%2040%2000%20%20%20%20%20%20%20%20%20%20%20%20%20nopl%20%20%200x0(%25rax)%0A%20%0A%20%3E%20objdump%20-d%20--section%3D.got%20mytest%20%20%20%20%0A%0Amytest%EF%BC%9A%20%20%20%20%20%E6%96%87%E4%BB%B6%E6%A0%BC%E5%BC%8F%20elf64-x86-64%0A%0ADisassembly%20of%20section%20.got%3A%0A%0A0000000000201f50%20%3C_GLOBAL_OFFSET_TABLE_%3E%3A%0A%20%20201f50%3A%20%20%20%20%20%20%2050%201d%2020%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%0A%20%20%20%20%20%20%20%20...%0A%60%60%60%0A-%20%E5%AF%B9%E4%BA%8E%E4%B8%80%E4%B8%AA%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%E5%BA%93%E6%96%87%E4%BB%B6%EF%BC%8C%E5%88%99%E5%A6%82%E5%89%8D%E6%96%87%E6%89%80%E8%BF%B0%E4%B8%80%E8%87%B4%EF%BC%8C%E5%8D%B3.got%E8%B4%9F%E8%B4%A3%E8%B7%B3%E8%BD%AC%E5%8F%98%E9%87%8F%EF%BC%8C%E8%80%8C.got.plt%E8%B4%9F%E8%B4%A3%E8%B7%B3%E8%BD%AC%E5%87%BD%E6%95%B0%E3%80%82%E5%87%BD%E6%95%B0%E7%9A%84GOT%E8%A1%A8%E4%BD%8D%E7%BD%AE%EF%BC%88_GLOBAL_OFFSET_TABLE_%EF%BC%89%E5%9C%A80x201000%0A%60%60%60x86asm%0A%3E%20objdump%20-d%20--section%3D.plt%20libtest.so%20%20%20%20%0A%0Alibtest.so%EF%BC%9A%20%20%20%20%20%E6%96%87%E4%BB%B6%E6%A0%BC%E5%BC%8F%20elf64-x86-64%0A%0ADisassembly%20of%20section%20.plt%3A%0A%0A0000000000000610%20%3C.plt%3E%3A%0A%20610%3A%20%20%20ff%2035%20f2%2009%2020%2000%20%20%20%20%20%20%20pushq%20%200x2009f2(%25rip)%20%20%20%20%20%20%20%20%23%20201008%20%3C_GLOBAL_OFFSET_TABLE_%2B0x8%3E%0A%20616%3A%20%20%20ff%2025%20f4%2009%2020%2000%20%20%20%20%20%20%20jmpq%20%20%20*0x2009f4(%25rip)%20%20%20%20%20%20%20%20%23%20201010%20%3C_GLOBAL_OFFSET_TABLE_%2B0x10%3E%0A%2061c%3A%20%20%200f%201f%2040%2000%20%20%20%20%20%20%20%20%20%20%20%20%20nopl%20%20%200x0(%25rax)%0A%0A%3E%20objdump%20-d%20--section%3D.got.plt%20libtest.so%20%20%20%20%0A%0Alibtest.so%EF%BC%9A%20%20%20%20%20%E6%96%87%E4%BB%B6%E6%A0%BC%E5%BC%8F%20elf64-x86-64%0A%0ADisassembly%20of%20section%20.got.plt%3A%0A%0A0000000000201000%20%3C_GLOBAL_OFFSET_TABLE_%3E%3A%0A%20%20201000%3A%20%20%20%20%20%20%2000%200e%2020%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%20%0A%20%20%20%20%20%20%20%20...%0A%60%60%60%0A%E4%BD%86%E5%85%B6%E5%AE%9E%EF%BC%8C%E6%88%91%E4%BB%AC%E9%9C%80%E8%A6%81%E5%85%B3%E6%B3%A8%E7%9A%84%E6%98%AF%E9%87%8D%E5%AE%9A%E5%90%91%E7%9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%95%E5%A4%84%E7%9A%84%E5%86%85%E5%AD%98%E3%80%82%E6%B5%81%E7%A8%8B%E5%A4%A7%E8%87%B4%E5%A6%82%E4%B8%8B%EF%BC%9A%0A%60%60%60mermaid%0Agraph%20TD%0AA%5B%22get%20module%20base%20from%20%2Fproc%2F%3Cpid%3E%2Fmaps%20file%22%5D%20--%3E%20B%5B%22Program%20table%20is%20at%20the%20beginning%22%5D%0AB%20--%3E%20C%5B%22Find%20.dynamic%20section%20in%20PHT%20by%20PT_DYNAMIC%22%5D%0AC%20--%3E%20D%5B%22Get%20.strtab%20by%20DT_STRTAB%22%5D%0AC%20--%3E%20E%5B%22Get%20.symtab%20by%20DT_SYMTAB%22%5D%0AC%20--%3E%20F%5B%22Get%20.rel(a).plt%20by%20DT_JMPREL%22%5D%0AC%20--%3E%20G%5B%22Get%20.rel(a).plt%20size%20by%20DT_PLTRELSZ%22%5D%0AF%20--%3E%20I%5B%22Loop%20in%20.rel(a).plt%22%5D%0AD%20--%3E%20I%0AE%20--%3E%20I%0AG%20--%3E%20I%0AI%20--%3E%20%7Cthe%20ith%20entry%7C%20J%5BGet%20symbol%20entry%20in%20.symtab%5D%0A%0AJ%20--%3E%20%7Cname%20index%20in%20symbol%20entry%7C%20H%7BName%20in%20.strtab%20matched%20%3F%7D%0AH%20--%3E%20%7CY%7C%20K%5BUpdate%20table%20item%5D%0AK%20--%3E%20L((End))%0AH%20--%3E%20%7CN%7CI%0A%60%60%60%0A%E6%88%91%E7%9A%84%E5%9F%BA%E7%A1%80%E4%BB%A3%E7%A0%81%E6%9D%A5%E8%87%AA%E4%BA%8E%5B1%5D%EF%BC%8C%E6%80%BB%E7%9A%84%E9%A1%B9%E7%9B%AE%E5%90%8E%E9%9D%A2%E6%88%91%E4%BC%9A%E6%9B%B4%E6%96%B0%E5%88%B0%5Bzhougy0717%2Finject_got%5D(https%3A%2F%2Fgithub.com%2Fzhougy0717%2Finject_got)%E4%BB%93%E5%BA%93%E4%B8%AD%E3%80%82%0A%23%23%23%23%20Get%20module%20base%0A%E8%BF%99%E9%87%8C%E8%A6%81%E5%81%9A%E7%9A%84%E5%85%B6%E5%AE%9E%E5%B0%B1%E6%98%AF%E8%8E%B7%E5%8F%96%E5%AF%B9%E5%BA%94%E7%9A%84image%E5%9C%A8%E8%99%9A%E6%8B%9F%E5%86%85%E5%AD%98%E4%B8%AD%E7%9A%84%E4%BD%8D%E7%BD%AE%E3%80%82%E4%BE%8B%E5%A6%82%EF%BC%9A%0A%E5%8F%AF%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6%0A!%5Be31d1d9013e9146aa111206290984949.png%5D(evernotecid%3A%2F%2F22617523-9521-4D00-B771-5F27B85F00EB%2Fappyinxiangcom%2F161681%2FENResource%2Fp6390)%0Alibc%E5%8A%A8%E6%80%81%E5%BA%93%0A!%5B6d153497c7a859245a4976e8f451a815.png%5D(evernotecid%3A%2F%2F22617523-9521-4D00-B771-5F27B85F00EB%2Fappyinxiangcom%2F161681%2FENResource%2Fp6388)%0A%E6%A0%B9%E6%8D%AE%E5%89%8D%E6%96%87%E7%9A%84%E8%A7%A3%E9%87%8A%EF%BC%8C%E8%BF%99%E9%87%8C%E4%B8%8D%E5%90%8C%E7%9A%84%E9%A1%B9%E7%9B%AE%E8%A1%A8%E7%A4%BA%E7%9A%84%E6%98%AF%E4%B8%8D%E5%90%8C%E7%9A%84%E6%AE%B5%E3%80%82%E8%80%8C%E6%A0%B9%E6%8D%AE%E6%88%91%E7%9A%84%E5%AE%9E%E9%AA%8C%E7%BB%93%E6%9E%9C%EF%BC%8C%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%8C%B9%E9%85%8D%E9%A1%B9%E5%B0%B1%E6%98%AF%E6%88%91%E4%BB%AC%E8%A6%81%E6%89%BE%E7%9A%84%E5%86%85%E5%AD%98%E5%9C%B0%E5%9D%80%E3%80%82%E8%80%8C%E8%A7%A3%E6%9E%90%E8%BF%99%E4%B8%AA%E5%86%85%E5%AD%98%E5%9C%B0%E5%9D%80%EF%BC%8C%E5%B0%B1%E6%98%AF%E5%81%9A%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%8C%B9%E9%85%8D%EF%BC%8C%E4%BB%A3%E7%A0%81%E5%A6%82%E4%B8%8B%EF%BC%9A%0A%60%60%60c%0A%20%20%20%20%2F%2F%20%E6%89%93%E5%BC%80%E6%96%87%E4%BB%B6%2Fproc%2Fpid%2Fmaps%EF%BC%8C%E8%8E%B7%E5%8F%96%E6%8C%87%E5%AE%9Apid%E8%BF%9B%E7%A8%8B%E5%8A%A0%E8%BD%BD%E7%9A%84%E5%86%85%E5%AD%98%E6%A8%A1%E5%9D%97%E4%BF%A1%E6%81%AF%0A%20%20%20%20fp%20%3D%20fopen(filename%2C%20%22r%22)%3B%0A%20%20%20%20if(fp%20!%3D%20NULL)%7B%0A%20%20%20%20%20%20%20%20%2F%2F%20%E6%AF%8F%E6%AC%A1%E4%B8%80%E8%A1%8C%EF%BC%8C%E8%AF%BB%E5%8F%96%E6%96%87%E4%BB%B6%20%2Fproc%2Fpid%2Fmaps%E4%B8%AD%E5%86%85%E5%AE%B9%0A%20%20%20%20%20%20%20%20while(fgets(line%2C%20sizeof(line)%2C%20fp))%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20%E6%9F%A5%E6%89%BE%E6%8C%87%E5%AE%9A%E7%9A%84so%E6%A8%A1%E5%9D%97%0A%20%20%20%20%20%20%20%20%20%20%20%20if(strstr(line%2C%20module_name))%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20%E5%88%86%E5%89%B2%E5%AD%97%E7%AC%A6%E4%B8%B2%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20pch%20%3D%20strtok(line%2C%20%22-%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BD%AC%E9%95%BF%E6%95%B4%E5%BD%A2%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20addr%20%3D%20strtoul(pch%2C%20NULL%2C%2016)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20break%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20fclose(fp)%3B%0A%20%20%20%20return%20(void*)addr%3B%0A%60%60%60%0A%23%23%23%23%20.rel.plt%E8%BF%98%E6%98%AF.rela.plt%0Arel%E5%92%8Crela%E6%98%AF%E4%B8%A4%E7%A7%8Drelocation%20type%E3%80%82%E6%98%AFrel%E8%BF%98%E6%98%AFrela%E4%BC%9A%E5%BD%B1%E5%93%8D%E5%88%B0%E5%90%8E%E7%BB%AD%E9%80%89%E6%8B%A9%E7%9A%84%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E7%B1%BB%E5%9E%8B%E3%80%82%E5%88%B0%E5%BA%95%E8%AF%A5%E7%94%A8rel%E8%BF%98%E6%98%AFrela%EF%BC%8C%E6%98%AF%E5%8F%96%E5%86%B3%E4%BA%8Eprocessor%20type%E7%9A%84%E3%80%82%E8%80%8Cx86_64%E9%83%BD%E6%98%AFrela%E7%B1%BB%E5%9E%8B%E7%9A%84%EF%BC%8Ci386%E5%92%8Carm32%E9%83%BD%E6%98%AFrel%E7%B1%BB%E5%9E%8B%E7%9A%84%E3%80%82%E9%99%A4%E4%BA%86%E9%80%9A%E8%BF%87Google%E6%9D%A5%E5%BE%97%E5%88%B0rel%20type%EF%BC%8C%E8%BF%98%E6%9C%89%E6%9B%B4%E9%9D%A0%E8%B0%B1%E7%9A%84%E6%96%B9%E6%B3%95%E6%98%AF%EF%BC%8C%E6%A3%80%E6%9F%A5.dynamic%20section%E7%9A%84DT_PLTREL%E5%AD%97%E6%AE%B5%E3%80%82%0A%60%60%60c%0A%20%20%20%20for(i%3D0%3Bi%20%3C%20dynamicSize%20%2F%20sizeof(Elf64_Dyn)%3Bi%20%2B%2B)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20uint64_t%20val%20%3D%20dynamic_table%5Bi%5D.d_un.d_val%3B%0A%20%20%20%20%20%20%20%20if%20(dynamic_table%5Bi%5D.d_tag%20%3D%3D%20DT_PLTREL)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20DT_RELA%20%3D%207%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20DT_REL%20%3D%2017%0A%20%20%20%20%20%20%20%20%20%20%20%20relType%20%3D%20dynamic_table%5Bi%5D.d_un.d_val%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%60%60%60%0A%23%23%23%23%20%E4%BB%8E.rel(a).plt%20index%E5%88%B0.strtab%20index%0A%E8%BF%99%E4%B8%80%E6%AE%B5%E4%BB%A3%E7%A0%81%E8%A6%81%E5%81%9A%E7%9A%84%E5%B0%B1%E6%98%AF%E6%89%BE%E5%88%B0.rel(a).plt%E8%A1%A8%E9%A1%B9%E6%89%80%E4%BB%A3%E8%A1%A8%E7%9A%84%E5%87%BD%E6%95%B0%E7%9A%84%E5%90%8D%E5%AD%97%E3%80%82%E8%BF%99%E4%B8%AA%E5%87%BD%E6%95%B0%E7%9A%84%E5%90%8D%E5%AD%97%E6%98%AF%E5%AD%98%E5%82%A8%E5%9C%A8.strtab%E8%8A%82%E7%9A%84%E3%80%82%E4%BB%A3%E7%A0%81%E5%A4%A7%E8%87%B4%E5%A6%82%E4%B8%8B%EF%BC%9A%0A%60%60%60c%0A%20%20%20%20%2F%2F%20%E8%8E%B7%E5%8F%96.rel(a).plt%2C%20.symtab%2C%20.strtab%E5%9C%B0%E5%9D%80%0A%20%20%20%20for(i%3D0%3Bi%20%3C%20dynamicSize%20%2F%20sizeof(Elf64_Dyn)%3Bi%20%2B%2B)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20uint64_t%20val%20%3D%20dynamic_table%5Bi%5D.d_un.d_val%3B%0A%20%20%20%20%20%20%20%20if%20(dynamic_table%5Bi%5D.d_tag%20%3D%3D%20DT_JMPREL)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20jmpRelOff%20%3D%20dynamic_table%5Bi%5D.d_un.d_ptr%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20if%20(dynamic_table%5Bi%5D.d_tag%20%3D%3D%20DT_STRTAB)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20strTabOff%20%3D%20dynamic_table%5Bi%5D.d_un.d_ptr%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20if%20(dynamic_table%5Bi%5D.d_tag%20%3D%3D%20DT_PLTRELSZ)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20pltRelSz%20%3D%20dynamic_table%5Bi%5D.d_un.d_val%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20if%20(dynamic_table%5Bi%5D.d_tag%20%3D%3D%20DT_SYMTAB)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20symTabOff%20%3D%20dynamic_table%5Bi%5D.d_un.d_ptr%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20%0A%20%20%20%20Elf64_Rela*%20rel_table%20%3D%20(Elf64_Rela*)jmpRelOff%3B%0A%20%20%20%20%2F%2F%20%E9%81%8D%E5%8E%86%E6%9F%A5%E6%89%BE%E8%A6%81hook%E7%9A%84%E5%AF%BC%E5%85%A5%E5%87%BD%E6%95%B0%0A%20%20%20%20%2F%2F%20i%20%3D%3D%3E%20.rela.plt%20item%20index%0A%20%20%20%20for(i%20%3D%200%3Bi%20%3C%20pltRelSz%20%2F%20sizeof(Elf64_Rela)%3Bi%2B%2B)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20int%20number%20%3D%20ELF64_R_SYM(rel_table%5Bi%5D.r_info)%3B%20%2F%2F%20.symtab%20index%0A%20%20%20%20%20%20%20%20Elf64_Sym*%20symEnt%20%3D%20(Elf64_Sym*)(number*sizeof(Elf64_Sym)%20%2B%20symTabOff)%3B%0A%20%20%20%20%20%20%20%20char*%20funcName%20%3D%20(char*)(symEnt-%3Est_name%20%2B%20strTabOff)%3B%0A%20%20%20%20%20%20%20%20if(strcmp(funcName%2C%20%22puts%22)%20%3D%3D%200)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E5%86%85%E5%AD%98%E5%88%86%E9%A1%B5%E7%9A%84%E5%A4%A7%E5%B0%8F%0A%20%20%20%20%20%20%20%20%20%20%20%20uint64_t%20page_size%20%3D%20getpagesize()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20%E8%8E%B7%E5%8F%96%E5%86%85%E5%AD%98%E5%88%86%E9%A1%B5%E7%9A%84%E8%B5%B7%E5%A7%8B%E5%9C%B0%E5%9D%80%EF%BC%88%E9%9C%80%E8%A6%81%E5%86%85%E5%AD%98%E5%AF%B9%E9%BD%90%EF%BC%89%0A%20%20%20%20%20%20%20%20%20%20%20%20uint64_t%20mem_page_start%20%3D%20(uint64_t)(((Elf64_Addr)rel_table%5Bi%5D.r_offset%20%2B%20(uint64_t)base_addr))%20%26%20(~(page_size%20-%201))%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20mprotect((void%20*)mem_page_start%2C%20page_size%2C%20PROT_READ%20%7C%20PROT_WRITE%20%7C%20PROT_EXEC)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20*(uint64_t%20*)(rel_table%5Bi%5D.r_offset%20%2B%20base_addr)%20%3D%20(uint64_t)my_puts%3B%20%2F%2F%20overwrite%20GOT%20item%0A%20%20%20%20%20%20%20%20%20%20%20%20break%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%60%60%60%0A%E4%B8%8B%E5%9B%BE%E5%B0%B1%E6%98%AF%E4%B8%8A%E9%9D%A2%E8%BF%99%E6%AE%B5%E4%BB%A3%E7%A0%81%E7%9A%84%E7%A4%BA%E6%84%8F%E5%9B%BE%E3%80%82%0A!%5B8a9964ab6563f1cffe61dabed1422c42.png%5D(evernotecid%3A%2F%2F22617523-9521-4D00-B771-5F27B85F00EB%2Fappyinxiangcom%2F161681%2FENResource%2Fp6392)%0A%E8%BF%99%E9%87%8C%E5%80%BC%E5%BE%97%E6%B3%A8%E6%84%8F%E7%9A%84%E6%98%AF%EF%BC%9A%0A-%20%E5%9C%A8%E8%A7%A3%E6%9E%90.dynamic%E8%8A%82%EF%BC%8C%E8%8E%B7%E5%8F%96.rel(a).plt%2C%20.symtab%2C%20.strtab%E4%BF%A1%E6%81%AF%E6%97%B6%EF%BC%8C%E8%A6%81%E6%B3%A8%E6%84%8F%E7%9A%84%E6%98%AFElf64_Dyn%E7%9A%84%E5%AE%9A%E4%B9%89%EF%BC%8C%E5%AE%83%E6%98%AF%E4%B8%80%E4%B8%AAunion%E7%BB%93%E6%9E%84%EF%BC%8C%E6%98%AF%E5%8C%BA%E5%88%86%E5%80%BC%E7%B1%BB%E5%9E%8B%E5%92%8C%E6%8C%87%E9%92%88%E7%B1%BB%E5%9E%8B%E7%9A%84%EF%BC%8C%E5%85%B6%E5%AE%9A%E4%B9%89%E5%A6%82%E4%B8%8B%EF%BC%9A%0A%60%60%60c%0Atypedef%20struct%20%7B%0A%20%20%20%20%20%20%20%20Elf64_Xword%20d_tag%3B%0A%20%20%20%20%20%20%20%20union%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Elf64_Xword%20%20%20%20%20d_val%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Elf64_Addr%20%20%20%20%20%20d_ptr%3B%0A%20%20%20%20%20%20%20%20%7D%20d_un%3B%0A%7D%20Elf64_Dyn%3B%0A%60%60%60%0A%E5%9C%A8%E8%8E%B7%E5%8F%96%E5%86%85%E5%AD%98%E5%9C%B0%E5%9D%80%E7%9A%84%E6%97%B6%E5%80%99%E8%A6%81%E7%94%A8d_ptr%2C%E8%80%8C%E5%9C%A8%E8%8E%B7%E5%8F%96%E4%BE%8B%E5%A6%82DT_PLTRELSZ%E6%97%B6%EF%BC%8C%E5%B0%B1%E6%98%BE%E7%84%B6%E6%98%AF%E4%B8%80%E4%B8%AA%E5%80%BC%E7%B1%BB%E5%9E%8B%E3%80%82%0A-%20%E5%89%8D%E9%9D%A2%E8%AF%B4%E7%9A%84relocation%20type%E5%9C%A8%E8%BF%99%E9%87%8C%E5%B0%B1%E4%BC%9A%E5%8F%91%E6%8C%A5%E4%BD%9C%E7%94%A8%E3%80%82.rel(a).plt%E8%A1%A8%E9%A1%B9%E5%9C%A8%E4%B8%8D%E5%90%8C%E7%9A%84relocation%20type%E7%9A%84%E6%83%85%E5%86%B5%E4%B8%8B%EF%BC%8C%E5%85%B6%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E6%98%AF%E4%B8%8D%E5%90%8C%E7%9A%84%E3%80%82%E4%BB%96%E4%BB%AC%E7%9A%84%E7%BB%93%E6%9E%84%E5%92%8C%E5%B0%BA%E5%AF%B8%E9%83%BD%E6%98%AF%E4%B8%8D%E5%90%8C%E7%9A%84%E3%80%82%0A%20%20%20%20-%20rel%E6%98%AFElf64_Rel%0A%20%20%20%20-%20rela%E6%98%AFElf64_Rela%0A-%20DT_SYMTAB%E6%98%AF.symtab%E8%8A%82%EF%BC%8C%E6%AF%8F%E4%B8%80%E4%B8%AAsymbol%E6%98%AF%E4%B8%80%E4%B8%AAElf64_Sym%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%0A-%20.strtab%E6%98%AF%E6%89%80%E6%9C%89%E7%AC%A6%E5%8F%B7%E7%9A%84%E5%90%8D%E5%AD%97%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%A1%A8%E6%A0%BC%E3%80%82%E8%80%8CElf64_Sym.st_name%E6%98%AF%E8%A1%A8%E6%A0%BC%E7%9A%84%E5%81%8F%E7%A7%BB%E5%9C%B0%E5%9D%80%E3%80%82%E6%B3%A8%E6%84%8F%EF%BC%8C%E4%B8%8D%E6%98%AF%E8%A1%A8%E6%A0%BC%E7%B4%A2%E5%BC%95%E3%80%82%E6%89%80%E4%BB%A5%E8%8E%B7%E5%8F%96%E5%90%8D%E5%AD%97%E7%9A%84%E6%96%B9%E6%B3%95%E6%98%AF%60symEnt-%3Est_name%20%2B%20strTabOff%60%E3%80%82%0A-%20%E6%9C%80%E5%90%8E%EF%BC%8C%E4%BF%AE%E6%94%B9%E5%AF%B9%E5%BA%94%E7%9A%84%E9%A1%B5%E8%A1%A8%E5%B1%9E%E6%80%A7%EF%BC%8C%E7%84%B6%E5%90%8E%E4%BF%AE%E6%94%B9%E5%AF%B9%E5%BA%94%E7%9A%84%E5%86%85%E5%AD%98%E5%9C%B0%E5%9D%80%E5%B0%B1%E5%8F%AF%E4%BB%A5%E6%B0%B4%E5%88%B0%E6%B8%A0%E6%88%90%E4%BA%86%0A%0A%23%23%20%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE%0A%5B1%5D%20%5BAndroid%20so%E6%B3%A8%E5%85%A5(inject)%E5%92%8CHook%E6%8A%80%E6%9C%AF%E5%AD%A6%E4%B9%A0%EF%BC%88%E4%BA%8C%EF%BC%89%E2%80%94%E2%80%94Got%E8%A1%A8hook%E4%B9%8B%E5%AF%BC%E5%85%A5%E8%A1%A8hook%5D(https%3A%2F%2Fwww.cnblogs.com%2Fgoodhacker%2Fp%2F9306997.html)%0A%5B2%5D%20%5BExecutable%20and%20Linkable%20Format%5D(https%3A%2F%2Fstevens.netmeister.org%2F631%2Felf.html)%0A%5B3%5D%20%5BOracle%20Documentation%5D(https%3A%2F%2Fdocs.oracle.com%2Fcd%2FE19683-01%2F817-3677%2F6mj8mbtc9%2Findex.html%23chapter6-79797)%0A%5B4%5D%20%5BExecutable%20and%20Linking%20Format%20Specification%2C%20Version%201.2%5D(https%3A%2F%2Frefspecs.linuxbase.org%2Felf%2Felf.pdf)%0A