In the Linux kernel, the following vulnerability has been resolved:
gpiolib: fix memory leak in gpiochipsetupdev()
Here is a backtrace report about memory leak detected in gpiochipsetupdev():
unreferenced object 0xffff88810b406400 (size 512): comm "python3", pid 1682, jiffies 4295346908 (age 24.090s) backtrace: kmalloctrace deviceadd deviceprivateinit at drivers/base/core.c:3361 (inlined by) deviceadd at drivers/base/core.c:3411 cdevdeviceadd gpiolibcdevregister gpiochipsetupdev gpiochipadddatawith_key
gcdevregister() & gcdevunregister() would call deviceadd() & devicedel() (no matter CONFIGGPIOCDEV is enabled or not) to register/unregister device.
However, if deviceadd() succeeds, some resource (like struct deviceprivate allocated by deviceprivateinit()) is not released by device_del().
Therefore, after deviceadd() succeeds by gcdevregister(), it needs to call put_device() to release resource in the error handle path.
Here we move forward the register of release function, and let it release every piece of resource by put_device() instead of kfree().
While at it, fix another subtle issue, i.e. when gc->ngpio is equal to 0, we still call kcalloc() and, in case of further error, kfree() on the ZERO_PTR pointer, which is not NULL. It's not a bug per se, but rather waste of the resources and potentially wrong expectation about contents of the gdev->descs variable.
[
{
"signature_type": "Function",
"digest": {
"function_hash": "103820645485410694064073421037129548298",
"length": 451.0
},
"target": {
"file": "drivers/gpio/gpiolib.c",
"function": "gpiochip_setup_dev"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@6daaa84b621485fe28c401be18debf92ae8ef04a",
"id": "CVE-2022-48975-3231dbe3",
"deprecated": false,
"signature_version": "v1"
},
{
"signature_type": "Function",
"digest": {
"function_hash": "103820645485410694064073421037129548298",
"length": 451.0
},
"target": {
"file": "drivers/gpio/gpiolib.c",
"function": "gpiochip_setup_dev"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@371363716398ed718e389bea8c5e9843a79dde4e",
"id": "CVE-2022-48975-4463b096",
"deprecated": false,
"signature_version": "v1"
},
{
"signature_type": "Function",
"digest": {
"function_hash": "103820645485410694064073421037129548298",
"length": 451.0
},
"target": {
"file": "drivers/gpio/gpiolib.c",
"function": "gpiochip_setup_dev"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@ec851b23084b3a0af8bf0f5e51d33a8d678bdc49",
"id": "CVE-2022-48975-63df45c8",
"deprecated": false,
"signature_version": "v1"
},
{
"signature_type": "Line",
"digest": {
"threshold": 0.9,
"line_hashes": [
"8105838462547840213219202959945539456",
"176671609424456509580597542179355556973",
"76223660564030782976156606790611561356",
"270079098973367300059285194275724127392",
"52096749785023653598617721818675086632",
"312800571249878349894958830924129485941",
"28456810557291430890163095404963537626",
"55926181776367673706337340138405775560",
"100833469379091101949189460901458047177",
"119208805364467466132809974777643825095",
"201966649243023670137907308333251180094",
"33875183863179862508926369218161140496",
"52505356893805109460338286656517256506",
"142439719397987669192121518024064825089",
"263000755414251842816108983633664206290",
"33661000792930183101814476974841122900",
"175478300409945951386702433595781873190",
"167442026668699130807513686805562914416",
"18513258361800635202861459076237716335",
"284449768562144460066062660300022546407",
"207041433331596124291040880848216078573",
"114064458568152659129611570975495113546",
"124551554907897983703544266773903502742",
"195001355180765247167398904383782074390",
"10696293784113107541852947719485195824",
"246449461435438817998978400760493834815",
"328795011460771128157099041045523685776",
"39990694888151475038626896326311781065",
"230545741311242598304864785532044850616",
"101513459690262942791044111353098888857",
"272336353585379343183630232015509788815",
"121279497173215736478994810652467423617",
"23020873670662560637850940562018328569",
"111476612194837582715536364336126642791",
"216190657821806209134509231573944071894",
"18272268963154064456343069578622653351",
"255038039100624770770934260519988016397",
"95050367323471245383608091734520623512",
"266922876498945382969988324683349721140",
"338134740236054313254576776328997779692",
"28725318732308634748983530835294214148",
"28992657663832155451940018012483003003",
"260819165438036302290971957171646930268",
"288841153290770553371202631633402467778",
"11708311069395932598277017862634640029",
"153069116751504910789899546470304812339",
"187249664425247740251854613576574230307",
"319156095437813060770609892840880141347",
"168607641202679401299084556330482067581",
"280943287206353876589404017794783843511",
"22325795380062505885713185967564725555",
"249487163790460840196920394419039530119",
"121316376374510099865052458756378378432",
"265359016055381683443489181619015977453",
"282655951615863600800377368822384058727",
"211917050387455936347555469743484323765",
"71591505105331484535479981705212715064"
]
},
"target": {
"file": "drivers/gpio/gpiolib.c"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@ec851b23084b3a0af8bf0f5e51d33a8d678bdc49",
"id": "CVE-2022-48975-c069b932",
"deprecated": false,
"signature_version": "v1"
},
{
"signature_type": "Function",
"digest": {
"function_hash": "245852021170985346628722848537649836474",
"length": 4416.0
},
"target": {
"file": "drivers/gpio/gpiolib.c",
"function": "gpiochip_add_data_with_key"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@371363716398ed718e389bea8c5e9843a79dde4e",
"id": "CVE-2022-48975-ec55f91a",
"deprecated": false,
"signature_version": "v1"
},
{
"signature_type": "Line",
"digest": {
"threshold": 0.9,
"line_hashes": [
"8105838462547840213219202959945539456",
"176671609424456509580597542179355556973",
"76223660564030782976156606790611561356",
"270079098973367300059285194275724127392",
"52096749785023653598617721818675086632",
"312800571249878349894958830924129485941",
"28456810557291430890163095404963537626",
"55926181776367673706337340138405775560",
"100833469379091101949189460901458047177",
"119208805364467466132809974777643825095",
"201966649243023670137907308333251180094",
"33875183863179862508926369218161140496",
"52505356893805109460338286656517256506",
"142439719397987669192121518024064825089",
"263000755414251842816108983633664206290",
"33661000792930183101814476974841122900",
"175478300409945951386702433595781873190",
"167442026668699130807513686805562914416",
"18513258361800635202861459076237716335",
"284449768562144460066062660300022546407",
"207041433331596124291040880848216078573",
"114064458568152659129611570975495113546",
"124551554907897983703544266773903502742",
"195001355180765247167398904383782074390",
"10696293784113107541852947719485195824",
"246449461435438817998978400760493834815",
"328795011460771128157099041045523685776",
"39990694888151475038626896326311781065",
"230545741311242598304864785532044850616",
"101513459690262942791044111353098888857",
"272336353585379343183630232015509788815",
"121279497173215736478994810652467423617",
"23020873670662560637850940562018328569",
"111476612194837582715536364336126642791",
"216190657821806209134509231573944071894",
"18272268963154064456343069578622653351",
"255038039100624770770934260519988016397",
"95050367323471245383608091734520623512",
"266922876498945382969988324683349721140",
"338134740236054313254576776328997779692",
"28725318732308634748983530835294214148",
"28992657663832155451940018012483003003",
"260819165438036302290971957171646930268",
"288841153290770553371202631633402467778",
"11708311069395932598277017862634640029",
"153069116751504910789899546470304812339",
"187249664425247740251854613576574230307",
"319156095437813060770609892840880141347",
"168607641202679401299084556330482067581",
"280943287206353876589404017794783843511",
"22325795380062505885713185967564725555",
"249487163790460840196920394419039530119",
"121316376374510099865052458756378378432",
"265359016055381683443489181619015977453",
"282655951615863600800377368822384058727",
"211917050387455936347555469743484323765",
"71591505105331484535479981705212715064"
]
},
"target": {
"file": "drivers/gpio/gpiolib.c"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@371363716398ed718e389bea8c5e9843a79dde4e",
"id": "CVE-2022-48975-ef0a0113",
"deprecated": false,
"signature_version": "v1"
},
{
"signature_type": "Function",
"digest": {
"function_hash": "143229055555424873952975738684009227076",
"length": 4250.0
},
"target": {
"file": "drivers/gpio/gpiolib.c",
"function": "gpiochip_add_data_with_key"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@6daaa84b621485fe28c401be18debf92ae8ef04a",
"id": "CVE-2022-48975-f2c4f113",
"deprecated": false,
"signature_version": "v1"
},
{
"signature_type": "Line",
"digest": {
"threshold": 0.9,
"line_hashes": [
"8105838462547840213219202959945539456",
"176671609424456509580597542179355556973",
"76223660564030782976156606790611561356",
"270079098973367300059285194275724127392",
"52096749785023653598617721818675086632",
"312800571249878349894958830924129485941",
"28456810557291430890163095404963537626",
"323419569977886229088850509622518319104",
"100833469379091101949189460901458047177",
"119208805364467466132809974777643825095",
"201966649243023670137907308333251180094",
"148034117466374271852188766016735430181",
"289458748072130452073743608703520302715",
"293041083754308319911831731798053297506",
"263000755414251842816108983633664206290",
"33661000792930183101814476974841122900",
"175478300409945951386702433595781873190",
"167442026668699130807513686805562914416",
"18513258361800635202861459076237716335",
"284449768562144460066062660300022546407",
"207041433331596124291040880848216078573",
"114064458568152659129611570975495113546",
"124551554907897983703544266773903502742",
"195001355180765247167398904383782074390",
"10696293784113107541852947719485195824",
"246449461435438817998978400760493834815",
"328795011460771128157099041045523685776",
"39990694888151475038626896326311781065",
"230545741311242598304864785532044850616",
"101513459690262942791044111353098888857",
"272336353585379343183630232015509788815",
"121279497173215736478994810652467423617",
"23020873670662560637850940562018328569",
"111476612194837582715536364336126642791",
"216190657821806209134509231573944071894",
"18272268963154064456343069578622653351",
"255038039100624770770934260519988016397",
"95050367323471245383608091734520623512",
"266922876498945382969988324683349721140",
"338134740236054313254576776328997779692",
"28725318732308634748983530835294214148",
"28992657663832155451940018012483003003",
"260819165438036302290971957171646930268",
"288841153290770553371202631633402467778",
"11708311069395932598277017862634640029",
"153069116751504910789899546470304812339",
"187249664425247740251854613576574230307",
"319156095437813060770609892840880141347",
"168607641202679401299084556330482067581",
"280943287206353876589404017794783843511",
"22325795380062505885713185967564725555",
"249487163790460840196920394419039530119",
"121316376374510099865052458756378378432",
"265359016055381683443489181619015977453",
"282655951615863600800377368822384058727",
"211917050387455936347555469743484323765",
"71591505105331484535479981705212715064"
]
},
"target": {
"file": "drivers/gpio/gpiolib.c"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@6daaa84b621485fe28c401be18debf92ae8ef04a",
"id": "CVE-2022-48975-f3e2830d",
"deprecated": false,
"signature_version": "v1"
},
{
"signature_type": "Function",
"digest": {
"function_hash": "245852021170985346628722848537649836474",
"length": 4416.0
},
"target": {
"file": "drivers/gpio/gpiolib.c",
"function": "gpiochip_add_data_with_key"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@ec851b23084b3a0af8bf0f5e51d33a8d678bdc49",
"id": "CVE-2022-48975-f607826a",
"deprecated": false,
"signature_version": "v1"
}
]