Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp475004imm; Wed, 18 Jul 2018 05:35:21 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdpXddEBp3Mv6ZkEI70NzHfwgxt7/f/5YBF7rvFFyf4Q6SIRWSrhrFW5lkp/qVnJIkmmHh+ X-Received: by 2002:a62:3ece:: with SMTP id y75-v6mr5073908pfj.7.1531917321614; Wed, 18 Jul 2018 05:35:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531917321; cv=none; d=google.com; s=arc-20160816; b=xHs95bnF5F9vVUsSznhHTJ2VUvIyPaYMojvxCanUtCb3Z+z5rcH9nD1naxlEUOnjKm 5gp40L68K3pFhfMgSRIkvt/Ve7vDzNtgCgzDwBN62Y2kjIrd/KJcyduTZ7I2lQppqBWR qRA5/zJm+08cNNNOoni59b1+I7Xzd1yktXySwV4p563cjslIGM3Th26xzMgQgXHwb++f mbYVFMU72dZf2h6eT3YGEBawennxDqGDp/iy/1glFTkbW6SOWuy9kBVbWLJPFmWjArrq +NakP1exEc8GNEZtCbYshlhmVwCX6MSCeut9NWUeUAPbIhVCdfPRr5u6TOuE0pd53QHh xfAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:subject:cc:to:from:message-id:date :arc-authentication-results; bh=eNMDf/upag2idG/yIBzNUkmywS5l8RbftGrFw0O1wr8=; b=WooVo23ub0OSaIkPSzoGDoYgjhUQ9qxKwjkIAK1Jrh02p0ea04bm+sh20pfTYhacFa g4FDhViwYeRUi8JxOIAdJgTKFJWRVQz68LvKD2PC1aN33TOCqusfPSRdkhI7BXYAR9zV 1t1OsatOrUxaysCTJL+elU7xMeqX6TCnxRwA6K7hv2Zb7RCagcW6cU90mhY3qxxQpq/G apxDVcx87dnNmvi0MPzAYvRtmPiN60rv5onsj/uS0aTsr7kFSa4UFqq15wwzGMUov4gk jgwTiA3TtEjETaRLMJX+6EKkI+DfRht+O6+miiq5KaSOvORBKnTCZtsg/n00Egrqoj3z 4+0g== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y186-v6si3280674pgb.395.2018.07.18.05.35.06; Wed, 18 Jul 2018 05:35:21 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730565AbeGRNMP (ORCPT + 99 others); Wed, 18 Jul 2018 09:12:15 -0400 Received: from mx2.suse.de ([195.135.220.15]:54516 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726297AbeGRNMP (ORCPT ); Wed, 18 Jul 2018 09:12:15 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1D3A4AD5B; Wed, 18 Jul 2018 12:34:30 +0000 (UTC) Date: Wed, 18 Jul 2018 14:34:28 +0200 Message-ID: From: Takashi Iwai To: " He, Bo " Cc: "alsa-devel@alsa-project.org" , "perex@perex.cz" , "linux-kernel@vger.kernel.org" , "Jun Zhang" , "Yanmin Zhang" Subject: Re: [PATCH] ALSA: core: fix unsigned int pages overflow when comapred In-Reply-To: References: User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/26 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 18 Jul 2018 13:52:45 +0200, He, Bo wrote: > > we see the below kernel panic on stress suspend resume test in > snd_malloc_sgbuf_pages(), snd_dma_alloc_pages_fallback() alloc > chunk maybe larger than the left pages due to the pages alignment, > which will cause the pages overflow. > > while (pages > 0) { > ... > pages -= chunk; > } > > the patch is change the pages from unsigned int to int to fix the issue. Thanks for the patch. Although the analysis is correct, the fix doesn't look ideal. It's also possible that the returned size may over sgbuf->tblsize if we are more unlucky. A change like below should work instead. Could you give it a try? Takashi -- 8< -- --- a/sound/core/sgbuf.c +++ b/sound/core/sgbuf.c @@ -108,7 +108,7 @@ void *snd_malloc_sgbuf_pages(struct device *device, break; } chunk = tmpb.bytes >> PAGE_SHIFT; - for (i = 0; i < chunk; i++) { + for (i = 0; i < chunk && pages > 0; i++) { table->buf = tmpb.area; table->addr = tmpb.addr; if (!i) @@ -117,9 +117,9 @@ void *snd_malloc_sgbuf_pages(struct device *device, *pgtable++ = virt_to_page(tmpb.area); tmpb.area += PAGE_SIZE; tmpb.addr += PAGE_SIZE; + sgbuf->pages++; + pages--; } - sgbuf->pages += chunk; - pages -= chunk; if (chunk < maxpages) maxpages = chunk; }