From nobody Sat Jul 25 20:08:12 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7450243B493 for ; Tue, 14 Jul 2026 09:22:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784020977; cv=none; b=Nqt3JlVtivRf7E2fY3ifbfSlXb01UEtO8Sr2qDz72a5J3N9rYjdQ4C8k75S0U6FUdhYHZo9H/Jg6KfTAK2/mOcb6GUzoQ2Q1HkBPBa2vooYZwcHCNb/1bkqTxsCPcwWIYw/1hQAwiXtXpJSiLyWzUGM5++W+fPDDgDwdo/H9ulw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784020977; c=relaxed/simple; bh=+UgPvdHQKtnyG+ZMziiZ6lZ4uWc2X/p5sgpads94KZk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZBsJ19R9VEHy+Ew/VS2ConbES8gXmgxrjZ/gDJl1kOE0A4r5yoybb5Hy4kAw5tZGMHvoFVTKnsir3OHAL+vScZishtAW6ABs3wjQKX/bEX74AIODvl6JFRIQj0RVahiWIpOsNzqf484MaMdkpZk/7gm+E0AvTsNhcTO4wxhoSXk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 95869cb07f6511f1aa26b74ffac11d73-20260714 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:8d63ad58-b823-40c9-824c-3bb7a065d08b,IP:0,U RL:0,TC:0,Content:0,EDM:-20,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-20 X-CID-META: VersionHash:e7bac3a,CLOUDID:8d456a54e472d39efb53e993091d104e,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:81|82|102|850|865|898,TC:nil,Content:0|1 5|50,EDM:1,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI: 0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 95869cb07f6511f1aa26b74ffac11d73-20260714 X-User: xieyi@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1925950862; Tue, 14 Jul 2026 17:22:50 +0800 From: Yi Xie To: akpm@linux-foundation.org, ljs@kernel.org Cc: linux-kernel@vger.kernel.org, Yi Xie Subject: [PATCH v2] ipc/shm: check shm_lock() in do_shmat cleanup Date: Tue, 14 Jul 2026 17:22:37 +0800 Message-Id: <20260714092237.147312-1-xieyi@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260714031713.72859-1-xieyi@kylinos.cn> References: <20260714031713.72859-1-xieyi@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" shm_lock() can fail; don't dereference the error pointer. Signed-off-by: Yi Xie --- v2: keep a single up_write(), as suggested by Lorenzo ipc/shm.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ipc/shm.c b/ipc/shm.c index b3e8a58e177d..d243137c4dbd 100644 --- a/ipc/shm.c +++ b/ipc/shm.c @@ -1677,12 +1677,16 @@ long do_shmat(int shmid, char __user *shmaddr, int = shmflg, out_nattch: down_write(&shm_ids(ns).rwsem); shp =3D shm_lock(ns, shmid); - shp->shm_nattch--; + if (IS_ERR(shp)) { + err =3D PTR_ERR(shp); + } else { + shp->shm_nattch--; =20 - if (shm_may_destroy(shp)) - shm_destroy(ns, shp); - else - shm_unlock(shp); + if (shm_may_destroy(shp)) + shm_destroy(ns, shp); + else + shm_unlock(shp); + } up_write(&shm_ids(ns).rwsem); return err; =20 --=20 2.25.1