Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PWX-29108 : Handle nil pointer dereference in cloudops #140

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rge-pure
Copy link

@rge-pure rge-pure commented Mar 27, 2023

What this PR does / why we need it:
Following issue was reported on gs-rel 2.13 on Azure PWX-29069. This was related to nil drive size being passed during drive create which was resulting into nil pointer dereference. This was fixed for Azure.

We need to do a thorough check on all the supported cloud platforms supported in cloudops for all the params that can be passed as “nil” that can result into a panic and handle those.

Which issue(s) this PR fixes
PWX-29108

Special notes for your reviewer:
General Workflow : Be very cautious with nil pointer check, avoid any false-positive

Follow the following rules to detect nil pointer or index out of range

    • Dereference variable in the same function.
    • Pointer variable used to access field or element in the same function.
    • Potential index out of range.
    • Variable mandatory for corresponding cloudops.
    • Variable caused panic bug before.
      Add special comments for rule 4.

Also, did a go fmt, some changes are based on that.

* Add nil checks for pointer variables in aws/aws.go
* Add nil checks for pointer variables in azure/azure.go
* Add nil checks for pointer variables in oracle/oracle.go
@rge-pure rge-pure self-assigned this Mar 27, 2023
@rge-pure rge-pure requested review from nrevanna and pp511 March 27, 2023 22:21
@codecov-commenter
Copy link

codecov-commenter commented Mar 27, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.50 ⚠️

Comparison is base (9ecda22) 8.10% compared to head (f040508) 7.61%.

Additional details and impacted files
@@            Coverage Diff            @@
##           master    #140      +/-   ##
=========================================
- Coverage    8.10%   7.61%   -0.50%     
=========================================
  Files          18      18              
  Lines        4664    4966     +302     
=========================================
  Hits          378     378              
- Misses       4264    4566     +302     
  Partials       22      22              
Impacted Files Coverage Δ
aws/aws.go 6.74% <0.00%> (-0.31%) ⬇️
azure/azure.go 0.55% <0.00%> (-0.02%) ⬇️
gce/gce.go 1.04% <0.00%> (-0.01%) ⬇️
oracle/oracle.go 6.56% <0.00%> (-0.19%) ⬇️

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@pp511
Copy link
Contributor

pp511 commented Mar 28, 2023

Discussed offline. Summarizing here:
Some params like *Encryption can be passed as nil. It won't cause panic but would just end up creating a non encrypted disk. Let's only check for mandatory params Eg: size. type could be a mandatory param in some clouds(not sure which) but is not in AWS as it defaults to gp2.

@rge-pure
Copy link
Author

Thanks Priyanshu for the advice.

@rge-pure rge-pure requested a review from a team March 31, 2023 20:16
* Be very cautious with nil pointer check, avoid any false-positive
check
* Follow the following rules to detect nil pointer or index out of range
- variable being deferenced in the same function
- pointer variable used to access field or element in the same function
- potential index out of range
- variable mandatory for corresponding cloudops
- variable caused panic bug before
@@ -796,7 +808,18 @@ func (s *awsOps) Create(
return nil, cloudops.NewStorageError(cloudops.ErrVolInval,
"Drive type not specified in the storage spec", "")
}

if vol.AvailabilityZone == nil {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to CreateVolumeInput documentation

  • AvailabilityZone is a required field
  • The size of the volume, in GiBs. You must specify either a snapshot ID or a volume size.
  • The snapshot from which to create the volume. You must specify either a snapshot ID or a volume size.

@@ -796,7 +808,18 @@ func (s *awsOps) Create(
return nil, cloudops.NewStorageError(cloudops.ErrVolInval,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not mandatory but being dereference below
if *vol.VolumeType == opsworks.VolumeTypeIo1 || *vol.VolumeType == "gp3" {

@@ -371,14 +371,20 @@ func (a *azureOps) Create(
options map[string]string,
) (interface{}, error) {
d, ok := template.(*compute.Disk)
if !ok || d.DiskProperties == nil || d.DiskProperties.DiskSizeGB == nil {
if !ok || d.DiskProperties == nil {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the documentation of Azure - If creationData.createOption is Empty, this field is mandatory and it indicates the size of the disk to create.

Also, this parameter caused panic before - https://portworx.atlassian.net/browse/PWX-29069

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants