From patchwork Wed Mar 15 11:31:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 13175671 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D65F1C7618B for ; Wed, 15 Mar 2023 11:31:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 45E046B007B; Wed, 15 Mar 2023 07:31:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 40DDA6B007D; Wed, 15 Mar 2023 07:31:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D65D6B007E; Wed, 15 Mar 2023 07:31:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1B7086B007B for ; Wed, 15 Mar 2023 07:31:47 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E432B1C690D for ; Wed, 15 Mar 2023 11:31:46 +0000 (UTC) X-FDA: 80570917812.25.22793E8 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by imf29.hostedemail.com (Postfix) with ESMTP id 5081A12001E for ; Wed, 15 Mar 2023 11:31:42 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=gVtTtbhI; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf29.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.136) smtp.mailfrom=kirill.shutemov@linux.intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678879904; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MD1pFyz84vdYwyMP/5a1kTCUnI97p/yuOqanyBZbHs4=; b=L3To43Ug4JfoZdrtQ3RiRB3qdpQVkFVeivZmKluh2nVndVYe+mf12HAnupQknCqFP6+71H VasLOXJGiXpqFQxyB88Jfm05aTMVBGNhDIA613LqLWcX/8Z5zwa3zl5oh1ftuLOaFRYtn4 tYY+Z3/dvjxhf5Zx1b2rwUz1raOtVQc= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=gVtTtbhI; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf29.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.136) smtp.mailfrom=kirill.shutemov@linux.intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678879904; a=rsa-sha256; cv=none; b=76klenqBJiqhepAqIJ4DolTy48yxMPmjynAlOxQyXkxL00hcIOmNF5lTvtkvD/sfQcmPbD Ti2C90HfxDHLzPFSV2BBkHszE9uNEFPEwjKgs9Nx23GZ12XfUB+gshSNIeDZDRWY6vHYMF 3Jugsg4lZrwpvkPBi4WoU5gmQHyZe3k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678879903; x=1710415903; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CbKC9In0sfgAFhGmEkzB7Bb+JmElN2MpqrLq/60tyc4=; b=gVtTtbhId8G1WBovr43rfDah0kjDjydSuqcLgD/wKe0YBc0HwlbZIMAI fp1LYO3tJC4AZCtuYRuM5mBWye9eWdG9BOiyhSn9/duAL0/Nr/FRF+WsK nPiXNNBMoBJ9UVdSY2JqHdc42E3kDugysMIEcVXrJHdepUTnztSErgM4t qh5FC5vXYN8bxQUyb7yqebok1In0iSs2H53Yy0o96OjFf/728y7S0hEHG am3N5dGo8hZB1pNmsm16PHmFGIa65qcuOaQRClkbvONIBLmCXqFXcaJyz 2uuFe3Um/GMUwcualJdMBRWrHc6g17Bf4XghN3CTF/33E7sg41LdQh7eb Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10649"; a="317330267" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="317330267" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 04:31:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10649"; a="925310514" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925310514" Received: from nopopovi-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.33.48]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 04:31:38 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id BB81D10CC9F; Wed, 15 Mar 2023 14:31:35 +0300 (+03) From: "Kirill A. Shutemov" To: Andrew Morton , Mel Gorman , Vlastimil Babka , David Hildenbrand Cc: linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Denis Efremov Subject: [PATCH 03/10] floppy: Fix MAX_ORDER usage Date: Wed, 15 Mar 2023 14:31:26 +0300 Message-Id: <20230315113133.11326-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230315113133.11326-1-kirill.shutemov@linux.intel.com> References: <20230315113133.11326-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 5081A12001E X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: f959p13idihuyi71kzto1gh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fSZSEbkq0TcJmOtsl392FsEQ8ANNdLo5rhjnWIRwTO7TsoQKjBYmxQnbSpm3zmmIwq4LxDCg2JxlaJtIuJSEJSCrZfnqRS/oq2N9kNrxxEfzzF0bzzFEeffsCN/rgb5o+s300tH7+obZVnPv641/FGwSnrEzEl+NNjuEdSkkgmJnuvO3Xyx3MBTZPJT2RwxyJgt7kMsCpAeyUM6yjG1loLFeY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: MAX_ORDER is not inclusive: the maximum allocation order buddy allocator can deliver is MAX_ORDER-1. Fix MAX_ORDER usage in floppy code. Also allocation buffer exactly PAGE_SIZE << MAX_ORDER bytes is okay. Fix MAX_LEN check. Signed-off-by: Kirill A. Shutemov Cc: Denis Efremov Acked-by: Mike Rapoport (IBM) Acked-by: Vlastimil Babka --- drivers/block/floppy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index 487840e3564d..90d2dfb6448e 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -3079,7 +3079,7 @@ static void raw_cmd_free(struct floppy_raw_cmd **ptr) } } -#define MAX_LEN (1UL << MAX_ORDER << PAGE_SHIFT) +#define MAX_LEN (1UL << (MAX_ORDER - 1) << PAGE_SHIFT) static int raw_cmd_copyin(int cmd, void __user *param, struct floppy_raw_cmd **rcmd) @@ -3108,7 +3108,7 @@ static int raw_cmd_copyin(int cmd, void __user *param, ptr->resultcode = 0; if (ptr->flags & (FD_RAW_READ | FD_RAW_WRITE)) { - if (ptr->length <= 0 || ptr->length >= MAX_LEN) + if (ptr->length <= 0 || ptr->length > MAX_LEN) return -EINVAL; ptr->kernel_data = (char *)fd_dma_mem_alloc(ptr->length); fallback_on_nodma_alloc(&ptr->kernel_data, ptr->length);