HackMD
  • API
    API  HackMD API beta testing
    HackMD API is now in beta, join us for a test drive.
    Getting started Got it
      • Create new note
      • Create a note from template
    • API  HackMD API beta testing
      API  HackMD API beta testing
      HackMD API is now in beta, join us for a test drive.
      Getting started Got it
      • Options
      • Versions and GitHub Sync
      • Transfer ownership
      • Delete this note
      • Template
      • Save as template
      • Insert from template
      • Export
      • Dropbox
      • Google Drive
      • Gist
      • Import
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
      • Download
      • Markdown
      • HTML
      • Raw HTML
      • ODF (Beta)
      • Sharing Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • More (Comment, Invitee)
      • Publishing
        Everyone on the web can find and read all notes of this public team.
        After the note is published, everyone on the web can find and read this note.
        See all published notes on profile page.
      • Commenting Enable
        Disabled Forbidden Owners Signed-in users Everyone
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Invitee
      • No invitee
    Menu Sharing Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Versions and GitHub Sync Transfer ownership Delete this note
    Export
    Dropbox Google Drive Gist
    Import
    Dropbox Google Drive Gist Clipboard
    Download
    Markdown HTML Raw HTML ODF (Beta)
    Back
    Sharing
    Sharing Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Note Permission
    Read
    Owners
    • Owners
    • Signed-in users
    • Everyone
    Owners Signed-in users Everyone
    Write
    Owners
    • Owners
    • Signed-in users
    • Everyone
    Owners Signed-in users Everyone
    More (Comment, Invitee)
    Publishing
    Everyone on the web can find and read all notes of this public team.
    After the note is published, everyone on the web can find and read this note.
    See all published notes on profile page.
    More (Comment, Invitee)
    Commenting Enable
    Disabled Forbidden Owners Signed-in users Everyone
    Permission
    Owners
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Invitee
    No invitee
       owned this note    owned this note      
    Published Linked with GitHub
    Like BookmarkBookmarked
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    Linux kernel 中的檔案權限設計 === from: http://lwn.net/Articles/696227/ 在 8/2 號的時候,Baole Ni 為了把 kernel 中有關 file permission 的 code 從八進位修改成 macro 的樣式,送了高達 1285 個 patch。David Miller 直接說這是「[patch 史上最糟的一個 submmit](http://lwn.net/Articles/696228/)」。更猛的是,他的 patch 信還送給了不只一位的 developer... 會有這樣的改動是因為,kernel 中有關權限的部份,其實已經在 `linux/stat.h` 已經有 macro 可以使用,像是 `S_IRWXUGO` 或是 `S_IRUGO` 這種表示方式,但大多數在 kernel code 的實作,還是使用 `0444` 這樣的八進位表示方式。 一場大戰就此開打,首先大家在看到這個 patch 之後,先不論他直接送上 1285 個 patch 這樣的神績,Steven Rostedt 在 patch mail 就回應: >I find 0444 more readable than S_IRUSR | S_IRGRP | S_IROTH. 大家發現,轉換成 macro 的方式沒有比較好閱讀啊!而且還要在 1285 個地方看到 `S_IRUSR | S_IRGRP` 這樣的表示方式,崩潰啦。 最後是 Linus [發出正式的公告](http://lwn.net/Articles/696229/),說這種 symbolic name 用在 sticky bit 或是 inode mode _type_ number 上還不錯,但是對於 permission bits,糟,糟糕透頂,沒有人應該在 kernel 或是 user space 中使用他們。 還沒結束,八進位表示也是個很糟的方式,[Al Viro](http://lwn.net/Articles/696230/) 指出,這種表示方式還是有可能造成難以發現的錯誤 (lovely potential for typos)。 真正的問題是,POSIX 定義的這些 `S_* macros` 就是難以閱讀,讓開發者難以使用。最後由 Ingo Molnar [提出一個新的變通方法](http://lwn.net/Articles/696231/),用一套新的 macro 來表示 permission bits. ```clike= #define PERM_rw_______ 0600 #define PERM_rw_r_____ 0640 #define PERM_rw_r__r__ 0644 #define PERM_rw_rw_r__ 0664 #define PERM_rw_rw_rw_ 0666 ``` Ingo 在信裡面給出一個例子,可以看出用八進位表示的時候,你很難去 code review 找出問題。你能在這個 code 看到兩個資安漏洞嗎? ```clike= + __ATTR(l1, 0444, driver_show_l4, NULL); + __ATTR(l3, 0446, driver_show_l4, NULL); + __ATTR(l2, 04444, driver_show_l4, NULL); + __ATTR(l4, 0444, driver_show_l4, NULL); ``` 轉換成新的方式,可以看到 `PERM_r__r__rw_` 跟 `PERM_sr__r__r__` 這兩個部份是很危險的。 ```clike= + __ATTR(l1, PERM_r__r__r__, driver_show_l4, NULL); + __ATTR(l3, PERM_r__r__rw_, driver_show_l4, NULL); + __ATTR(l2, PERM_sr__r__r__, driver_show_l4, NULL); + __ATTR(l4, PERM_r__r__r__, driver_show_l4, NULL); ``` ---- Comments === Q1. `epa:`為什麼不用 `const int` 而要用 `#define`?

    Import from clipboard

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lost their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template is not available.


    Upgrade

    All
    • All
    • Team
    No template found.

    Create custom template


    Upgrade

    Delete template

    Do you really want to delete this template?

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in via Google

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Tutorials

    Book Mode Tutorial

    Slide Mode Tutorial

    YAML Metadata

    Contacts

    Facebook

    Twitter

    Feedback

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions

    Versions and GitHub Sync

    Sign in to link this note to GitHub Learn more
    This note is not linked with GitHub Learn more
     
    Add badge Pull Push GitHub Link Settings
    Upgrade now

    Version named by    

    More Less
    • Edit
    • Delete

    Note content is identical to the latest version.
    Compare with
      Choose a version
      No search result
      Version not found

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub

        Please sign in to GitHub and install the HackMD app on your GitHub repo. Learn more

         Sign in to GitHub

        HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Available push count

        Upgrade

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Upgrade

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully