Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp7504335ybp; Wed, 16 Oct 2019 09:36:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqwuJmBfbJN/1pwaJIpKLjdtqPlnB6UozUBXtiNhyuV7BgLxQ2bUtQXS6Fk1aXTRlrz7dpqZ X-Received: by 2002:a05:6402:7cc:: with SMTP id u12mr40417575edy.63.1571243800409; Wed, 16 Oct 2019 09:36:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571243800; cv=none; d=google.com; s=arc-20160816; b=GQpz8RuYKlqwKgxU5VpoTG+8SDY/aRe3SKScHB0vS1y+Gxe1pLPIFpwG71vnrC4mXf 6u4Q5rzrey72YrGwGD/GAk8djj/Pf/iFXHAhdYeiFQM+BatG2Mj4FlrbJwgyQ6A6IBw0 2QbxceE5He5o1yRSc5Msyq8wbFpnY+JfYRXA5W4YmHYc+teisbLZkxGABPybh4gLSrYI nv3HzMTu0PJCfsXVuvdjBp8HgKMwfz0ueHKXCdWJ0lm1J+GiKUJDxgsvCr2vvWcjR0oX m0C8ALU5QnO7j3FsOjNDH3lhrLcqad2QLl96zm/qvRRXjG6TsMDffP85JpQ10aXcru2H O2sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :autocrypt:openpgp:from:references:cc:to:subject; bh=pEm3x6IFosi7GD2oKK9cwAs3AC37Bt7rnRO2ui1Zo6I=; b=YKEvB+ihXlzqPO9Szjbu3NoKBVQT7A9OHM7h3Vx7XpyFtBheMG0m/EDJOJAJWqZlEt ARSXHn10lUYKDZlFH1hq3MDFWjz+elHPa2OCBQa1C7F/93WuZD2N9Nlk4ra3MIouD3gw FVMGdA0Ihjseqjg4dWJPar0ULiJ56t79j7QbvOasb5itSSQsRdW7FL1pVImVQLjDDTz0 5HaCEkD8z9KAvFH1DLZeHHN6TyiD9pqxt8MGokvo83iIppy0Bzl389cQ/LCayJNUv95D +14nwR5kj9/jV5Sj2peEZn0QKelreEVO2s3SdDnbVOiyFZugnlGvMQDoCoLJaGcgLQjf UGBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x51si18267402eda.272.2019.10.16.09.36.17; Wed, 16 Oct 2019 09:36:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390752AbfJPO41 (ORCPT + 99 others); Wed, 16 Oct 2019 10:56:27 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:44006 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388424AbfJPO40 (ORCPT ); Wed, 16 Oct 2019 10:56:26 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x9GEqxuC161948 for ; Wed, 16 Oct 2019 10:56:25 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0b-001b2d01.pphosted.com with ESMTP id 2vp3cfdxq2-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 16 Oct 2019 10:56:24 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 16 Oct 2019 15:56:23 +0100 Received: from b06avi18626390.portsmouth.uk.ibm.com (9.149.26.192) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 16 Oct 2019 15:56:20 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x9GEtlf837683498 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Oct 2019 14:55:47 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 244C011C052; Wed, 16 Oct 2019 14:56:19 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BE51111C054; Wed, 16 Oct 2019 14:56:18 +0000 (GMT) Received: from [9.152.214.37] (unknown [9.152.214.37]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 16 Oct 2019 14:56:18 +0000 (GMT) Subject: Re: memory leaks in dasd_eckd_check_characteristics() error paths To: Qian Cai , Jan Hoeppner , Heiko Carstens , Vasily Gorbik , Christian Borntraeger Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org References: <1570044801.5576.262.camel@lca.pw> <6f5584d5-755c-e416-52da-3cb99c69adaf@linux.ibm.com> <1571234974.5937.53.camel@lca.pw> From: Stefan Haberland Openpgp: preference=signencrypt Autocrypt: addr=sth@linux.ibm.com; keydata= mQINBFtGVggBEADI1Lne1npTa+b5x5EJ7ka0siRMargCCo5dcOaCBBG3wT24IyyG6chdV7Yr vkeH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8JDOklOPJCe0bBKFK0ZMF1Kz9AzFj/RFzWfB5 ABEBAAGJAiUEGAEIAA8FAltGVggCGwwFCQlmAYAACgkQ9KmDAON4ldGPmA/+L3V5wkmWZJjD ZJIvio/wHMoqObEG6MxsFvGEoSDJBBGQ5oTiysACFM2vkOaOhj2Izh2L+dbuKJIT0Qus0hUJ uEjGgIAXn7hYNeM1MMqSA81NEoCeUhNHeZudf5WSoglG3rUnxIXrnxfDkn8Vd36cinGejyrI qJoydRMpX48I3wJcyvZ8+xgM/LLlvXEH4BpuJL+vQkefJrn0R2vxTnHcj5TE1tKNwhI7/343 PNzhgHGYynjCbF4u9qpSqcJl/exFnRXaTH6POIbHXIRe8n4TfdXsOcbI3j/GUF0cXinkfxdt BWH5rC3Ng+EN3jkDo8N9qF7uEqN9rRaekqsO0jYMQJlfZeJSQH9KHD+wgZly9j6DmnGexbdB aJdzCtbIR+oJy0HjfwvIQrgp1pj0yvXeDsUHykATsORx0ZitlGUuU6tlAnbH346nNSDoklLI lEDvODTgpkhWDczM69MGKrFYgDcIqXZFWzea6Xq+cuGtGO5xV/4K+efWQovlIdv4mE4j2E2G yXj14Nuyh4wqdX9/yspSZCH1TCbXD9WEB5nQCQNAKzIB7YaTQBjFi1HFzGOGYteZGC37DJ6a xEMRG8/iNZSU4dSL+XsaTnUk5wzzSnz0QVOEOqRY5tkS3zpo9OUGevyR3R6bRqH3EaA5H1cS cH4TNHyhiR0KAbxE8qKx3Jc= Date: Wed, 16 Oct 2019 16:56:18 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <1571234974.5937.53.camel@lca.pw> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 19101614-0028-0000-0000-000003AA9AE4 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19101614-0029-0000-0000-0000246CB4CB Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-10-16_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=65 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910160129 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16.10.19 16:09, Qian Cai wrote: > On Wed, 2019-10-16 at 15:29 +0200, Stefan Haberland wrote: >> Hi, >> >> thanks for reporting this. >> >> On 02.10.19 21:33, Qian Cai wrote: >>> For some reasons, dasd_eckd_check_characteristics() received -ENOMEM and then >>> dasd_generic_set_online() emits this message, >>> >>> dasd: 0.0.0122 Setting the DASD online with discipline ECKD failed with rc=-12 >>> >>> After that, there are several memory leaks below. There are "config_data" and >>> then stored as, >>> >>> /* store per path conf_data */ >>> device->path[pos].conf_data = conf_data; >>> >>> When it processes the error path in  dasd_generic_set_online(), it calls >>> dasd_delete_device() which nuke the whole "struct dasd_device" without freeing >>> the device->path[].conf_data first. >> Usually dasd_delete_device() calls dasd_generic_free_discipline() which >> takes care of >> the device->path[].conf_data in dasd_eckd_uncheck_device(). >> From a first look this looks sane. >> >> So I need to spend a closer look if this does not happen correctly here. > When dasd_eckd_check_characteristics() failed here, > > if (!private) { > private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA); > if (!private) { > dev_warn(&device->cdev->dev, >  "Allocating memory for private DASD data " >  "failed\n"); > return -ENOMEM; > } > device->private = private; > > The device->private is NULL. > > Then, in dasd_eckd_uncheck_device(), it will return immediately. > > if (!private) > return; Yes but in this case there is no per_path configuration data stored. This is done after the private structure is allocated successfully. >>> Is it safe to free those in >>> dasd_free_device() without worrying about the double-free? Or, is it better to >>> free those in dasd_eckd_check_characteristics()'s goto error handling, i.e., >>> out_err*? >>> >>> --- a/drivers/s390/block/dasd.c >>> +++ b/drivers/s390/block/dasd.c >>> @@ -153,6 +153,9 @@ struct dasd_device *dasd_alloc_device(void) >>>   */ >>>  void dasd_free_device(struct dasd_device *device) >>>  { >>> +       for (int i = 0; i < 8; i++) >>> +               kfree(device->path[i].conf_data); >>> + >>>         kfree(device->private); >>>         free_pages((unsigned long) device->ese_mem, 1); >>>         free_page((unsigned long) device->erp_mem); >>> >>> >>> unreferenced object 0x0fcee900 (size 256): >>>   comm "dasdconf.sh", pid 446, jiffies 4294940081 (age 170.340s) >>>   hex dump (first 32 bytes): >>>     dc 01 01 00 f0 f0 f2 f1 f0 f7 f9 f0 f0 c9 c2 d4  ................ >>>     f7 f5 f0 f0 f0 f0 f0 f0 f0 c6 d9 c2 f7 f1 62 33  ..............b3 >>>   backtrace: >>>     [<00000000a83b1992>] kmem_cache_alloc_trace+0x200/0x388 >>>     [<00000000048ef3e2>] dasd_eckd_read_conf+0x408/0x1400 [dasd_eckd_mod] >>>     [<00000000ce31f195>] dasd_eckd_check_characteristics+0x3cc/0x938 >>> [dasd_eckd_mod] >>>     [<00000000f6f1759b>] dasd_generic_set_online+0x150/0x4c0 >>>     [<00000000efca1efa>] ccw_device_set_online+0x324/0x808 >>>     [<00000000f9779774>] online_store_recog_and_online+0xe8/0x220 >>>     [<00000000349a5446>] online_store+0x2ce/0x420 >>>     [<000000005bd145f8>] kernfs_fop_write+0x1bc/0x270 >>>     [<0000000005664197>] vfs_write+0xce/0x220 >>>     [<0000000044a8bccb>] ksys_write+0xea/0x190 >>>     [<0000000037335938>] system_call+0x296/0x2b4 >>