Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp186844ybm; Wed, 22 May 2019 01:14:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqzxJ/5077Q+k1yzQJjhmxoYSkKzIkMRcVrzeadPLO5hU/2OOQT+0xcyBs6pzEIX4t7fFSCT X-Received: by 2002:a63:2b96:: with SMTP id r144mr74232234pgr.314.1558512843525; Wed, 22 May 2019 01:14:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558512843; cv=none; d=google.com; s=arc-20160816; b=Fytk1R8RM288zJqHgPaj7eUT3QuWBpxLpmHiGmCJuoW75EhH/dOLvrHtOTpth7r74l Bk+N6jtMqXQ1Z5tRZRu6mx5PffuQDNqxsdzamfayat1e8/qlL/MVumVXFoLdpsUl91EA hKyuldbQ35mwHZKWR9qNa51glOoa/AfsyCAHOdEMGqj9Qw89wCCtamYEWyXjmR9A91Tr z0USTt/7oRkXFeCWFSKkmfsJyn0+px49IWiX3jjRrrsuJ2DMnQe9dsiKzOx9gbB+AVPF H68qeB+WKNSPVwPI7TBILiDsaghGRqzMe0UYZqnrySteX4TMxQVXFIu76riS4vJ/t5Up 6J3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Eti3TImRx56hinakaM+GO4KiRjx+tMNw0bxj57lLePA=; b=vluNi0MQ1JVpPO7QIaGJBO68TTs7fPm4nbdfdOwCmHdG1KYaszxFIiiiVNxmJ7Z+zu xq3j7zyIEsVU3xYuCGsO6UClwiU8Oi9apNZbJXnIN6hJu/hGR3n+Z6DoacQsDiKRCszD ZrlxebdMN2MNS+Rxio7jLbsc1NG6HBAxYAJ833+sHoelv8NOQ0iuUM1LzQQrAEB3GEwi 9bh73inooPKQGc3zLoCR6o2w20SqJJnnL2Jxi19LpTtdeLHocleahx9gFQnF6hunCk05 aEPYdH3OCzMQq/TNv3dl7hLAtyXeq0N+Fp/YvVa2er45x466Di+vIuqhmwqNgTyzVoe5 5VzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=D9Uom5FG; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d5si22118518pla.376.2019.05.22.01.13.47; Wed, 22 May 2019 01:14:03 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=D9Uom5FG; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728536AbfEVIKs (ORCPT + 99 others); Wed, 22 May 2019 04:10:48 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:46364 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728159AbfEVIKs (ORCPT ); Wed, 22 May 2019 04:10:48 -0400 Received: by mail-pg1-f195.google.com with SMTP id o11so727879pgm.13 for ; Wed, 22 May 2019 01:10:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Eti3TImRx56hinakaM+GO4KiRjx+tMNw0bxj57lLePA=; b=D9Uom5FGuRUl6X5RivO2rLKVbgOAJvOnWsg32AR6UpqgoGxlHq5MF4ojlx3u+aZZty vq0E17FZhku4nBGqRMdDYrnumWdcPkNfnbNvjnPuB9tHnwSpQtyziPr2JbKdSxcepcET pRM8bEIcMxL3yv/Wlv9/mw/C7G7vyMFRGetBGGfHliAKdIS1+U2i6ES2QBha5gblCt4z wWpgSTejFzk6bIHqFzpMDanP8TJYLHiZGb6Rzc2cB0UM+O1GvQ8Lm/FPn4+FRXBGcj3j i3+joGrqpLsLwoxSgkzDZPFyrX1S++YqUOtWLpd2TOfGv8ero7BfeRBGW2tw091/tnum sRGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Eti3TImRx56hinakaM+GO4KiRjx+tMNw0bxj57lLePA=; b=bX6u84Ii2DhoTjMtigoc9RfmzjGqHUa2mtxDeT5GrrtWbel/FhiE510e/+Xx6eSZIA fYUVGQqNr5A3OYFUFvKvmDljZpo4J2fsz0uTPYbtBx1rdT4ktHAvq/8gJZ+bZ3bIaAuZ 35C9OE3WvS3/eYA+jILn8Fu/49KErCH+agIs7M1DNkjD6B10PdljnYI3EGuKOk6KuVWE ooKjg3GkzHEWqOb/hWFZOaOI6Ot2GB5mTwtlDC4lh7dCa75ZEoMBat2d7AUNbqRnYFAU akxv70VNF/5D+7NlHg95yjkn2uCgPhm8gA+W67zr3bW0sBKIDw1vZo/nH9UfmDLT/8Cy qedQ== X-Gm-Message-State: APjAAAWz6OshjEZUQv1F9ui+xGAkGNMQC50lSsCNRTVHbjjBEUsn+crX nLiLUVEkv6LnUE4IskIxFrE= X-Received: by 2002:a63:1045:: with SMTP id 5mr44165466pgq.55.1558512647450; Wed, 22 May 2019 01:10:47 -0700 (PDT) Received: from zhanggen-UX430UQ ([66.42.35.75]) by smtp.gmail.com with ESMTPSA id e10sm45898976pfm.137.2019.05.22.01.10.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 01:10:46 -0700 (PDT) Date: Wed, 22 May 2019 16:10:29 +0800 From: Gen Zhang To: Nicolas Pitre Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] vt: Fix a missing-check bug in drivers/tty/vt/vt.c Message-ID: <20190522081029.GB5109@zhanggen-UX430UQ> References: <20190521022940.GA4858@zhanggen-UX430UQ> <20190521030905.GB5263@zhanggen-UX430UQ> <20190521040019.GD5263@zhanggen-UX430UQ> <20190521073901.GF5263@zhanggen-UX430UQ> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 21, 2019 at 10:43:11PM -0400, Nicolas Pitre wrote: > On Tue, 21 May 2019, Gen Zhang wrote: > > > On Tue, May 21, 2019 at 12:30:38AM -0400, Nicolas Pitre wrote: > > > Now imagine that MIN_NR_CONSOLES is defined to 10 instead of 1. > > > > > > What happens with allocated memory if the err_vc condition is met on the > > > 5th loop? > > Yes, vc->vc_screenbuf from the last loop is still not freed, right? I > > don't have idea to solve this one. Could please give some advice? Since > > we have to consider the err_vc condition. > > > > > If err_vc_screenbuf condition is encountered on the 5th loop (curcons = > > > 4), what is the value of vc_cons[4].d? Isn't it the same as vc that you > > > just freed? > > > > > > > > > Nicolas > > Thanks for your explaination! You mean a double free situation may > > happen, right? But in vc_allocate() there is also such a kfree(vc) and > > vc_cons[currcons].d = NULL operation. This situation is really confusing > > me. > > What you could do is something that looks like: > > for (currcons = 0; currcons < MIN_NR_CONSOLES; currcons++) { > vc_cons[currcons].d = vc = kzalloc(...); > if (!vc) > goto fail1; > ... > vc->vc_screenbuf = kzalloc(...); > if (!vc->vc_screenbuf) > goto fail2; > ... > > return 0; > > /* free already allocated memory on error */ > fail1: > while (curcons > 0) { > curcons--; > kfree(vc_cons[currcons].d->vc_screenbuf); > fail2: > kfree(vc_cons[currcons].d); > vc_cons[currcons].d = NULL; > } > console_unlock(); > return -ENOMEM; > > > Nicolas Thanks for your patient explaination, Nicolas! I will work on it and resubmit it. Thanks Gen