From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id 5837A23D5C for ; Sun, 21 Jan 2024 13:06:28 +0100 (CET) Received: (qmail 22163 invoked by uid 550); 21 Jan 2024 12:04:26 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 22128 invoked from network); 21 Jan 2024 12:04:26 -0000 MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dustri.org; s=key1; t=1705838775; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ObDCORSzPEQD278PV4dTAjVWPBYTWHIa1sK1RK6L9mo=; b=cQ1/oVs7FO+cxec0XD215qR0YaDSGBQvK9NPiBN8dMkncDDI/K3Y96uE8PGgta8613HQkO D2Kg1+sDiUDw3raB+tjgZ6lr/On4uO9pqxSZFjJUDq+0JcDtItkfgfHkjoNZILFhM7L2Wf ySvZKXucH9ZTofIZL6p/3jyht2R+qDyF/+xiVYjyGA4252Qb6PFmhijp6R7jve1YvwU5kC Km8IfNUiA33xVuMhKCWXYmmNhfWgVIIhAjgaht2e5tf9uSTDVb0uh0qOUX/e8hQmZ3K7xR D+lWX/ayMOUdBijMSzh6eIJwJry7mdjFlsWU8ex+EEJA8mzAc2UP+OPAcv8wDA== Date: Sun, 21 Jan 2024 12:06:14 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: julien.voisin@dustri.org Message-ID: <820837e29ea605142a934e672d670fbbd9d44cbd@dustri.org> TLS-Required: No To: "Rich Felker" Cc: musl@lists.openwall.com In-Reply-To: <20240121034301.GZ4163@brightrain.aerifal.cx> References: <20240109190726.GO4163@brightrain.aerifal.cx> <20240121034301.GZ4163@brightrain.aerifal.cx> X-Migadu-Flow: FLOW_OUT Subject: Re: [musl] Protect pthreads' mutexes against use-after-destroy > Draft attached in case anyone wants to play with it. This could > probably be something we could consider to adopt. Couldn't a macro like `#define mutex_is_destroyed (!(m->_m_type & 8) && (= m->_m_lock =3D=3D 0x3fffffff)` be used instead? Or at least named constants instead of `8` and `0x3fffffff`= . Also, the code-style seems inconsistent: ``` + if (own =3D=3D 0x3fffffff) { + /* Catch use-after-destroy */ + if (!(type & 8)) a_crash();=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 +=20 return ENOTRECOVERABLE; + } ``` vs=20 ``` +=20 /* Catch use-after-destroy */ + if (own =3D=3D 0x3fffffff && !(type & 8)) a_crash= (); return EPERM; ``` Both are the same check, yet only one has both conditions in a single `if= `.