rustix-linux-procfs-0.1.1/.cargo_vcs_info.json0000644000000001360000000000100150200ustar { "git": { "sha1": "84fe5f37e43bab027e1bd9f80460cf7a862a82e1" }, "path_in_vcs": "" }rustix-linux-procfs-0.1.1/CODE_OF_CONDUCT.md000064400000000000000000000066611046102023000164200ustar 00000000000000# Contributor Covenant Code of Conduct *Note*: this Code of Conduct pertains to individuals' behavior. Please also see the [Organizational Code of Conduct][OCoC]. ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the Bytecode Alliance CoC team at [report@bytecodealliance.org](mailto:report@bytecodealliance.org). The CoC team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The CoC team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the Bytecode Alliance's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] [OCoC]: https://github.com/sunfishcode/rustix-linux-procfs/blob/main/ORG_CODE_OF_CONDUCT.md [homepage]: https://www.contributor-covenant.org [version]: https://www.contributor-covenant.org/version/1/4/ rustix-linux-procfs-0.1.1/COPYRIGHT000064400000000000000000000016111046102023000151020ustar 00000000000000Short version for non-lawyers: `rustix-linux-procfs` is triple-licensed under Apache 2.0 with the LLVM Exception, Apache 2.0, and MIT terms. Longer version: Copyrights in the `rustix-linux-procfs` project are retained by their contributors. No copyright assignment is required to contribute to the `rustix-linux-procfs` project. Some files include code derived from Rust's `libstd`; see the comments in the code for details. Except as otherwise noted (below and/or in individual files), `rustix-linux-procfs` is licensed under: - the Apache License, Version 2.0, with the LLVM Exception or - the Apache License, Version 2.0 or , - or the MIT license or , at your option. rustix-linux-procfs-0.1.1/Cargo.lock0000644000000072750000000000100130060ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "bitflags" version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" [[package]] name = "errno" version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e" dependencies = [ "libc", "windows-sys", ] [[package]] name = "libc" version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" [[package]] name = "linux-raw-sys" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" [[package]] name = "once_cell" version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "rustix" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d97817398dd4bb2e6da002002db259209759911da105da92bec29ccb12cf58bf" dependencies = [ "bitflags", "errno", "libc", "linux-raw-sys", "windows-sys", ] [[package]] name = "rustix-linux-procfs" version = "0.1.1" dependencies = [ "once_cell", "rustix", ] [[package]] name = "windows-sys" version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_gnullvm", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" rustix-linux-procfs-0.1.1/Cargo.toml0000644000000027370000000000100130270ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" rust-version = "1.63" name = "rustix-linux-procfs" version = "0.1.1" authors = ["Dan Gohman "] build = false include = [ "src", "Cargo.toml", "COPYRIGHT", "LICENSE*", "/*.md", ] autolib = false autobins = false autoexamples = false autotests = false autobenches = false description = "Utilities for opening Linux procfs files and directories" documentation = "https://docs.rs/rustix-linux-procfs" readme = "README.md" keywords = [ "linux", "procfs", ] categories = ["os::unix-apis"] license = "Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT" repository = "https://github.com/sunfishcode/rustix-linux-procfs" [features] default = ["std"] std = ["rustix/std"] [lib] name = "rustix_linux_procfs" path = "src/lib.rs" [dependencies.once_cell] version = "1.5.2" [dependencies.rustix] version = "1.0.0" features = [ "alloc", "fs", ] default-features = false [dev-dependencies.rustix] version = "1.0.0" features = ["std"] default-features = false rustix-linux-procfs-0.1.1/Cargo.toml.orig000064400000000000000000000014471046102023000165050ustar 00000000000000[package] name = "rustix-linux-procfs" version = "0.1.1" authors = [ "Dan Gohman ", ] description = "Utilities for opening Linux procfs files and directories" documentation = "https://docs.rs/rustix-linux-procfs" license = "Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT" repository = "https://github.com/sunfishcode/rustix-linux-procfs" edition = "2021" keywords = ["linux", "procfs"] categories = ["os::unix-apis"] include = ["src", "Cargo.toml", "COPYRIGHT", "LICENSE*", "/*.md"] rust-version = "1.63" [dependencies] rustix = { version = "1.0.0", default-features = false, features = ["alloc", "fs"] } once_cell = "1.5.2" [features] default = ["std"] std = ["rustix/std"] [dev-dependencies] rustix = { version = "1.0.0", default-features = false, features = ["std"] } rustix-linux-procfs-0.1.1/LICENSE-APACHE000064400000000000000000000251371046102023000155440ustar 00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. rustix-linux-procfs-0.1.1/LICENSE-Apache-2.0_WITH_LLVM-exception000064400000000000000000000277231046102023000217650ustar 00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --- LLVM Exceptions to the Apache 2.0 License ---- As an exception, if, as a result of your compiling your source code, portions of this Software are embedded into an Object form of such source code, you may redistribute such embedded portions in such Object form without complying with the conditions of Sections 4(a), 4(b) and 4(d) of the License. In addition, if you combine or link compiled forms of this Software with software that is licensed under the GPLv2 ("Combined Software") and if a court of competent jurisdiction determines that the patent provision (Section 3), the indemnity provision (Section 9) or other Section of the License conflicts with the conditions of the GPLv2, you may retroactively and prospectively choose to deem waived or otherwise exclude such Section(s) of the License, but only in their entirety and only with respect to the Combined Software. rustix-linux-procfs-0.1.1/LICENSE-MIT000064400000000000000000000017771046102023000152600ustar 00000000000000Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. rustix-linux-procfs-0.1.1/ORG_CODE_OF_CONDUCT.md000064400000000000000000000160721046102023000171240ustar 00000000000000# Bytecode Alliance Organizational Code of Conduct (OCoC) *Note*: this Code of Conduct pertains to organizations' behavior. Please also see the [Individual Code of Conduct](CODE_OF_CONDUCT.md). ## Preamble The Bytecode Alliance (BA) welcomes involvement from organizations, including commercial organizations. This document is an *organizational* code of conduct, intended particularly to provide guidance to commercial organizations. It is distinct from the [Individual Code of Conduct (ICoC)](CODE_OF_CONDUCT.md), and does not replace the ICoC. This OCoC applies to any group of people acting in concert as a BA member or as a participant in BA activities, whether or not that group is formally incorporated in some jurisdiction. The code of conduct described below is not a set of rigid rules, and we did not write it to encompass every conceivable scenario that might arise. For example, it is theoretically possible there would be times when asserting patents is in the best interest of the BA community as a whole. In such instances, consult with the BA, strive for consensus, and interpret these rules with an intent that is generous to the community the BA serves. While we may revise these guidelines from time to time based on real-world experience, overall they are based on a simple principle: *Bytecode Alliance members should observe the distinction between public community functions and private functions — especially commercial ones — and should ensure that the latter support, or at least do not harm, the former.* ## Guidelines * **Do not cause confusion about Wasm standards or interoperability.** Having an interoperable WebAssembly core is a high priority for the BA, and members should strive to preserve that core. It is fine to develop additional non-standard features or APIs, but they should always be clearly distinguished from the core interoperable Wasm. Treat the WebAssembly name and any BA-associated names with respect, and follow BA trademark and branding guidelines. If you distribute a customized version of software originally produced by the BA, or if you build a product or service using BA-derived software, use names that clearly distinguish your work from the original. (You should still provide proper attribution to the original, of course, wherever such attribution would normally be given.) Further, do not use the WebAssembly name or BA-associated names in other public namespaces in ways that could cause confusion, e.g., in company names, names of commercial service offerings, domain names, publicly-visible social media accounts or online service accounts, etc. It may sometimes be reasonable, however, to register such a name in a new namespace and then immediately donate control of that account to the BA, because that would help the project maintain its identity. For further guidance, see the BA Trademark and Branding Policy [TODO: create policy, then insert link]. * **Do not restrict contributors.** If your company requires employees or contractors to sign non-compete agreements, those agreements must not prevent people from participating in the BA or contributing to related projects. This does not mean that all non-compete agreements are incompatible with this code of conduct. For example, a company may restrict an employee's ability to solicit the company's customers. However, an agreement must not block any form of technical or social participation in BA activities, including but not limited to the implementation of particular features. The accumulation of experience and expertise in individual persons, who are ultimately free to direct their energy and attention as they decide, is one of the most important drivers of progress in open source projects. A company that limits this freedom may hinder the success of the BA's efforts. * **Do not use patents as offensive weapons.** If any BA participant prevents the adoption or development of BA technologies by asserting its patents, that undermines the purpose of the coalition. The collaboration fostered by the BA cannot include members who act to undermine its work. * **Practice responsible disclosure** for security vulnerabilities. Use designated, non-public reporting channels to disclose technical vulnerabilities, and give the project a reasonable period to respond, remediate, and patch. [TODO: optionally include the security vulnerability reporting URL here.] Vulnerability reporters may patch their company's own offerings, as long as that patching does not significantly delay the reporting of the vulnerability. Vulnerability information should never be used for unilateral commercial advantage. Vendors may legitimately compete on the speed and reliability with which they deploy security fixes, but withholding vulnerability information damages everyone in the long run by risking harm to the BA project's reputation and to the security of all users. * **Respect the letter and spirit of open source practice.** While there is not space to list here all possible aspects of standard open source practice, some examples will help show what we mean: * Abide by all applicable open source license terms. Do not engage in copyright violation or misattribution of any kind. * Do not claim others' ideas or designs as your own. * When others engage in publicly visible work (e.g., an upcoming demo that is coordinated in a public issue tracker), do not unilaterally announce early releases or early demonstrations of that work ahead of their schedule in order to secure private advantage (such as marketplace advantage) for yourself. The BA reserves the right to determine what constitutes good open source practices and to take action as it deems appropriate to encourage, and if necessary enforce, such practices. ## Enforcement Instances of organizational behavior in violation of the OCoC may be reported by contacting the Bytecode Alliance CoC team at [report@bytecodealliance.org](mailto:report@bytecodealliance.org). The CoC team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The CoC team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. When the BA deems an organization in violation of this OCoC, the BA will, at its sole discretion, determine what action to take. The BA will decide what type, degree, and duration of corrective action is needed, if any, before a violating organization can be considered for membership (if it was not already a member) or can have its membership reinstated (if it was a member and the BA canceled its membership due to the violation). In practice, the BA's first approach will be to start a conversation, with punitive enforcement used only as a last resort. Violations often turn out to be unintentional and swiftly correctable with all parties acting in good faith. rustix-linux-procfs-0.1.1/README.md000064400000000000000000000043471046102023000150770ustar 00000000000000

rustix-linux-procfs

Utilities for opening Linux procfs files and directories

Github Actions CI Status zulip chat crates.io page docs.rs docs

This crate contains functions for obtaining file descriptors for files and directories under "/proc" on Linux. This crate does a considerable amount of work to determine whether `/proc` is mounted, with actual `procfs`, and without any additional mount points on top of the paths we open. Why all the effort to detect bind mount points? People are doing all kinds of things with Linux containers these days, with many different privilege schemes, and we want to avoid making any unnecessary assumptions. Libraries will sometimes use procfs *implicitly* (when Linux gives them no better options), in ways that aren't obvious from their public APIs. These filesystem accesses might not be visible to someone auditing the main code of an application for places which may be influenced by the filesystem namespace. So with the checking here, they may fail, but they won't be able to succeed with bogus results. As a caveat, QEMU intercepts selected paths in `open` to emulate their contents, however this crate's extra checks bypass QEMU's interceptions, so using this crate instead of just opening the paths directly can cause problems when running under QEMU. As a historical note, the functions used to be part of the [`rustix`] crate, but were factored out into a separate crate to simplify the `rustix` crate, as they can be implemented on top of rustix's public API. [`rustix`]: https://crates.io/crates/rustix rustix-linux-procfs-0.1.1/src/lib.rs000064400000000000000000000416361046102023000155250ustar 00000000000000#![doc = include_str!("../README.md")] #![cfg(any(target_os = "linux", target_os = "android"))] #![no_std] use core::mem::MaybeUninit; use once_cell::sync::OnceCell; use rustix::cstr; use rustix::fd::{AsFd, BorrowedFd, OwnedFd}; use rustix::ffi::CStr; use rustix::fs::{ fstat, fstatfs, major, openat, readlinkat_raw, renameat, seek, FileType, FsWord, Mode, OFlags, RawDir, SeekFrom, Stat, CWD, PROC_SUPER_MAGIC, }; use rustix::io; use rustix::path::DecInt; /// Linux's procfs always uses inode 1 for its root directory. const PROC_ROOT_INO: u64 = 1; // Identify an entry within "/proc", to determine which anomalies to check for. #[derive(Copy, Clone, Debug)] enum Kind { Proc, Pid, Fd, File, Symlink, } /// Check a subdirectory of "/proc" for anomalies. fn check_proc_entry( kind: Kind, entry: BorrowedFd<'_>, proc_stat: Option<&Stat>, ) -> io::Result { let entry_stat = fstat(entry)?; check_proc_entry_with_stat(kind, entry, entry_stat, proc_stat) } /// Check a subdirectory of "/proc" for anomalies, using the provided `Stat`. fn check_proc_entry_with_stat( kind: Kind, entry: BorrowedFd<'_>, entry_stat: Stat, proc_stat: Option<&Stat>, ) -> io::Result { // Check the filesystem magic. check_procfs(entry)?; match kind { Kind::Proc => check_proc_root(entry, &entry_stat)?, Kind::Pid | Kind::Fd => check_proc_subdir(entry, &entry_stat, proc_stat)?, Kind::File => check_proc_file(&entry_stat, proc_stat)?, Kind::Symlink => check_proc_symlink(&entry_stat, proc_stat)?, } // "/proc" directories are typically mounted r-xr-xr-x. // "/proc/self/fd" is r-x------. Allow them to have fewer permissions, but // not more. match kind { Kind::Symlink => { // On Linux, symlinks don't have their own permissions. } _ => { let expected_mode = if let Kind::Fd = kind { 0o500 } else { 0o555 }; if entry_stat.st_mode & 0o777 & !expected_mode != 0 { return Err(io::Errno::NOTSUP); } } } match kind { Kind::Fd => { // Check that the "/proc/self/fd" directory doesn't have any // extraneous links into it (which might include unexpected // subdirectories). if entry_stat.st_nlink != 2 { return Err(io::Errno::NOTSUP); } } Kind::Pid | Kind::Proc => { // Check that the "/proc" and "/proc/self" directories aren't // empty. if entry_stat.st_nlink <= 2 { return Err(io::Errno::NOTSUP); } } Kind::File => { // Check that files in procfs don't have extraneous hard links to // them (which might indicate hard links to other things). if entry_stat.st_nlink != 1 { return Err(io::Errno::NOTSUP); } } Kind::Symlink => { // Check that symlinks in procfs don't have extraneous hard links // to them (which might indicate hard links to other things). if entry_stat.st_nlink != 1 { return Err(io::Errno::NOTSUP); } } } Ok(entry_stat) } fn check_proc_root(entry: BorrowedFd<'_>, stat: &Stat) -> io::Result<()> { // We use `O_DIRECTORY` for proc directories, so open should fail if we // don't get a directory when we expect one. assert_eq!(FileType::from_raw_mode(stat.st_mode), FileType::Directory); // Check the root inode number. if stat.st_ino != PROC_ROOT_INO { return Err(io::Errno::NOTSUP); } // Proc is a non-device filesystem, so check for major number 0. // if major(stat.st_dev) != 0 { return Err(io::Errno::NOTSUP); } // Check that "/proc" is a mountpoint. if !is_mountpoint(entry) { return Err(io::Errno::NOTSUP); } Ok(()) } fn check_proc_subdir( entry: BorrowedFd<'_>, stat: &Stat, proc_stat: Option<&Stat>, ) -> io::Result<()> { // We use `O_DIRECTORY` for proc directories, so open should fail if we // don't get a directory when we expect one. assert_eq!(FileType::from_raw_mode(stat.st_mode), FileType::Directory); check_proc_nonroot(stat, proc_stat)?; // Check that subdirectories of "/proc" are not mount points. if is_mountpoint(entry) { return Err(io::Errno::NOTSUP); } Ok(()) } fn check_proc_file(stat: &Stat, proc_stat: Option<&Stat>) -> io::Result<()> { // Check that we have a regular file. if FileType::from_raw_mode(stat.st_mode) != FileType::RegularFile { return Err(io::Errno::NOTSUP); } check_proc_nonroot(stat, proc_stat)?; Ok(()) } fn check_proc_symlink(stat: &Stat, proc_stat: Option<&Stat>) -> io::Result<()> { // Check that we have a symbolic link. if FileType::from_raw_mode(stat.st_mode) != FileType::Symlink { return Err(io::Errno::NOTSUP); } check_proc_nonroot(stat, proc_stat)?; Ok(()) } fn check_proc_nonroot(stat: &Stat, proc_stat: Option<&Stat>) -> io::Result<()> { // Check that we haven't been linked back to the root of "/proc". if stat.st_ino == PROC_ROOT_INO { return Err(io::Errno::NOTSUP); } // Check that we're still in procfs. if stat.st_dev != proc_stat.unwrap().st_dev { return Err(io::Errno::NOTSUP); } Ok(()) } /// Check that `file` is opened on a `procfs` filesystem. fn check_procfs(file: BorrowedFd<'_>) -> io::Result<()> { let statfs = fstatfs(file)?; let f_type = statfs.f_type; if f_type != FsWord::from(PROC_SUPER_MAGIC) { return Err(io::Errno::NOTSUP); } Ok(()) } /// Check whether the given directory handle is a mount point. fn is_mountpoint(file: BorrowedFd<'_>) -> bool { // We use a `renameat` call that would otherwise fail, but which fails with // `XDEV` first if it would cross a mount point. let err = renameat(file, cstr!("../."), file, cstr!(".")).unwrap_err(); match err { io::Errno::XDEV => true, // the rename failed due to crossing a mount point io::Errno::BUSY => false, // the rename failed normally _ => panic!("Unexpected error from `renameat`: {:?}", err), } } /// Open a directory in `/proc`, mapping all errors to `io::Errno::NOTSUP`. fn proc_opendirat(dirfd: Fd, path: P) -> io::Result { // We don't add `PATH` here because that disables `DIRECTORY`. And we don't // add `NOATIME` for the same reason as the comment in `open_and_check_file`. let oflags = OFlags::RDONLY | OFlags::NOFOLLOW | OFlags::DIRECTORY | OFlags::CLOEXEC | OFlags::NOCTTY; openat(dirfd, path, oflags, Mode::empty()).map_err(|_err| io::Errno::NOTSUP) } /// Returns a handle to Linux's `/proc` directory. /// /// This ensures that `/proc` is procfs, that nothing is mounted on top of it, /// and that it looks normal. It also returns the `Stat` of `/proc`. /// /// # References /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html fn proc() -> io::Result<(BorrowedFd<'static>, &'static Stat)> { static PROC: StaticFd = StaticFd::new(); // `OnceBox` is “racy” in that the initialization function may run // multiple times. We're ok with that, since the initialization function // has no side effects. PROC.get_or_try_init(|| { // Open "/proc". let proc = proc_opendirat(CWD, cstr!("/proc"))?; let proc_stat = check_proc_entry(Kind::Proc, proc.as_fd(), None).map_err(|_err| io::Errno::NOTSUP)?; Ok(new_static_fd(proc, proc_stat)) }) .map(|(fd, stat)| (fd.as_fd(), stat)) } /// Returns a handle to Linux's `/proc/self` directory. /// /// This ensures that `/proc/self` is procfs, that nothing is mounted on top of /// it, and that it looks normal. It also returns the `Stat` of `/proc/self`. /// /// # References /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html #[allow(unsafe_code)] fn proc_self() -> io::Result<(BorrowedFd<'static>, &'static Stat)> { static PROC_SELF: StaticFd = StaticFd::new(); // The init function here may run multiple times; see above. PROC_SELF .get_or_try_init(|| { let (proc, proc_stat) = proc()?; // `getpid` would return our pid in our own pid namespace, so // instead use `readlink` on the `self` symlink to learn our pid in // the procfs namespace. let self_symlink = open_and_check_file(proc, proc_stat, cstr!("self"), Kind::Symlink)?; let mut buf = [MaybeUninit::::uninit(); 20]; let (init, _uninit) = readlinkat_raw(self_symlink, cstr!(""), &mut buf)?; let pid: &[u8] = unsafe { core::mem::transmute(init) }; // Open "/proc/self". Use our pid to compute the name rather than // literally using "self", as "self" is a symlink. let proc_self = proc_opendirat(proc, pid)?; let proc_self_stat = check_proc_entry(Kind::Pid, proc_self.as_fd(), Some(proc_stat)) .map_err(|_err| io::Errno::NOTSUP)?; Ok(new_static_fd(proc_self, proc_self_stat)) }) .map(|(owned, stat)| (owned.as_fd(), stat)) } /// Returns a handle to Linux's `/proc/self/fd` directory. /// /// This ensures that `/proc/self/fd` is `procfs`, that nothing is mounted on /// top of it, and that it looks normal. /// /// # References /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html #[cfg_attr(docsrs, doc(cfg(feature = "procfs")))] pub fn proc_self_fd() -> io::Result> { static PROC_SELF_FD: StaticFd = StaticFd::new(); // The init function here may run multiple times; see above. PROC_SELF_FD .get_or_try_init(|| { let (_, proc_stat) = proc()?; let (proc_self, _proc_self_stat) = proc_self()?; // Open "/proc/self/fd". let proc_self_fd = proc_opendirat(proc_self, cstr!("fd"))?; let proc_self_fd_stat = check_proc_entry(Kind::Fd, proc_self_fd.as_fd(), Some(proc_stat)) .map_err(|_err| io::Errno::NOTSUP)?; Ok(new_static_fd(proc_self_fd, proc_self_fd_stat)) }) .map(|(owned, _stat)| owned.as_fd()) } type StaticFd = OnceCell<(OwnedFd, Stat)>; #[inline] fn new_static_fd(fd: OwnedFd, stat: Stat) -> (OwnedFd, Stat) { (fd, stat) } /// Returns a handle to Linux's `/proc/self/fdinfo` directory. /// /// This ensures that `/proc/self/fdinfo` is `procfs`, that nothing is mounted /// on top of it, and that it looks normal. It also returns the `Stat` of /// `/proc/self/fd`. /// /// # References /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html fn proc_self_fdinfo() -> io::Result<(BorrowedFd<'static>, &'static Stat)> { static PROC_SELF_FDINFO: StaticFd = StaticFd::new(); PROC_SELF_FDINFO .get_or_try_init(|| { let (_, proc_stat) = proc()?; let (proc_self, _proc_self_stat) = proc_self()?; // Open "/proc/self/fdinfo". let proc_self_fdinfo = proc_opendirat(proc_self, cstr!("fdinfo"))?; let proc_self_fdinfo_stat = check_proc_entry(Kind::Fd, proc_self_fdinfo.as_fd(), Some(proc_stat)) .map_err(|_err| io::Errno::NOTSUP)?; Ok((proc_self_fdinfo, proc_self_fdinfo_stat)) }) .map(|(owned, stat)| (owned.as_fd(), stat)) } /// Returns a handle to a Linux `/proc/self/fdinfo/` file. /// /// This ensures that `/proc/self/fdinfo/` is `procfs`, that nothing is /// mounted on top of it, and that it looks normal. /// /// # References /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html #[inline] #[cfg_attr(docsrs, doc(cfg(feature = "procfs")))] pub fn proc_self_fdinfo_fd(fd: Fd) -> io::Result { _proc_self_fdinfo(fd.as_fd()) } fn _proc_self_fdinfo(fd: BorrowedFd<'_>) -> io::Result { let (proc_self_fdinfo, proc_self_fdinfo_stat) = proc_self_fdinfo()?; let fd_str = DecInt::from_fd(fd); open_and_check_file( proc_self_fdinfo, proc_self_fdinfo_stat, fd_str.as_c_str(), Kind::File, ) } /// Returns a handle to a Linux `/proc/self/pagemap` file. /// /// This ensures that `/proc/self/pagemap` is `procfs`, that nothing is /// mounted on top of it, and that it looks normal. /// /// # References /// - [Linux] /// - [Linux pagemap] /// /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html /// [Linux pagemap]: https://www.kernel.org/doc/Documentation/vm/pagemap.txt #[inline] #[cfg_attr(docsrs, doc(cfg(feature = "procfs")))] pub fn proc_self_pagemap() -> io::Result { proc_self_file(cstr!("pagemap")) } /// Returns a handle to a Linux `/proc/self/maps` file. /// /// This ensures that `/proc/self/maps` is `procfs`, that nothing is /// mounted on top of it, and that it looks normal. /// /// # References /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html #[inline] #[cfg_attr(docsrs, doc(cfg(feature = "procfs")))] pub fn proc_self_maps() -> io::Result { proc_self_file(cstr!("maps")) } /// Returns a handle to a Linux `/proc/self/status` file. /// /// This ensures that `/proc/self/status` is `procfs`, that nothing is /// mounted on top of it, and that it looks normal. /// /// # References /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html #[inline] #[cfg_attr(docsrs, doc(cfg(feature = "procfs")))] pub fn proc_self_status() -> io::Result { proc_self_file(cstr!("status")) } /// Open a file under `/proc/self`. fn proc_self_file(name: &CStr) -> io::Result { let (proc_self, proc_self_stat) = proc_self()?; open_and_check_file(proc_self, proc_self_stat, name, Kind::File) } /// Open a procfs file within in `dir` and check it for bind mounts. fn open_and_check_file( dir: BorrowedFd<'_>, dir_stat: &Stat, name: &CStr, kind: Kind, ) -> io::Result { let (_, proc_stat) = proc()?; // Don't use `NOATIME`, because it [requires us to own the file], and when // a process sets itself non-dumpable Linux changes the user:group of its // `/proc/` files [to root:root]. // // [requires us to own the file]: https://man7.org/linux/man-pages/man2/openat.2.html // [to root:root]: https://man7.org/linux/man-pages/man5/proc.5.html let mut oflags = OFlags::RDONLY | OFlags::CLOEXEC | OFlags::NOFOLLOW | OFlags::NOCTTY; if let Kind::Symlink = kind { // Open symlinks with `O_PATH`. oflags |= OFlags::PATH; } let file = openat(dir, name, oflags, Mode::empty()).map_err(|_err| io::Errno::NOTSUP)?; let file_stat = fstat(&file)?; // `is_mountpoint` only works on directory mount points, not file mount // points. To detect file mount points, scan the parent directory to see if // we can find a regular file with an inode and name that matches the file // we just opened. If we can't find it, there could be a file bind mount on // top of the file we want. // // TODO: With Linux 5.8 we might be able to use `statx` and // `STATX_ATTR_MOUNT_ROOT` to detect mountpoints directly instead of doing // this scanning. let expected_type = match kind { Kind::File => FileType::RegularFile, Kind::Symlink => FileType::Symlink, _ => unreachable!(), }; let mut found_file = false; let mut found_dot = false; // Open a new fd, so that if we're called on multiple threads, they don't // share a seek position. let oflags = OFlags::RDONLY | OFlags::CLOEXEC | OFlags::NOFOLLOW | OFlags::NOCTTY | OFlags::DIRECTORY; let dir = openat(dir, cstr!("."), oflags, Mode::empty()).map_err(|_err| io::Errno::NOTSUP)?; let check_dir_stat = fstat(&dir)?; if check_dir_stat.st_dev != dir_stat.st_dev || check_dir_stat.st_ino != dir_stat.st_ino { return Err(io::Errno::NOTSUP); } // Position the directory iteration at the start. seek(&dir, SeekFrom::Start(0))?; let mut buf = [MaybeUninit::uninit(); 2048]; let mut iter = RawDir::new(dir, &mut buf); while let Some(entry) = iter.next() { let entry = entry.map_err(|_err| io::Errno::NOTSUP)?; if entry.ino() == file_stat.st_ino && entry.file_type() == expected_type && entry.file_name() == name { // We found the file. Proceed to check the file handle. let _ = check_proc_entry_with_stat(kind, file.as_fd(), file_stat, Some(proc_stat))?; found_file = true; } else if entry.ino() == dir_stat.st_ino && entry.file_type() == FileType::Directory && entry.file_name() == cstr!(".") { // We found ".", and it's the right ".". found_dot = true; } } if found_file && found_dot { Ok(file) } else { Err(io::Errno::NOTSUP) } }