From patchwork Mon Nov 21 03:41:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick McGehearty X-Patchwork-Id: 60899 X-Patchwork-Delegate: azanella@linux.vnet.ibm.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E2423858C36 for ; Mon, 21 Nov 2022 03:42:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E2423858C36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669002146; bh=kI96u3gE/ws2g3AfhVm0tMbzrEiz14GHi1ff9Bs6d5E=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jvMrzQpjH8arUZ2ghPmWdabJFucZkCpxNcAS/vDnUVl15Y5jdRdHcchCiI2qap5u1 Zorpy/kqSMuVnTnXLK7n2B1TiQRE+JEpM+Z0SoMOweUNwYwE9u1Bhz3hNnjXtN2zWg iJsoyraDYogPXMRiiXvL/X0WraqZwrvVYmMOuews= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id AE4C73858C2F for ; Mon, 21 Nov 2022 03:41:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AE4C73858C2F Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AL1R5wS024635 for ; Mon, 21 Nov 2022 03:41:41 GMT Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kxr99k3cb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 21 Nov 2022 03:41:41 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2AL39PUx031283 for ; Mon, 21 Nov 2022 03:41:40 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2170.outbound.protection.outlook.com [104.47.56.170]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3kxnk34ba8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 21 Nov 2022 03:41:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LpIvDnD3h3/mmEsJ2fioe/zgsKK5Bih7FkvTABTja8q/5cOrW4R4DlNQEHLi7keZ8ux/iHOIxY9Znjt+Yo1hULtQevYDOAj6bGDigNoSxtWWS4Hj6y9m4RCQWuzIxWH3y028E3Osl+AQt6YDQPsmPIjC0vuf1XWYOfUuG5Mz4WTdEk73k3kBhAUChB5GV15xEc5jNP3UkOeZeTm03QP2i2vj9JlpUCrjCUsULSgegr97WNXkRJYw7loPVkNmCbyRhfzgqklu4tDMXg8TrL0a8mlfePf/nuZdLyi1unQmIHoq+gYjvUQFoqIh7x2YjxH84Z6al78cZRYpAnHF924reA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mJo2o6hkTq6M0uQOUMeAmvo/1aoMPGuCaoorudpw7NE=; b=XKmNsg20eRJyBQootfdxtnxd4pOAAxxVCRsqGFyWH2k+2EPzG+W4OvlWcPlx9aDGiHO1Cs+80DC2W2DNrrwQPysi2Gai/OgPN0CNpnmQ+efuDjRnZiU0a2tYiY0p2NJ+VKDp9KGwU+PRsj7r7ioO6sxksQyJzXbhWRuF2ygLPRgj0Zev+P4E5AqpmTU4y8Yh72pc7Kt547pAisIsUjAwobDZnT1gIIkBN421EwD6H+44AmL8NSEttgSEU2FTi+a2kZ30gXiFNv67r6PlVM4eQc1KUWSL3ChEiAeYcfSUBiKRoYr0rDt+JfJM30+9ZhOvc7OSUSs2SNhQDslgKW0aFg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none Received: from BYAPR10MB3208.namprd10.prod.outlook.com (2603:10b6:a03:159::10) by CH2PR10MB4119.namprd10.prod.outlook.com (2603:10b6:610:ae::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.18; Mon, 21 Nov 2022 03:41:38 +0000 Received: from BYAPR10MB3208.namprd10.prod.outlook.com ([fe80::9aae:27cb:b098:f6f6]) by BYAPR10MB3208.namprd10.prod.outlook.com ([fe80::9aae:27cb:b098:f6f6%4]) with mapi id 15.20.5834.011; Mon, 21 Nov 2022 03:41:38 +0000 Message-ID: Date: Sun, 20 Nov 2022 21:41:34 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Content-Language: en-US To: GNU C Library Subject: [PATCH] Resolve-flockfile-funlockfile-differences X-ClientProxiedBy: SA9P223CA0007.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::12) To BYAPR10MB3208.namprd10.prod.outlook.com (2603:10b6:a03:159::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3208:EE_|CH2PR10MB4119:EE_ X-MS-Office365-Filtering-Correlation-Id: 02cf8b52-664a-41a2-6ea0-08dacb724bd7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sLRb+GKgCNo8I2BgvmLWyuisPc0PmS1KBZJ0XXeH5hrBLhLxI07nAQBch65c1p57+ENXmUQr0d1+i2FDVd0DLSX++wzlYMDQzVR0yQSdbDJvIpIJRxUJ7CZM7fZy3XQhhA60tR6fn1EaxihojTdQgDkeAp04zyL1oI2t3fGb0VuxmaY35tYr9iqIgPbpU11t24v8yZazdQa6hgPltEtEplDZ9RjyxVKXucRT4A1ASms3EpygIzf32guMZbWI1iR8Dz8emvMfg/HAk+HC5Fthis5gEY/haYIdVYUJ4ROAp+zJSTDpq8/4x3vhSzvxNCydo6Lu1I49vEMxHJIbSZlI7g+K20U5OyGG6funKYyMzLn+d0hyRgcicmtVReK2YptSFqyWZU21C/mK5y2qnf7asRUDtySEK00/4GW5lxOsquH7Yim4roQZRzjq2fr1Ozt/blgb148rFhvTgJGuVwllLlkCXDxn/ofA6934Ln/7G/o= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB3208.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(346002)(366004)(136003)(39860400002)(396003)(376002)(451199015)(6916009)(8936002)(2906002)(66556008)(66946007)(66476007)(38100700002)(316002)(41300700001)(31686004)(8676002)(235185007)(31696002)(86362001)(6486002)(478600001)(2616005)(26005)(6666004)(6512007)(33964004)(6506007)(564344004)(186003)(83380400001)(36756003)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?cH12A8mab1QJn/+J0iXAMotX4VP8?= =?ut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f-8?q?GzhR769WWye2W5Ubtd649ckXQcI9FV52b5toYkNMd+490N+TwnxN+EpholfvD6QXY?= =?utf-8?q?kWR2fmU9Sqr6uBpK2ZZiNJdln2KVZW6oGfvon1J9PSaQbHTvTvlsS2u9ZEXbyikpo?= =?utf-8?q?cPbbRqwqWLLSOuDKr5tuj4d9iEN4+qLneN2iO3FJeIdiKczN2q8IfX3kHEXj6RdeZ?= =?utf-8?q?5cd3MyafGXCgFSgCyPuXzNtlfXsHHwMg+Tx8AvzrKqfOs6jI/FJSCBz9pqW0iork0?= =?utf-8?q?+WCqC0w+oOBK9hzsPN5C27QCnK12GjQxls/XqGsadgd4fQHFQBo31dPiRvPTkVxng?= =?utf-8?q?Rckzq0NTDXlBJUN43b7VyWUj/f/enfv3RdCd9gcRhDv7A9tiMlqz62iREi6mWA7ZT?= =?utf-8?q?Aa0yAV4oxgrABbVMfX0zxze/3ar3gZsgolZKRunhEJfD0HAOaMNFfZCDn5KsaWzYm?= =?utf-8?q?nCJum4P6mzVgeRJs1omoSfMdF9Cf9M4uWxO3BxVESXj0+3yT14/ZlI8RK8IBbLu2w?= =?utf-8?q?JDxo07+F8z8W7+COXQ39AYHCMWYrZoOYwKOJgBY8x4Dh9eKW2KcRifrFlg2EA1zHi?= =?utf-8?q?b7iMOhspHiTprU5LktceIWg9EbcXIisFs+UP6I//p0eQmNDgRXxP0ohwIX/BSykkT?= =?utf-8?q?Cv7dq8+QTI2nXj7d1SELUxIz084ylnEOZQ=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: A63L70w/TCo1/qgytljRsV5/HGPfjWxpTFSvy5IDdfZtylRy1tlzdRYLqvusYAzGliag7Q30/LHpUfHKAjIuNYlGQxVUtxCFUMkdRB//jPDMQtIWjD2noE4MzapZeGX8r7d5YrFbZ+hqDbXdgA9Vlmsmr/29fIjghuut4xC2UVMrnYTdyVXlOtn2JsiZze16xGe9EEiKEydENWbXLRbf7UK6gRb2ZHbvZJGCGypeIay1t1LtBhKgNt0xDIzDLe3zpWkTMgUz7FIAnF+LGZcP9FYqwaG8sdYCyGdyWWVYG2tKRYliTqO+O1yy2ySdZ5Sg3IYTglGMxlPyW90r4xVlytSORNjMmT2O7PnEVCv7kaIEYekKooq1mtHQYeCIi6oJJwEx3KwCl50RBfajfk5lTO2Nj1PyqbAyZg6FjKEtcQFXQz3PZJR/h3V8GZ8G0+QbcTe3B1+/0dh3pNJCk/gyJIgsMSOC2fPXWlsgw77ajotWJKcM4u/UyCih2LlSEWF0dyVzgohTdF0cspo/gXtErDglq9vWlNafvEvYAfXcxSvcYIb+g0YPVsaU4bIcLnDTgbBKp1FjiNh9/T0I3yM7VS2g0ofnDw6I44SglneIQnZHnMiQRDGdH3pLAKAPLntW9NTQO3ZrZuo2kFzPUs5kikUVwf2/oO1HcrCFNJAbGiQZg3Qf0UhPru3t0fDXFyDAxTtf2UL9jdH6lwpcI201bv4z/mn/FVZfLr2Vq1zaUWVJeffrLXgaudkI+E5rXZNsm1ZbMOvGharSOVH22LMV0Q== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 02cf8b52-664a-41a2-6ea0-08dacb724bd7 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3208.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2022 03:41:38.7497 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: TGmDvwRWF54Ma979UsiNHMYyt+m6tNSM0kVp8OpRirEMRwNyfxhQx1lhpYBsoGb4A+YSpiATljE/Ph/Y2F9vAbhQhiP7sbgryrEWru/Vchg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB4119 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-21_02,2022-11-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 suspectscore=0 malwarescore=0 spamscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211210027 X-Proofpoint-GUID: QyuEU8tI-_rDXzDQy0dMmpkz2JTIDhOz X-Proofpoint-ORIG-GUID: QyuEU8tI-_rDXzDQy0dMmpkz2JTIDhOz X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org Content-Disposition: attachment; filename="0001-Resolve-flockfile-funlockfile-differences.patch" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick McGehearty via Libc-alpha From: Patrick McGehearty Reply-To: Patrick McGehearty Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" From 009033afe026dc8d6931e6fe4e92e6b4e7a693a2 Mon Sep 17 00:00:00 2001 From: Patrick McGehearty Date: Thu, 10 Nov 2022 21:51:00 +0000 Subject: [PATCH] Resolve flockfile/funlockfile differences This patch resolves differences between flockfile/funlockfile and LOCK_STREAM/UNLOCKSTREAM to avoid failure to unlock a stream mutex in a multi-threaded application context which allows entering using LOCK_STREAM but leaving using funlockfile or vice-versa. This issue was detected during stress tests of a large proprietary application. The cause and solution was identified by Gerd Rausch. The issue occurs because _IO_funlockfile has different definitions in different contexts: Comparing the inline version in libio/libio.h # define _IO_flockfile(_fp) \ if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_flockfile (_fp) And the non-inline version in stdio-common/flockfile.c __flockfile (FILE *stream) { _IO_lock_lock (*stream->_lock); } Note the lack of the _IO_USER_LOCK in the __flockfile version. This difference means it is possible to bypass the lock in some cases and not release the lock in other cases. Either way, it causes trouble. The proposed fix is to simple add the _IO_USER_LOCK guard to the non-line versions of flockfile and funlockfile. Modified files: stdio-common/flockfile.c stdio-common/funlockfile.c --- stdio-common/flockfile.c | 3 ++- stdio-common/funlockfile.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/stdio-common/flockfile.c b/stdio-common/flockfile.c index 49f72c6..4b41ce8 100644 --- a/stdio-common/flockfile.c +++ b/stdio-common/flockfile.c @@ -22,7 +22,8 @@ void __flockfile (FILE *stream) { - _IO_lock_lock (*stream->_lock); + if ((stream->_flags & _IO_USER_LOCK) == 0) + _IO_lock_lock (*stream->_lock); } weak_alias (__flockfile, flockfile); weak_alias (__flockfile, _IO_flockfile) diff --git a/stdio-common/funlockfile.c b/stdio-common/funlockfile.c index bf44c99..f330a28 100644 --- a/stdio-common/funlockfile.c +++ b/stdio-common/funlockfile.c @@ -23,7 +23,8 @@ void __funlockfile (FILE *stream) { - _IO_lock_unlock (*stream->_lock); + if ((stream->_flags & _IO_USER_LOCK) == 0) + _IO_lock_unlock (*stream->_lock); } weak_alias (__funlockfile, _IO_funlockfile) weak_alias (__funlockfile, funlockfile);