From owner-freebsd-standards@FreeBSD.ORG Fri Jan 21 05:40:07 2011 Return-Path: Delivered-To: freebsd-standards@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 439551065675 for ; Fri, 21 Jan 2011 05:40:07 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 0731F8FC12 for ; Fri, 21 Jan 2011 05:40:07 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p0L5e6n4076220 for ; Fri, 21 Jan 2011 05:40:06 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p0L5e6eE076219; Fri, 21 Jan 2011 05:40:06 GMT (envelope-from gnats) Resent-Date: Fri, 21 Jan 2011 05:40:06 GMT Resent-Message-Id: <201101210540.p0L5e6eE076219@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-standards@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Zhouyi Zhou Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A49A7106564A for ; Fri, 21 Jan 2011 05:33:17 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (unknown [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 9494A8FC1D for ; Fri, 21 Jan 2011 05:33:17 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p0L5XHie003509 for ; Fri, 21 Jan 2011 05:33:17 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id p0L5XHXL003508; Fri, 21 Jan 2011 05:33:17 GMT (envelope-from nobody) Message-Id: <201101210533.p0L5XHXL003508@red.freebsd.org> Date: Fri, 21 Jan 2011 05:33:17 GMT From: Zhouyi Zhou To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: standards/154185: race condition in mb_dupcl X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Jan 2011 05:40:07 -0000 >Number: 154185 >Category: standards >Synopsis: race condition in mb_dupcl >Confidential: no >Severity: serious >Priority: low >Responsible: freebsd-standards >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Jan 21 05:40:06 UTC 2011 >Closed-Date: >Last-Modified: >Originator: Zhouyi Zhou >Release: FreeBSD 8.0 >Organization: ICT CAS >Environment: FreeBSD zzy 8.0-RELEASE FreeBSD 8.0-RELEASE #85: Fri Jan 21 12:56:40 UTC 2011 root@zzy:/root/sys/amd64/compile/GENERIC amd64 >Description: There is race condition in function mb_dupcl in src/sys/kern/uipc_mbuf.c The code to add reference count in mb_dupcl is as follows 390 if (*(m->m_ext.ref_cnt) == 1) 391 *(m->m_ext.ref_cnt) += 1; The x86 asm code for these two lines is: 0xffffffff807aa28d : sub $0x1,%eax 0xffffffff807aa290 : je 0xffffffff807aa2f0 .. 0xffffffff807aa2f0 : mov (%rdx),%ecx 0xffffffff807aa2f2 : add $0x1,%ecx 0xffffffff807aa2f5 : mov %ecx,(%rdx) It is appearant that multiple threads will race for the contents of (%rdx) >How-To-Repeat: Can write a kernel module like: struct mbuf *m; MGETHDR(m, M_DONTWAIT, MT_DATA); MCLGET(m, M_DONTWAIT); Then let multiple threads execute simulately: m1 = m_copypacket(m, M_DONTWAIT); m_freem(m1); >Fix: function mb_dupcl 390 - if (*(m->m_ext.ref_cnt) == 1) 391 - *(m->m_ext.ref_cnt) += 1; 392 - else 393 atomic_add_int(m->m_ext.ref_cnt, 1); >Release-Note: >Audit-Trail: >Unformatted: