Skip to content

Detect buffer overflow in fcntl.fcntl() and fcntl.ioctl() #132915

Closed
@serhiy-storchaka

Description

@serhiy-storchaka

fcntl() and ioctl() take an argument which can be a pointer to a buffer of unspecified length, depending on operation. They can also write in that buffer, depending on operation. A temporary buffer of size 1024 is used, so a chance of directly overflowing the bytes-like object provided by user is small, but if its size than necessary, the user will get truncated data in best case, and in worst case it will cause the C stack corruption.

We cannot prevent this, unless we limit the set of supported operations to a small set of allowed operations. This is not practical, because fcntl() and ioctl() exist to support operations not explicitly supported by Python. But we can detect a buffer overflow, and raise an exception. It may be too late, if the stack or memory are corrupted, but it is better than silently ignore error.

Linked PRs

Metadata

Metadata

Labels

extension-modulesC modules in the Modules dirtype-featureA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions