Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8826671ybi; Tue, 23 Jul 2019 16:08:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqxXzdKd0g/BedDEXNdDlOoK4aksSxpAAdh9iSKJ8h9AFeb9Cd8Nqnve5lfMXd0wQTvRhXmr X-Received: by 2002:a17:90a:8d09:: with SMTP id c9mr86070361pjo.131.1563923316379; Tue, 23 Jul 2019 16:08:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563923316; cv=none; d=google.com; s=arc-20160816; b=EFynueZJzIH0YSlyu5diTAwLh4v0JpLTOya31svfbq6pHGLoZw9Wv07Z2u5b6rtc96 hN7psvcsdKee6X4otOWRKATDn9uFKeyMLnNPYMajWoukDBfuGhJxl0fEAY7J2tZOBaqq 0YuR1zfDR7o0NWroelyrsOaei8BwLf3EFbpzURsbTBAVE9I3C12vo9xwkjHmJ+i4zIS8 /TFJDz5+ZfC4UrwWTjotus2HZ8XtYc2K0NtKK3m7py3tqSJ3H80RNFwGozRP5LDnFg1I CQhaftfRl5lwwBh0u7UqqS19Fmw5ExNSbSE7iHv5C33nOwCvPQEvXNyPBTE/DqaDUav+ d5sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=d+pnG65HXsnRmlzhaNNzk6y1yw6MWg2lSfilUvi/rLw=; b=cHWaWF87XiCiJ9Cis6CsrKbKYEqh9msOCc2kmZ2wt+61cmuqS537sd8Xj800BXVL4z eV3ArzuGaXo55ivnNqxCmy6yUPhy42MJJdHIBQ0NKkhIn5CHKFwjN5iumX7cZG9C/dkZ gHtiBg9L7chy0hprE4L1Bg15Bnz4iJs15D/IwGRBbsAWcDwF9GKw3QjKqMS2PbSFeNpg OwSKWRaVSg7xVJu5DW3QMZDrHY8Eyf8fqyR+NaKDt0CvzeB8dhUKssuyu7i/EtpF6qD3 mbX651O8TlaspUijA9uzHpGoIbZxXZTYGhJ5qwYEKNl6hBKvv1ulfD7ZnNjfiQnvd1D2 IBaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=V9weTodO; 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 b3si12794866pfa.89.2019.07.23.16.08.20; Tue, 23 Jul 2019 16:08:36 -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=V9weTodO; 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 S1727931AbfGWM0B (ORCPT + 99 others); Tue, 23 Jul 2019 08:26:01 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:41330 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726438AbfGWM0B (ORCPT ); Tue, 23 Jul 2019 08:26:01 -0400 Received: by mail-pf1-f195.google.com with SMTP id m30so19082525pff.8 for ; Tue, 23 Jul 2019 05:26:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=d+pnG65HXsnRmlzhaNNzk6y1yw6MWg2lSfilUvi/rLw=; b=V9weTodOYCYaFd7X60mM2I0iNT2dJQddnTuM96ykARlIZO67gGvp+UQa2YlwCxGAaF Uk+SHoks11jMp8cTcExW76F8m+UwjFNGkT639eWlWP0AmGb5c13LsC8p9rx+1LMac0JX cj/teAaKGGjSunYWoqBM4aD8BpXrJ4vZVkErEJAVlzZi7E2+ieYK6hIwC6GSDfniTuu+ /yyf1+SDD2Yj5F8v/ZdaFgdMFyFHBE9DHRHPe3VGLxh1FQCyhdgANw8O7wFYNF+z9hyU ZdisoYQHQu/NPOt4wd346std2iUJ2Qzph4fOv1kiEiTfWTAdCHUmtdS4lxDfyBYjQeCb vzxw== 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; bh=d+pnG65HXsnRmlzhaNNzk6y1yw6MWg2lSfilUvi/rLw=; b=Q8hVCMLnHXO6njzoWFYasruOK5KRZecbJ1oGolJlQEIb48rV9wrfNeB+WE21C4WfWS mpl6O+ErYXbNzjb+ZZw6uEvhCgBj0ctHH9VIQks24akCqdVJODTWpiNJ33+lyuIeVwU5 vfr4pT1pFBSCrieEHKu6HnP9Q92zvR3IVGyo2b/ylBPb2O+gCIHA3UL84uQk+5xag9BU S0zr18wws33G4zCaBtxkj2paHlJy310Jilor9GVxk5Lv/U+gX1s3mixWcMybTIRu0Wtd /cIEtfyo9Rn6fiHRYyHiEO7tRJyU1GGx8NBj+y5KTxbSVDpLrSEatyYTt3tsMmVkBUjl y1SQ== X-Gm-Message-State: APjAAAUWNkPdWUH10gHKXfZ/XeqD55/psP5or9Lqt+rhJ2tHvMnUYhOd NeB/9jNmrCAQ53CIc4HDbYY= X-Received: by 2002:a17:90a:b387:: with SMTP id e7mr84704034pjr.113.1563884760953; Tue, 23 Jul 2019 05:26:00 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([2402:f000:4:72:808::3ca]) by smtp.gmail.com with ESMTPSA id g18sm75138115pgm.9.2019.07.23.05.25.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jul 2019 05:26:00 -0700 (PDT) From: Jia-Ju Bai To: dhowells@redhat.com Cc: linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] fs: afs: Fix a possible null-pointer dereference in afs_put_read() Date: Tue, 23 Jul 2019 20:25:53 +0800 Message-Id: <20190723122553.14565-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In afs_read_dir(), there is an if statement on line 255 to check whether req->pages is NULL: if (!req->pages) goto error; If req->pages is NULL, afs_put_read() on line 337 is executed. In afs_put_read(), req->pages[i] is used on line 195. Thus, a possible null-pointer dereference may occur in this case. To fix this possible bug, an if statement is added in afs_put_read() to check req->pages. This bug is found by a static analysis tool STCheck written by us. Signed-off-by: Jia-Ju Bai --- fs/afs/file.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/afs/file.c b/fs/afs/file.c index 56b69576274d..dd3c55c9101c 100644 --- a/fs/afs/file.c +++ b/fs/afs/file.c @@ -191,11 +191,13 @@ void afs_put_read(struct afs_read *req) int i; if (refcount_dec_and_test(&req->usage)) { - for (i = 0; i < req->nr_pages; i++) - if (req->pages[i]) - put_page(req->pages[i]); - if (req->pages != req->array) - kfree(req->pages); + if (req->pages) { + for (i = 0; i < req->nr_pages; i++) + if (req->pages[i]) + put_page(req->pages[i]); + if (req->pages != req->array) + kfree(req->pages); + } kfree(req); } } -- 2.17.0