Skip to content

Fix uouv on oom on object allocation #11739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

iluuu1994
Copy link
Member

@iluuu1994 iluuu1994 commented Jul 18, 2023

Initialize object.handlers to std_object_handlers in zend_object_alloc. This avoids a use-after-free for objects using custom handlers that are installed after allocation, accessing the handlers on shutdown when they haven't been set yet.

Fixes GH-11734

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and is a nice solution

@Girgias
Copy link
Member

Girgias commented Jul 18, 2023

Well apparently the compilers are not happy:

/home/runner/work/php-src/php-src/Zend/zend_objects_API.h: In function ‘void* zend_object_alloc(size_t, zend_class_entry*)’:
/home/runner/work/php-src/php-src/Zend/zend_objects_API.h:98:23: error: pointer of type ‘void *’ used in arithmetic [-Werror=pointer-arith]
   98 |  ((zend_object *)(obj + obj_size - sizeof(zend_object)))->handlers = &std_object_handlers;
      |                   ~~~~^~~~~~~~~~
/home/runner/work/php-src/php-src/Zend/zend_objects_API.h:98:34: error: pointer of type ‘void *’ used in arithmetic [-Werror=pointer-arith]
   98 |  ((zend_object *)(obj + obj_size - sizeof(zend_object)))->handlers = &std_object_handlers;
      |                   ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~

@iluuu1994
Copy link
Member Author

It's missing a (uintptr_t) cast.

Initialize object.handlers to std_object_handlers in zend_object_alloc. This
avoids a use-after-free for objects using custom handlers that are installed
after allocation, accessing the handlers on shutdown when they haven't been set
yet.

Fixes phpGH-11734
* installed. This avoids a use-of-uninitialized-value on shutdown. This would be more fitting in
* zend_object_std_init(), but some extensions set handlers before calling
* zend_object_std_init(). */
((zend_object *)((uintptr_t)obj + obj_size - sizeof(zend_object)))->handlers = &std_object_handlers;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, this is completely wrong. std_object_handlers->offset is zero and this may be inconsistent with the real obj_size. This is wrong for SplPriorityQueue.

Do I miss something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. I was completely unaware of this field... I'll look for a case-by-case solution then. All objects must set handlers before allocating with emalloc.

@iluuu1994 iluuu1994 closed this Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants