From patchwork Wed May 16 17:56:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10404565 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 BDC64601F7 for ; Wed, 16 May 2018 17:56:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC4F0285EB for ; Wed, 16 May 2018 17:56:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0C60285F7; Wed, 16 May 2018 17:56:35 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16EC4285F7 for ; Wed, 16 May 2018 17:56:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 693676B034B; Wed, 16 May 2018 13:56:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 644576B034C; Wed, 16 May 2018 13:56:33 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5812B6B034D; Wed, 16 May 2018 13:56:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id 1B6456B034B for ; Wed, 16 May 2018 13:56:33 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id bd7-v6so972537plb.20 for ; Wed, 16 May 2018 10:56:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id; bh=5nDsviOpVtap6qmrq7wg9Rz8YCg+gkLv34yTbZdWjY4=; b=Kuy3zvRf/gTY6X0zzU/i8TzvCeHrawr8FRsqx9apmZYM/dIyzcJ8X0MT4CrpljPXax 1OIzNGo+TZq7cT2n8d7WDc2hi+9MhbW1W84utOb2rqbwaygJjxFWwLr179SXd+jSGn8L f3zJvmLrQyxrKZmVkQC/43Mmm76j2ClA9iKpKvukTryt30pFyjv3VhjKON6Nto8YC/xN i5Tk0C4PQxTprqObU2Xr2HvAmInn+36hXzAEdFlcAdJL8g5OSow0i5A8+aQgZzUB81y3 lHOu1OLKNi1G2Pfkgaly64z02OdfQQ5za/dEfOKsprkbHVMC2jNVyVy2O/tfyWqxJ02D wLDg== X-Gm-Message-State: ALKqPwcAy4BWIkuRjGQN0CddvTgdamZwG6hDwrP8OsLJDHDqdndZB3Tf 9QFuBWUR79fQUK4LjRQz5lsPnTQu9MwgbtWGORwHYmJuPrFRo/Ih/Vrzc7ldtd8C3V8iwluR8mx 10hU8t29mQsh6MXeIdEAP6y5XzmWUnx3KTuNxSfB9h1XwQSiOzegZidm6Hmld33u2Ub/5I5zBsf k15j8tyhTpYmWa6VR+v4+W9m9+6W9Z2jAcA7P4lC0NG/pv0hEkT5mFqGWIwYQobMrBT9cSWvspc roULzE6opDwBit5x/yK0niZ76Xb2oL9HziYrmoamzbKJbYjjIup5uloX06K3t28bKDEAXIDFNJf F8BcwY6VPuSnyCQWxBiRtNHMnODUJNaSVGjKWSP26TdKDcEbx5U8YzBWFj8bwEW7yY4czrbSbfz L X-Received: by 2002:a62:e710:: with SMTP id s16-v6mr1916562pfh.227.1526493392791; Wed, 16 May 2018 10:56:32 -0700 (PDT) X-Received: by 2002:a62:e710:: with SMTP id s16-v6mr1916512pfh.227.1526493391910; Wed, 16 May 2018 10:56:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526493391; cv=none; d=google.com; s=arc-20160816; b=RI3nNnp3NO/4Zfd185nOHQbqL1BgVnpQKKaGhPscFunY30GPZ8GzK9AfUxQQoL0dW5 qNOCgHA997M/f72MlVpnJfPfBGm7r8QaCILgEeJ6LmLWp1PlCuY4RIlkiQkHf+QccPco l82ElWOtmCg1fgjInr+JgvuZAzPjcQg4VKr4uLpTCGDPUSYi7flNzHeqEBjb2FSQbYLn nyxiwwOxVw/dxeQ2wzKR5UqEmv5m+brlCifo5I8Fr3VTygJC4sGcQNLU8jxDjE9eU2HF nDXDVUzx5KB1zVuxTHIq9xRMoTT62T5Ej8b0xJVKeAODrSVPhmhvU3cq2RsQi4apPgib CgEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=5nDsviOpVtap6qmrq7wg9Rz8YCg+gkLv34yTbZdWjY4=; b=Ne64JW2rrSyuLU+t/bRH17ztAH15Inisgj9Jd7a1O4uj7clMuTRWh/jxyPm73kefui 4y3s2dW67I6i+R6+e9eryR0sVTXZ8i80zbG5s+GUiq7JSCpu7QBao0RTYx8I7NljhyV2 /+YI+N1yRCTB1JnIn35QvZppAFOtvU+/qYLhvLP1HY9fecrv7cEVn21ko1ruG1BZtiNZ DNMD607WPtulnqj/w7odp3sISEkIb+b6ZTlGlmDD05uVzuvXu/H+qSVKJX1tVK7bmryz hMc6i66kSoLy9GdjWtkzvJlP7pQX4/XKS2lO2ATBOcxHJycLpkLhLIBVgidNawyrTVbU enqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@osandov-com.20150623.gappssmtp.com header.s=20150623 header.b=bwFlDPY5; spf=neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of osandov@osandov.com) smtp.mailfrom=osandov@osandov.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id x1-v6sor1999073plb.71.2018.05.16.10.56.31 for (Google Transport Security); Wed, 16 May 2018 10:56:31 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of osandov@osandov.com) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@osandov-com.20150623.gappssmtp.com header.s=20150623 header.b=bwFlDPY5; spf=neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of osandov@osandov.com) smtp.mailfrom=osandov@osandov.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=5nDsviOpVtap6qmrq7wg9Rz8YCg+gkLv34yTbZdWjY4=; b=bwFlDPY5DWFQd63RfBbBrTJXBeIuaDPysw7Tj/BQWFpzbgW+8pSfCoxMgyURf9NBpW ZTHs/i2WjgaAd2SQYVpyTGc4MOjWs4D9t02vLtu+wRdAXQtRuoedBY/sSAJ8XRzqjzTx UnI+ymZXWSaId0LeLXwnfx4U/RReJqcajvmwpZLkgO0DvulnV1ctKxf78haKnkIiy9h6 CXvcrRazbLqsStAOGBUCZv8d3VPomLiI7f6U/BGUxe7sh53b2FialT9C0sBzvo2bHHvk jCuOiYwbu4IuH2EV2bzAi9tmTapSAhjO22S6sy3z1bScuwKm36W3NzsEF+8WYKjw/89E Bg1w== X-Google-Smtp-Source: AB8JxZoUUimXoKYp9TIcodOhTAwYmmMiI5A2eMVw03FxoVasS6kbWzCXS2RVvmeoaKWV2vL0BA6wkQ== X-Received: by 2002:a17:902:aa03:: with SMTP id be3-v6mr1900640plb.61.1526493391010; Wed, 16 May 2018 10:56:31 -0700 (PDT) Received: from vader.hsd1.wa.comcast.net ([2601:602:8800:a9a9:e6a7:a0ff:fe0b:c9a8]) by smtp.gmail.com with ESMTPSA id l17-v6sm3778575pgn.85.2018.05.16.10.56.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 May 2018 10:56:30 -0700 (PDT) From: Omar Sandoval To: linux-mm@kvack.org Cc: Andrew Morton , Huang Ying , kernel-team@fb.com Subject: [PATCH] mm: fix nr_rotate_swap leak in swapon() error case Date: Wed, 16 May 2018 10:56:22 -0700 Message-Id: X-Mailer: git-send-email 2.17.0 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval If swapon() fails after incrementing nr_rotate_swap, we don't decrement it and thus effectively leak it. Make sure we decrement it if we incremented it. Fixes: 81a0298bdfab ("mm, swap: don't use VMA based swap readahead if HDD is used as swap") Signed-off-by: Omar Sandoval Reviewed-by: Rik van Riel Reviewed-by: "Huang, Ying" --- Based on v4.17-rc5. mm/swapfile.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index cc2cf04d9018..78a015fcec3b 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3112,6 +3112,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) unsigned long *frontswap_map = NULL; struct page *page = NULL; struct inode *inode = NULL; + bool inced_nr_rotate_swap = false; if (swap_flags & ~SWAP_FLAGS_VALID) return -EINVAL; @@ -3215,8 +3216,10 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) cluster = per_cpu_ptr(p->percpu_cluster, cpu); cluster_set_null(&cluster->index); } - } else + } else { atomic_inc(&nr_rotate_swap); + inced_nr_rotate_swap = true; + } error = swap_cgroup_swapon(p->type, maxpages); if (error) @@ -3307,6 +3310,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) vfree(swap_map); kvfree(cluster_info); kvfree(frontswap_map); + if (inced_nr_rotate_swap) + atomic_dec(&nr_rotate_swap); if (swap_file) { if (inode && S_ISREG(inode->i_mode)) { inode_unlock(inode);