RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1327388 - Fix use-after-free in st_queue_handler
Summary: Fix use-after-free in st_queue_handler
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: autofs
Version: 7.2
Hardware: All
OS: Linux
medium
medium
Target Milestone: rc
: ---
Assignee: Ian Kent
QA Contact: xiaoli feng
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-04-15 04:01 UTC by Frank Sorenson
Modified: 2016-11-04 07:44 UTC (History)
2 users (show)

Fixed In Version: autofs-5.0.7-56.el7
Doc Type: Bug Fix
Doc Text:
Cause: In function st_queue_handler() the task structure may be referenced after being freed. Consequence: This can occasionally lead to a segmentation fault. Fix: Move the line which references this task structure to a location before it is freed. Result: No segmentation fault can occur due to this reference.
Clone Of:
Environment:
Last Closed: 2016-11-04 07:44:05 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
patch to fix the use-after-free (737 bytes, patch)
2016-04-15 04:09 UTC, Frank Sorenson
no flags Details | Diff
Patch - fix use-after-free in st_queue_handler() (1.01 KB, patch)
2016-05-17 06:29 UTC, Ian Kent
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2016:2508 0 normal SHIPPED_LIVE autofs bug fix and enhancement update 2016-11-03 14:13:33 UTC

Description Frank Sorenson 2016-04-15 04:01:14 UTC
Description of problem:

In st_queue_handler, the 'task' may be referenced after being freed.


Version-Release number of selected component (if applicable):

kernel-3.10.0-327.10.1.el7.x86_64
autofs-5.0.7-54.el7.x86_64


How reproducible:

see below


Steps to Reproduce:

# echo "/autofs_segv	/etc/auto.segv0" > /etc/auto.master
# echo "subdir	-fstype=autofs	file:/etc/auto.segv1" > /etc/auto.segv0
# > /etc/auto.segv1

# systemctl restart autofs.service

(run under ElectricFence to get segfault when the freed memory is accessed)
# ef /usr/sbin/automount -t 20 -f

(in another terminal)
# ls /autofs_segv/subdir

(wait about 5 seconds)


Actual results:

segfault


Expected results:

automount continues running


Additional info:

here, 'next' gets a pointer in the 'task->pending' list, then 'task' is freed, but the 'next->pending' list may still include the 'task'.  The 'list_del_init(&next->pending)' will then attempt to write to the address:

	/* Next task */
	next = list_entry((&task->pending)->next,
		struct state_queue, pending);

	list_del(&task->list);
	free(task);

	list_del_init(&next->pending);  <<<<<<<<<<<<


97	static __inline__ void list_del_init(struct list_head *entry)
98	{
99		__list_del(entry->prev, entry->next); <<<<<<<<<
100		INIT_LIST_HEAD(entry); 


76	static __inline__ void __list_del(struct list_head * prev,
77					  struct list_head * next)
78	{
79		next->prev = prev;  <<<<<<<<<<<< crash while setting 'next->prev'
80		prev->next = next;


#0  0x00007fbc191ed89d in __list_del (prev=0x7fbc14f13fd8, next=0x7fbc14f13fd8) at ../include/list.h:79
#1  0x00007fbc191ed8fc in list_del_init (entry=0x7fbc15ea0fd8) at ../include/list.h:99
#2  0x00007fbc191f0592 in st_queue_handler (arg=0x0) at state.c:1187
#3  0x00007fbc18b91dc5 in start_thread (arg=0x7fbc190a3700) at pthread_create.c:308
#4  0x00007fbc179f821d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:113

in frame 2:
(gdb) p task
$4 = (struct state_queue *) 0x7fbc14f13fc0

(gdb) p &task->pending
$6 = (struct list_head *) 0x7fbc14f13fd8


(gdb) p next
$7 = (struct state_queue *) 0x7fbc15ea0fc0

(gdb) p &next->pending
$11 = (struct list_head *) 0x7fbc15ea0fd8


(gdb) p (&next->pending)->prev
$12 = (struct list_head *) 0x7fbc14f13fd8

(gdb) p (&next->pending)->next
$15 = (struct list_head *) 0x7fbc14f13fd8

so we're trying to write back to the '&task->pending' after freeing task

Comment 1 Frank Sorenson 2016-04-15 04:09:58 UTC
Created attachment 1147456 [details]
patch to fix the use-after-free

Comment 3 Ian Kent 2016-04-15 07:15:36 UTC
(In reply to Frank Sorenson from comment #0)
> Description of problem:
> 
> In st_queue_handler, the 'task' may be referenced after being freed.
> 
> 
> Version-Release number of selected component (if applicable):
> 
> kernel-3.10.0-327.10.1.el7.x86_64
> autofs-5.0.7-54.el7.x86_64
> 
> 
> How reproducible:
> 
> see below
> 
> 
> Steps to Reproduce:
> 
> # echo "/autofs_segv	/etc/auto.segv0" > /etc/auto.master
> # echo "subdir	-fstype=autofs	file:/etc/auto.segv1" > /etc/auto.segv0
> # > /etc/auto.segv1
> 
> # systemctl restart autofs.service
> 
> (run under ElectricFence to get segfault when the freed memory is accessed)
> # ef /usr/sbin/automount -t 20 -f
> 
> (in another terminal)
> # ls /autofs_segv/subdir
> 
> (wait about 5 seconds)
> 
> 
> Actual results:
> 
> segfault
> 
> 
> Expected results:
> 
> automount continues running
> 
> 
> Additional info:
> 
> here, 'next' gets a pointer in the 'task->pending' list, then 'task' is
> freed, but the 'next->pending' list may still include the 'task'.  The
> 'list_del_init(&next->pending)' will then attempt to write to the address:

OK, it's been a while since I looked at this code.

I'll have a look.

AFAICR these two lists should be distinct so freeing something
on one should not affect the other.

I'll need to work out how the senario your describing works, not
a big problem but will take some effort.

Ian

Comment 4 Ian Kent 2016-04-15 07:22:53 UTC
(In reply to Frank Sorenson from comment #0)
> Description of problem:
> 
> In st_queue_handler, the 'task' may be referenced after being freed.

snip ...

> 
> here, 'next' gets a pointer in the 'task->pending' list, then 'task' is
> freed, but the 'next->pending' list may still include the 'task'.  The
> 'list_del_init(&next->pending)' will then attempt to write to the address:
> 
> 	/* Next task */
> 	next = list_entry((&task->pending)->next,
> 		struct state_queue, pending);
> 
> 	list_del(&task->list);
> 	free(task);
> 
> 	list_del_init(&next->pending);  <<<<<<<<<<<<
> 
> 
> 97	static __inline__ void list_del_init(struct list_head *entry)
> 98	{
> 99		__list_del(entry->prev, entry->next); <<<<<<<<<
> 100		INIT_LIST_HEAD(entry); 
> 
> 
> 76	static __inline__ void __list_del(struct list_head * prev,
> 77					  struct list_head * next)
> 78	{
> 79		next->prev = prev;  <<<<<<<<<<<< crash while setting 'next->prev'
> 80		prev->next = next;

Oh right, enough said.

Ian

Comment 5 Ian Kent 2016-05-17 06:29:57 UTC
Created attachment 1158184 [details]
Patch - fix use-after-free in st_queue_handler()

Comment 6 Ian Kent 2016-05-17 06:31:47 UTC
Comment on attachment 1147456 [details]
patch to fix the use-after-free

Some minor changes were made to the name of the patch and layout of the description of Franks' original patch.

Comment 10 errata-xmlrpc 2016-11-04 07:44:05 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2016-2508.html


Note You need to log in before you can comment on or make changes to this bug.