From patchwork Thu Aug 3 17:11:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 9879531 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B7A2D604D9 for ; Thu, 3 Aug 2017 17:12:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A65E628889 for ; Thu, 3 Aug 2017 17:12:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4A1C288E8; Thu, 3 Aug 2017 17:12:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0AE4D28946 for ; Thu, 3 Aug 2017 17:12:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=m8B/Zp0hExZuAAUyjRaTipiUbGJ8Dg5DJFrRr8REYaI=; b=cG9vZZEulKue0lGpT0hWFtLXTa lIEYja1fPgaX/kdOaIzpyTTi4FtHHMjJWPWll1Eh0Y1jcONZ6Qhj7akVgcVUFTS8oRnJdZici9+lo S10eFNp1FQIpDBpbTkG1RhEyxEw3pQldtsWNybsboAgL8adAMAS0aCn0pseeffP14v181LYqkAnNr fI4TbbVLORkZLG6uejt/jiyF7o5yJNmAB9kjE0YkOJCeL9C2N2mLkNOdDjsO2Zeiwz8k8U1qMVqK4 A3nUxsI0U2XqZtkY4R2RUlGzhRfecdwO8m86pPdzJiZuj2KXX7/5VG6xDrlvGA7X56LB4tEByTg03 269+f3IA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ddJfa-0002vD-6c; Thu, 03 Aug 2017 17:12:22 +0000 Received: from mail-pg0-x22f.google.com ([2607:f8b0:400e:c05::22f]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ddJfR-0002Yx-Di for linux-arm-kernel@lists.infradead.org; Thu, 03 Aug 2017 17:12:20 +0000 Received: by mail-pg0-x22f.google.com with SMTP id v77so8619892pgb.3 for ; Thu, 03 Aug 2017 10:11:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wX4PSBftMX6zC6YerxwpWV2pTRJplSGC7uJ+hk8pnEM=; b=OYh+P1wvcE2WeAreKx7Cqkr5QI+IQRhIAamUWQF7XYUavOLeEztlaN6fDINIU2pmOo 7+Njy67z1IpZjgum0Efz9HeVyv6NahG1oKRQFoVj+/aLQ8H6ueBhYnZRqj3J8Le9KCLh M7vdret2BY7xet5EO1aeC0rL51XqpaNw1N7peuDxf0mJFq6njPjICxZWUgNHCrcCYeil ai3rjBV5ESzKK32HreyD7QxBii3wV0jTp+/dHnxEcimBb8o3M6RH58TgTSa33k/O7i0D 32x4z755gJed6sr69Sm50SoAUaPK8AWyzER9Eh1xjARiM6MbJ5bReM5vjWO1dpEvMUUZ Es5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wX4PSBftMX6zC6YerxwpWV2pTRJplSGC7uJ+hk8pnEM=; b=dvGEnDvmdriFcEUiF+5SYLSomyQaAluYu3v0vUL+Rr9hBl2TgTVd7ErW5gl05RuEJW AN/hxtQOdWsyNmnHwEe/Y1qdR2dLF6GQWD2q+rTKb9l0ZJPPj/PmOTH/WokUHbJ9wanv ZHdinMC7roq67PGAq+Y/96MjmaMbuaTETbeAUSS4eOd/ySV/jJj0E3YqZbY14HWvlukt 6tBuVTuFRCIw6PKLXNPhUc4D0wSqvSGnHSbBghRLHzkLmEEM5VKn8toUV/QmK0xoEqsC X6I8/MCY6f+0vNi9NX2Ja0hgWu9uX7oslF6AUlRf28Kwga4gMVCJmnyHXzVnW0fYLvkg JCAw== X-Gm-Message-State: AIVw111WXdxdTnGPQnmYy03VjCY8BmP2F1G0oC8J51OP8Xd9UVtYGX8t E0zc3xoq1brJSW8L X-Received: by 10.98.133.134 with SMTP id m6mr2270037pfk.97.1501780312356; Thu, 03 Aug 2017 10:11:52 -0700 (PDT) Received: from ndesaulniers0.mtv.corp.google.com ([100.98.120.50]) by smtp.gmail.com with ESMTPSA id s3sm62393595pgn.70.2017.08.03.10.11.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Aug 2017 10:11:51 -0700 (PDT) From: Nick Desaulniers To: Subject: [PATCH] arm64: avoid overflow in VA_START and PAGE_OFFSET Date: Thu, 3 Aug 2017 10:11:16 -0700 Message-Id: <20170803171117.107992-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.14.0.rc1.383.gd1ce394fe2-goog In-Reply-To: <20170803132035.gixd7m7oxtehpquu@yury-thinkpad> References: <20170803132035.gixd7m7oxtehpquu@yury-thinkpad> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170803_101214_004292_B75952DC X-CRM114-Status: GOOD ( 10.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Ard Biesheuvel , Catalin Marinas , Oleksandr Andrushchenko , Nick Desaulniers , dianders@chromium.org, ghackmann@google.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, srhines@google.com, Will Deacon , pirama@google.com, akpm@linux-foundation.org, Laura Abbott , Neeraj Upadhyay , zijun_hu@htc.com, Alexander Popov MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The bitmask used to define these values produces overflow, as seen by this compiler warning: arch/arm64/kernel/head.S:47:8: warning: integer overflow in preprocessor expression #elif (PAGE_OFFSET & 0x1fffff) != 0 ^~~~~~~~~~~ arch/arm64/include/asm/memory.h:52:46: note: expanded from macro 'PAGE_OFFSET' #define PAGE_OFFSET (UL(0xffffffffffffffff) << (VA_BITS - 1)) ~~~~~~~~~~~~~~~~~~ ^ It would be preferrable to use GENMASK_ULL() instead, but it's not set up to be used from assembly (the UL() macro token pastes UL suffixes when not included in assembly sources). Suggested-by: Yury Norov Suggested-by: Matthias Kaehlcke Signed-off-by: Nick Desaulniers --- arch/arm64/include/asm/memory.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index 32f82723338a..dde717a31dee 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -64,8 +64,9 @@ * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area. */ #define VA_BITS (CONFIG_ARM64_VA_BITS) -#define VA_START (UL(0xffffffffffffffff) << VA_BITS) -#define PAGE_OFFSET (UL(0xffffffffffffffff) << (VA_BITS - 1)) +#define VA_START ((UL(0xffffffffffffffff) >> VA_BITS) << VA_BITS) +#define PAGE_OFFSET ((UL(0xffffffffffffffff) >> (VA_BITS - 1)) \ + << (VA_BITS - 1)) #define KIMAGE_VADDR (MODULES_END) #define MODULES_END (MODULES_VADDR + MODULES_VSIZE) #define MODULES_VADDR (VA_START + KASAN_SHADOW_SIZE)